Skip to content

Commit

Permalink
Add basemap datadir
Browse files Browse the repository at this point in the history
  • Loading branch information
iMilchshake committed Sep 9, 2024
1 parent 9bb0510 commit 86f3cc6
Show file tree
Hide file tree
Showing 22 changed files with 21 additions and 8 deletions.
Binary file removed automap_out.map
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added data/basemaps/grass.map
Binary file not shown.
File renamed without changes.
29 changes: 21 additions & 8 deletions src/twmap_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ use twmap::{
};

#[derive(RustEmbed)]
#[folder = "automapper/"]
#[folder = "data/automapper/"]
pub struct AutoMapperConfigs;

#[derive(RustEmbed)]
#[folder = "data/basemaps/"]
pub struct BaseMaps;

impl AutoMapperConfigs {
pub fn get_config(name: String) -> Automapper {
let file = AutoMapperConfigs::get(&(name.clone() + ".rules"))
Expand All @@ -22,6 +26,17 @@ impl AutoMapperConfigs {
}
}

impl BaseMaps {
// TODO: add support for custom name or random
pub fn get_base_map() -> TwMap {
let file = BaseMaps::get("grass.map").expect("base map not found");
let mut tw_map = TwMap::parse(&file.data).expect("parsing failed");
tw_map.load().expect("map loading failed");

tw_map
}
}

pub struct TwExport;

impl TwExport {
Expand All @@ -36,7 +51,7 @@ impl TwExport {
automapper_config.clone()
}

pub fn process_layer(
pub fn process_tile_layer(
tw_map: &mut TwMap,
map: &Map,
layer_index: &usize,
Expand Down Expand Up @@ -90,14 +105,12 @@ impl TwExport {
}

pub fn export(map: &Map, path: &PathBuf) {
let mut tw_map =
TwMap::parse(&std::fs::read("automap_test.map").expect("map file couldn't be read"))
.expect("parsing failed");
tw_map.load().expect("loading failed");
let mut tw_map = BaseMaps::get_base_map();

TwExport::process_layer(&mut tw_map, map, &0, "Freeze", &BlockTypeTW::Freeze);
TwExport::process_layer(&mut tw_map, map, &1, "Hookable", &BlockTypeTW::Hookable);
TwExport::process_tile_layer(&mut tw_map, map, &0, "Freeze", &BlockTypeTW::Freeze);
TwExport::process_tile_layer(&mut tw_map, map, &1, "Hookable", &BlockTypeTW::Hookable);

// TODO: move into function
// get game layer
let game_layer = tw_map
.find_physics_layer_mut::<GameLayer>()
Expand Down
Binary file removed test.map
Binary file not shown.

0 comments on commit 86f3cc6

Please sign in to comment.