--- a/rust/landgen/src/wavefront_collapse/generator.rs Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/landgen/src/wavefront_collapse/generator.rs Mon Jan 27 14:06:10 2025 +0100
@@ -364,3 +364,29 @@
}
}
}
+
+impl<T: AsRef<str>> From<T> for EdgeDescription {
+ fn from(val: T) -> Self {
+ use std::cmp::Ordering;
+
+ let reversed = val.as_ref().chars().rev().collect::<String>();
+
+ match val.as_ref().cmp(&reversed) {
+ Ordering::Less => EdgeDescription {
+ name: val.as_ref().to_owned(),
+ symmetrical: Some(false),
+ reversed: Some(false),
+ },
+ Ordering::Equal => EdgeDescription {
+ name: reversed,
+ symmetrical: Some(true),
+ reversed: Some(false),
+ },
+ Ordering::Greater => EdgeDescription {
+ name: reversed,
+ symmetrical: Some(false),
+ reversed: Some(true),
+ },
+ }
+ }
+}
--- a/rust/mapgen/src/lib.rs Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/mapgen/src/lib.rs Mon Jan 27 14:06:10 2025 +0100
@@ -2,21 +2,21 @@
pub mod theme;
use self::theme::Theme;
+use crate::template::maze::TemplateCollectionDesc as MazeTemplateCollectionDesc;
use crate::template::outline::TemplateCollectionDesc as OutlineTemplateCollectionDesc;
use crate::template::wavefront_collapse::TemplateCollectionDesc as WfcTemplateCollectionDesc;
-use crate::template::maze::TemplateCollectionDesc as MazeTemplateCollectionDesc;
use std::path::{Path, PathBuf};
use land2d::Land2D;
use landgen::{
+ maze::{MazeLandGenerator, MazeTemplate},
outline_template_based::{
outline_template::OutlineTemplate, template_based::TemplatedLandGenerator,
},
wavefront_collapse::generator::{
TemplateDescription as WfcTemplate, WavefrontCollapseLandGenerator,
},
- maze::{MazeTemplate, MazeLandGenerator},
LandGenerationParameters, LandGenerator,
};
use rand::{seq::SliceRandom, Rng};
@@ -286,9 +286,9 @@
#[cfg(test)]
mod tests {
- use std::path::Path;
use crate::{MapGenerator, OutlineTemplate, TemplateType};
use rand::thread_rng;
+ use std::path::Path;
#[test]
fn simple_load() {
--- a/rust/mapgen/src/template/mod.rs Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/mapgen/src/template/mod.rs Mon Jan 27 14:06:10 2025 +0100
@@ -1,3 +1,3 @@
+pub mod maze;
pub mod outline;
pub mod wavefront_collapse;
-pub mod maze;
--- a/rust/mapgen/src/template/outline.rs Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/mapgen/src/template/outline.rs Mon Jan 27 14:06:10 2025 +0100
@@ -64,7 +64,8 @@
})
.collect(),
walls: desc
- .walls.unwrap_or_default()
+ .walls
+ .unwrap_or_default()
.iter()
.map(|v| {
v.iter()
--- a/rust/mapgen/src/template/wavefront_collapse.rs Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/mapgen/src/template/wavefront_collapse.rs Mon Jan 27 14:06:10 2025 +0100
@@ -6,32 +6,9 @@
use std::collections::hash_map::HashMap;
#[derive(Debug, Deserialize)]
-#[serde(remote = "EdgeDescription")]
-pub struct EdgeDesc {
- pub name: String,
- pub reversed: Option<bool>,
- pub symmetrical: Option<bool>,
-}
-
-#[derive(Debug, Deserialize)]
-#[serde(remote = "EdgesDescription")]
-pub struct EdgesDesc {
- #[serde(with = "EdgeDesc")]
- pub top: EdgeDescription,
- #[serde(with = "EdgeDesc")]
- pub right: EdgeDescription,
- #[serde(with = "EdgeDesc")]
- pub bottom: EdgeDescription,
- #[serde(with = "EdgeDesc")]
- pub left: EdgeDescription,
-}
-
-#[derive(Debug, Deserialize)]
-#[serde(remote = "TileDescription")]
pub struct TileDesc {
pub name: String,
- #[serde(with = "EdgesDesc")]
- pub edges: EdgesDescription,
+ pub edges: [String; 4],
pub is_negative: Option<bool>,
pub can_flip: Option<bool>,
pub can_mirror: Option<bool>,
@@ -41,15 +18,10 @@
}
#[derive(Debug, Deserialize)]
-pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription);
-#[derive(Debug, Deserialize)]
-pub struct EdgeDescriptionHelper(#[serde(with = "EdgeDesc")] EdgeDescription);
-
-#[derive(Debug, Deserialize)]
pub struct ComplexEdgeDesc {
- pub begin: Option<EdgeDescriptionHelper>,
- pub fill: Option<EdgeDescriptionHelper>,
- pub end: Option<EdgeDescriptionHelper>,
+ pub begin: Option<String>,
+ pub fill: Option<String>,
+ pub end: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct NonStrictComplexEdgesDesc {
@@ -69,7 +41,7 @@
pub max_hedgehogs: u8,
pub wrap: bool,
pub edges: Option<NonStrictComplexEdgesDesc>,
- pub tiles: Vec<TileDescriptionHelper>,
+ pub tiles: Vec<TileDesc>,
}
#[derive(Debug, Deserialize)]
@@ -80,25 +52,17 @@
impl From<&TemplateDesc> for TemplateDescription {
fn from(desc: &TemplateDesc) -> Self {
- let [top, right, bottom, left]:[Option<ComplexEdgeDescription>; 4] = if let Some(edges) = &desc.edges {
- [
- &edges.top,
- &edges.right,
- &edges.bottom,
- &edges.left,
- ]
- .map(|e| e.as_ref().map(Into::into))
- } else {
- [None, None, None, None]
- };
+ let [top, right, bottom, left]: [Option<ComplexEdgeDescription>; 4] =
+ if let Some(edges) = &desc.edges {
+ [&edges.top, &edges.right, &edges.bottom, &edges.left]
+ .map(|e| e.as_ref().map(Into::into))
+ } else {
+ [None, None, None, None]
+ };
Self {
size: Size::new(desc.width, desc.height),
- tiles: desc
- .tiles
- .iter()
- .map(|TileDescriptionHelper(t)| t.clone())
- .collect(),
+ tiles: desc.tiles.iter().map(|t| t.into()).collect(),
wrap: desc.wrap,
can_invert: desc.can_invert,
is_negative: desc.is_negative,
@@ -112,12 +76,34 @@
}
}
+impl From<&TileDesc> for TileDescription {
+ fn from(desc: &TileDesc) -> Self {
+ let [top, right, bottom, left]: [EdgeDescription; 4] = desc.edges.clone().map(|e| e.into());
+
+ Self {
+ name: desc.name.clone(),
+ edges: EdgesDescription {
+ top,
+ right,
+ bottom,
+ left,
+ },
+ is_negative: desc.is_negative,
+ can_flip: desc.can_flip,
+ can_mirror: desc.can_mirror,
+ can_rotate90: desc.can_rotate90,
+ can_rotate180: desc.can_rotate180,
+ can_rotate270: desc.can_rotate270,
+ }
+ }
+}
+
impl From<&ComplexEdgeDesc> for ComplexEdgeDescription {
fn from(value: &ComplexEdgeDesc) -> Self {
Self {
- begin: value.begin.as_ref().map(|EdgeDescriptionHelper(e)| e.clone()),
- fill: value.fill.as_ref().map(|EdgeDescriptionHelper(e)| e.clone()),
- end: value.end.as_ref().map(|EdgeDescriptionHelper(e)| e.clone()),
+ begin: value.begin.as_ref().map(|e| e.into()),
+ fill: value.fill.as_ref().map(|e| e.into()),
+ end: value.end.as_ref().map(|e| e.into()),
}
}
}
--- a/share/hedgewars/Data/wfc_templates.yaml Mon Jan 27 13:08:58 2025 +0100
+++ b/share/hedgewars/Data/wfc_templates.yaml Mon Jan 27 14:06:10 2025 +0100
@@ -12,28 +12,12 @@
wrap: true
edges:
bottom:
- fill:
- name: "ff"
- symmetrical: true
+ fill: "ff"
top:
- fill:
- name: "ff"
- symmetrical: true
+ fill: "ff"
tiles: &template_00_tiles
- name: "120_filled.png"
- edges:
- top:
- name: "ff"
- symmetrical: true
- right:
- name: "ff"
- symmetrical: true
- bottom:
- name: "ff"
- symmetrical: true
- left:
- name: "ff"
- symmetrical: true
+ edges: ["ff", "ff", "ff", "ff"]
is_negative: true
can_mirror: false
can_flip: false
@@ -41,18 +25,7 @@
can_rotate180: false
can_rotate270: false
- name: "120_bar.png"
- edges:
- top:
- name: "ff"
- symmetrical: true
- right:
- name: "fe"
- bottom:
- name: "ee"
- symmetrical: true
- left:
- name: "fe"
- reversed: true
+ edges: ["ff", "fe", "ee", "ef"]
is_negative: true
can_mirror: false
can_flip: false
@@ -60,19 +33,7 @@
can_rotate180: true
can_rotate270: true
- name: "120_filled.png"
- edges:
- top:
- name: "ee"
- symmetrical: true
- right:
- name: "ee"
- symmetrical: true
- bottom:
- name: "ee"
- symmetrical: true
- left:
- name: "ee"
- symmetrical: true
+ edges: ["ee", "ee", "ee", "ee"]
is_negative: false
can_mirror: false
can_flip: false
@@ -80,18 +41,7 @@
can_rotate180: false
can_rotate270: false
- name: "120_corner.png"
- edges:
- top:
- name: "fe"
- right:
- name: "ee"
- symmetrical: true
- bottom:
- name: "ee"
- symmetrical: true
- left:
- name: "fe"
- reversed: true
+ edges: ["fe", "ee", "ee", "ef"]
is_negative: true
can_mirror: false
can_flip: false
@@ -99,18 +49,7 @@
can_rotate180: true
can_rotate270: true
- name: "120_corner.png"
- edges:
- top:
- name: "fe"
- reversed: true
- right:
- name: "ff"
- symmetrical: true
- bottom:
- name: "ff"
- symmetrical: true
- left:
- name: "fe"
+ edges: ["ef", "ff", "ff", "fe"]
is_negative: false
can_mirror: false
can_flip: false
@@ -118,17 +57,7 @@
can_rotate180: true
can_rotate270: true
- name: "120_two_corners.png"
- edges:
- top:
- name: "fe"
- right:
- name: "fe"
- reversed: true
- bottom:
- name: "fe"
- left:
- name: "fe"
- reversed: true
+ edges: ["fe", "ef", "fe", "ef"]
is_negative: true
can_mirror: true
can_flip: false
@@ -146,44 +75,21 @@
wrap: false
edges: &open_edges
top:
- begin:
- name: "ee"
- symmetrical: true
- fill:
- name: "ee"
- symmetrical: true
- end:
- name: "ee"
- symmetrical: true
+ begin: "ee"
+ fill: "ee"
+ end: "ee"
right:
- begin:
- name: "ee"
- symmetrical: true
- fill:
- name: "ee"
- symmetrical: true
- end:
- name: "ee"
- symmetrical: true
+ begin: "ee"
+ fill: "ee"
+ end: "ee"
bottom:
- begin:
- name: "fe"
- reversed: true
- fill:
- name: "ff"
- symmetrical: true
- end:
- name: "fe"
+ begin: "ef"
+ fill: "ff"
+ end: "fe"
left:
- begin:
- name: "ee"
- symmetrical: true
- fill:
- name: "ee"
- symmetrical: true
- end:
- name: "ee"
- symmetrical: true
+ begin: "ee"
+ fill: "ee"
+ end: "ee"
tiles: *template_00_tiles
- &template_02
@@ -230,172 +136,66 @@
wrap: true
edges:
bottom:
- fill:
- name: "fff"
- symmetrical: true
+ fill: "ff"
tiles: &rooms_tiles
- name: "bend_120.png"
- edges:
- top:
- name: "fee"
- right:
- name: "fee"
- reversed: true
- bottom:
- name: "fff"
- symmetrical: true
- left:
- name: "fff"
- symmetrical: true
+ edges: ["fee", "fee", "fff", "fff"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "corner_120.png"
- edges:
- top:
- name: "fee"
- reversed: true
- right:
- name: "fee"
- bottom:
- name: "eee"
- symmetrical: true
- left:
- name: "eee"
- symmetrical: true
+ edges: ["eef", "fee", "eee", "eee"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "corridor_120.png"
- edges:
- top:
- name: "efe"
- symmetrical: true
- right:
- name: "eee"
- symmetrical: true
- bottom:
- name: "eee"
- symmetrical: true
- left:
- name: "efe"
- symmetrical: true
+ edges: ["efe", "eee", "eee", "efe"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: false
can_rotate270: false
- name: "door_120.png"
- edges:
- top:
- name: "fff"
- symmetrical: true
- right:
- name: "fee"
- bottom:
- name: "efe"
- symmetrical: true
- left:
- name: "fee"
- reversed: true
+ edges: ["fff", "fee", "efe", "eef"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "empty_120.png"
- edges:
- top:
- name: "fff"
- symmetrical: true
- right:
- name: "fff"
- symmetrical: true
- bottom:
- name: "fff"
- symmetrical: true
- left:
- name: "fff"
- symmetrical: true
+ edges: ["fff", "fff", "fff", "fff"]
can_mirror: false
can_flip: false
can_rotate90: false
can_rotate180: false
can_rotate270: false
- name: "side_120.png"
- edges:
- top:
- name: "eee"
- symmetrical: true
- right:
- name: "fee"
- reversed: true
- bottom:
- name: "fff"
- symmetrical: true
- left:
- name: "fee"
+ edges: ["eee", "eef", "fff", "fee"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "t_120.png"
- edges:
- top:
- name: "eee"
- symmetrical: true
- right:
- name: "efe"
- symmetrical: true
- bottom:
- name: "efe"
- symmetrical: true
- left:
- name: "efe"
- symmetrical: true
+ edges: ["eee", "efe", "efe", "efe"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "turn_120.png"
- edges:
- top:
- name: "efe"
- symmetrical: true
- right:
- name: "efe"
- symmetrical: true
- bottom:
- name: "eee"
- symmetrical: true
- left:
- name: "eee"
- symmetrical: true
+ edges: ["efe", "efe", "eee", "eee"]
can_mirror: false
can_flip: false
can_rotate90: true
can_rotate180: true
can_rotate270: true
- name: "wall_120.png"
- edges:
- top:
- name: "eee"
- symmetrical: true
- right:
- name: "eee"
- symmetrical: true
- bottom:
- name: "eee"
- symmetrical: true
- left:
- name: "eee"
- symmetrical: true
+ edges: ["eee", "eee", "eee", "eee"]
can_mirror: false
can_flip: false
can_rotate90: false