Auto stash before merge of "level/tiled" and "origin/level/tiled"

This commit is contained in:
Carter Tomlenovich 2021-10-01 21:10:14 -04:00
parent ae75f99bc2
commit 1a94016a11
3 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.7.2" name="abwsx3mzcgs21" tilewidth="32" tileheight="32" tilecount="864" columns="36">
<image source="../../../../../../Downloads/abwsx3mzcgs21.png" width="1152" height="768"/>
</tileset>

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ use std::{io::Write, path::Path};
use raylib::{texture::Texture2D, RaylibHandle, RaylibThread}; use raylib::{texture::Texture2D, RaylibHandle, RaylibThread};
use tempfile::{tempdir, NamedTempFile}; use tempfile::{tempdir, NamedTempFile};
use tracing::debug; use tracing::debug;
use tiled::*;
/// Contains all game assets. /// Contains all game assets.
/// ///
/// This uses macro magic to automatically embed the contents of `game/assets/` into the executable /// This uses macro magic to automatically embed the contents of `game/assets/` into the executable
@ -65,3 +65,24 @@ pub fn load_texture_from_internal_data(
Ok(texture) Ok(texture)
} }
// Loading specific to level files.
pub fn load_map_from_internal_data(path: &str) -> Result<Map, ResourceLoadError> {
let temp_dir = tempdir()?;
let tmp_path = temp_dir.path().join(Path::new(path).filename().unwrap());
std::fs::write(&tmp_path,
&StaticGameData::get(path)
.ok_or(ResourceLoadError::AssetNotFound(path.to_string()))?
.data,
)?;
let map_file = File::open(tmp_path.to_str())?;
let level = parse(map_file).unwrap();
temp_dir.close()?;
Ok(level);
}