# HG changeset patch # User unC0Rr # Date 1724928976 -7200 # Node ID 3402b218569810265d595af58ec33ebf0b7fe0d4 # Parent 0fd23fc57947cf1b3584b2ee63d2bfd573375ad7 Pass full path to WFC for tile loading diff -r 0fd23fc57947 -r 3402b2185698 rust/landgen/src/wavefront_collapse/generator.rs --- a/rust/landgen/src/wavefront_collapse/generator.rs Wed Aug 28 17:16:23 2024 +0200 +++ b/rust/landgen/src/wavefront_collapse/generator.rs Thu Aug 29 12:56:16 2024 +0200 @@ -6,7 +6,7 @@ use std::collections::HashSet; use std::fs::File; use std::io::{BufReader, Result}; -use std::path::Path; +use std::path::{Path, PathBuf}; #[derive(Clone)] pub struct EdgeDescription { @@ -53,21 +53,23 @@ pub struct WavefrontCollapseLandGenerator { pub template: TemplateDescription, + data_path: PathBuf, } impl WavefrontCollapseLandGenerator { - pub fn new(template: TemplateDescription) -> Self { - Self { template } + pub fn new(template: TemplateDescription, data_path: &Path) -> Self { + Self { template, data_path: data_path.to_owned() } } fn load_image_tiles( + &self, parameters: &LandGenerationParameters, tile_description: &TileDescription, ) -> Result>> { let mut result = Vec::new(); let file = File::open( - Path::new("../share/hedgewars/Data/Tiles") + self.data_path.join("Tiles") .join(&tile_description.name) .as_path(), )?; @@ -160,7 +162,7 @@ let mut result = Vec::new(); for tile_description in self.template.tiles.iter() { - if let Ok(mut tiles) = Self::load_image_tiles(parameters, tile_description) { + if let Ok(mut tiles) = self.load_image_tiles(parameters, tile_description) { result.append(&mut tiles); } else { eprintln!("Failed to load a tile!"); diff -r 0fd23fc57947 -r 3402b2185698 rust/lib-hwengine-future/src/lib.rs --- a/rust/lib-hwengine-future/src/lib.rs Wed Aug 28 17:16:23 2024 +0200 +++ b/rust/lib-hwengine-future/src/lib.rs Thu Aug 29 12:56:16 2024 +0200 @@ -64,7 +64,7 @@ let yaml_templates = fs::read_to_string(data_path.join(Path::new("wfc_templates.yaml")).as_path()) .expect("Error reading map templates file"); - let mut map_gen = MapGenerator::::new(); + let mut map_gen = MapGenerator::::new(data_path); map_gen.import_yaml_templates(&yaml_templates); let distance_divisor = feature_size.pow(2) / 8 + 10; @@ -96,7 +96,7 @@ let data_path = Path::new(&data_path); let theme_name: &str = unsafe { CStr::from_ptr(theme_name) }.to_str().unwrap(); - let map_gen = MapGenerator::<()>::new(); + let map_gen = MapGenerator::<()>::new(data_path); let theme = Theme::load( data_path diff -r 0fd23fc57947 -r 3402b2185698 rust/mapgen/src/lib.rs --- a/rust/mapgen/src/lib.rs Wed Aug 28 17:16:23 2024 +0200 +++ b/rust/mapgen/src/lib.rs Thu Aug 29 12:56:16 2024 +0200 @@ -4,6 +4,7 @@ use self::theme::Theme; use crate::template::outline::TemplateCollectionDesc as OutlineTemplateCollectionDesc; use crate::template::wavefront_collapse::TemplateCollectionDesc as WfcTemplateCollectionDesc; +use std::path::{Path, PathBuf}; use land2d::Land2D; use landgen::{ @@ -32,12 +33,14 @@ #[derive(Debug)] pub struct MapGenerator { pub(crate) templates: HashMap>, + data_path: PathBuf, } impl MapGenerator { - pub fn new() -> Self { + pub fn new(data_path: &Path) -> Self { Self { templates: HashMap::new(), + data_path: data_path.to_owned(), } } @@ -158,7 +161,7 @@ } pub fn build_generator(&self, template: WfcTemplate) -> impl LandGenerator { - WavefrontCollapseLandGenerator::new(template) + WavefrontCollapseLandGenerator::new(template, &self.data_path) } }