--- a/rust/lib-hwengine-future/src/lib.rs Mon Jan 27 14:06:10 2025 +0100
+++ b/rust/lib-hwengine-future/src/lib.rs Mon Jan 27 15:48:24 2025 +0100
@@ -103,7 +103,7 @@
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes());
let yaml_templates =
- fs::read_to_string(data_path.join(Path::new("wfc_templates.yaml")).as_path())
+ fs::read_to_string(data_path.join(Path::new("wfc_templates.toml")).as_path())
.expect("Error reading map templates file");
let mut map_gen = MapGenerator::<WfcTemplate>::new(data_path);
map_gen.import_yaml_templates(&yaml_templates);
--- a/rust/mapgen/Cargo.toml Mon Jan 27 14:06:10 2025 +0100
+++ b/rust/mapgen/Cargo.toml Mon Jan 27 15:48:24 2025 +0100
@@ -8,7 +8,6 @@
vec2d = { path = "../vec2d" }
land2d = { path = "../land2d" }
landgen = { path = "../landgen" }
-lfprng = { path = "../lfprng" }
integral-geometry = { path = "../integral-geometry" }
rand = "0.8"
@@ -16,3 +15,4 @@
serde_yaml = "0.9"
serde_derive = "1.0"
png = "0.17"
+toml = "0.8"
--- a/rust/mapgen/src/lib.rs Mon Jan 27 14:06:10 2025 +0100
+++ b/rust/mapgen/src/lib.rs Mon Jan 27 15:48:24 2025 +0100
@@ -160,7 +160,7 @@
impl MapGenerator<WfcTemplate> {
pub fn import_yaml_templates(&mut self, text: &str) {
- let mut desc: WfcTemplateCollectionDesc = serde_yaml::from_str(text).unwrap();
+ let mut desc: WfcTemplateCollectionDesc = toml::from_str(text).unwrap();
let templates = std::mem::take(&mut desc.templates);
self.templates = desc
.template_types
@@ -168,7 +168,7 @@
.map(|(size, indices)| {
(
TemplateType(size),
- indices.iter().map(|i| (&templates[*i]).into()).collect(),
+ indices.iter().map(|i| (&templates[*i]).to_template(&desc.tiles, &desc.edges)).collect(),
)
})
.collect();
--- a/rust/mapgen/src/template/wavefront_collapse.rs Mon Jan 27 14:06:10 2025 +0100
+++ b/rust/mapgen/src/template/wavefront_collapse.rs Mon Jan 27 15:48:24 2025 +0100
@@ -35,37 +35,42 @@
pub struct TemplateDesc {
pub width: usize,
pub height: usize,
- pub can_invert: bool,
- pub is_negative: bool,
- pub put_girders: bool,
+ pub can_invert: Option<bool>,
+ pub is_negative: Option<bool>,
+ pub put_girders: Option<bool>,
pub max_hedgehogs: u8,
- pub wrap: bool,
- pub edges: Option<NonStrictComplexEdgesDesc>,
- pub tiles: Vec<TileDesc>,
+ pub wrap: Option<bool>,
+ pub edges: Option<String>,
+ pub tiles: Vec<String>,
}
#[derive(Debug, Deserialize)]
pub struct TemplateCollectionDesc {
pub templates: Vec<TemplateDesc>,
+ pub tiles: HashMap<String, Vec<TileDesc>>,
+ pub edges: HashMap<String, NonStrictComplexEdgesDesc>,
pub template_types: HashMap<String, Vec<usize>>,
}
-impl From<&TemplateDesc> for TemplateDescription {
- fn from(desc: &TemplateDesc) -> Self {
+impl TemplateDesc {
+ pub fn to_template(&self, tiles: &HashMap<String, Vec<TileDesc>>, edges: &HashMap<String, NonStrictComplexEdgesDesc>) -> TemplateDescription {
let [top, right, bottom, left]: [Option<ComplexEdgeDescription>; 4] =
- if let Some(edges) = &desc.edges {
+ if let Some(edges_name) = &self.edges {
+ let edges = edges.get(edges_name).expect("missing template 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(|t| t.into()).collect(),
- wrap: desc.wrap,
- can_invert: desc.can_invert,
- is_negative: desc.is_negative,
+ let tiles = self.tiles.iter().flat_map(|t| tiles.get(t).expect("missing template tiles")).collect::<Vec<_>>();
+
+ TemplateDescription {
+ size: Size::new(self.width, self.height),
+ tiles: tiles.into_iter().map(|t| t.into()).collect(),
+ wrap: self.wrap.unwrap_or(false),
+ can_invert: self.can_invert.unwrap_or(false),
+ is_negative: self.is_negative.unwrap_or(false),
edges: NonStrictComplexEdgesDescription {
top,
right,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/wfc_templates.toml Mon Jan 27 15:48:24 2025 +0100
@@ -0,0 +1,237 @@
+# Templates for wavefront collapse map generator in hedgewars
+
+################ TILES ################
+# round120 tiles
+[[tiles.round120]]
+name = "120_filled.png"
+edges = [ "f", "f", "f", "f" ]
+is_negative = true
+can_mirror = false
+can_flip = false
+can_rotate90 = false
+can_rotate180 = false
+can_rotate270 = false
+
+[[tiles.round120]]
+name = "120_bar.png"
+edges = [ "f", "fe", "e", "ef" ]
+is_negative = true
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.round120]]
+name = "120_filled.png"
+edges = [ "e", "e", "e", "e" ]
+is_negative = false
+can_mirror = false
+can_flip = false
+can_rotate90 = false
+can_rotate180 = false
+can_rotate270 = false
+
+[[tiles.round120]]
+name = "120_corner.png"
+edges = [ "fe", "e", "e", "ef" ]
+is_negative = true
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.round120]]
+name = "120_corner.png"
+edges = [ "ef", "f", "f", "fe" ]
+is_negative = false
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.round120]]
+name = "120_two_corners.png"
+edges = [ "fe", "ef", "fe", "ef" ]
+is_negative = true
+can_mirror = true
+can_flip = false
+can_rotate90 = false
+can_rotate180 = false
+can_rotate270 = false
+
+# Rooms tiles
+[[tiles.Rooms]]
+name = "bend_120.png"
+edges = [ "fee", "fee", "f", "f" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "corner_120.png"
+edges = [ "eef", "fee", "e", "e" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "corridor_120.png"
+edges = [ "efe", "e", "e", "efe" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = false
+can_rotate270 = false
+
+[[tiles.Rooms]]
+name = "door_120.png"
+edges = [ "f", "fee", "efe", "eef" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "empty_120.png"
+edges = [ "f", "f", "f", "f" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = false
+can_rotate180 = false
+can_rotate270 = false
+
+[[tiles.Rooms]]
+name = "side_120.png"
+edges = [ "e", "eef", "f", "fee" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "t_120.png"
+edges = [ "e", "efe", "efe", "efe" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "turn_120.png"
+edges = [ "efe", "efe", "e", "e" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = true
+can_rotate180 = true
+can_rotate270 = true
+
+[[tiles.Rooms]]
+name = "wall_120.png"
+edges = [ "e", "e", "e", "e" ]
+can_mirror = false
+can_flip = false
+can_rotate90 = false
+can_rotate180 = false
+can_rotate270 = false
+
+################ EDGES ################
+[edges.bottom_row]
+top = { begin = "e", fill = "e", end = "e" }
+right = { begin = "e", fill = "e", end = "e" }
+bottom = { begin = "ef", fill = "f", end = "fe" }
+left = { begin = "e", fill = "e", end = "e" }
+
+[edges.top_bottom]
+top.fill = "f"
+bottom.fill = "f"
+
+################ TEMPLATES ################
+[[templates]]
+# 0
+width = 3960
+height = 1920
+can_invert = false
+is_negative = false
+put_girders = true
+max_hedgehogs = 40
+wrap = true
+edges = "top_bottom"
+tiles = [ "round120" ]
+
+[[templates]]
+# 1
+width = 3960
+height = 1920
+can_invert = false
+is_negative = false
+put_girders = true
+max_hedgehogs = 40
+wrap = false
+edges = "bottom_row"
+tiles = [ "round120" ]
+
+[[templates]]
+# 2
+width = 1200
+height = 600
+can_invert = false
+is_negative = false
+put_girders = true
+max_hedgehogs = 24
+wrap = false
+edges = "bottom_row"
+tiles = [ "round120" ]
+
+[[templates]]
+# 3
+width = 720
+height = 7920
+can_invert = false
+is_negative = false
+put_girders = true
+max_hedgehogs = 64
+wrap = false
+edges = "bottom_row"
+tiles = [ "round120" ]
+
+[[templates]]
+# 4
+width = 2200
+height = 960
+can_invert = false
+is_negative = false
+put_girders = true
+max_hedgehogs = 24
+wrap = false
+edges = "bottom_row"
+tiles = [ "round120" ]
+
+[[templates]]
+# 4
+width = 3960
+height = 1920
+can_invert = false
+is_negative = true
+put_girders = true
+max_hedgehogs = 40
+wrap = true
+edges = "top_bottom"
+tiles = [ "Rooms" ]
+
+
+[template_types]
+small = [ 2 ]
+medium = [ 4 ]
+large = [ 1 ]
+cavern = [ 0, 5 ]
+wacky = [ 3 ]
--- a/share/hedgewars/Data/wfc_templates.yaml Mon Jan 27 14:06:10 2025 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,210 +0,0 @@
----
-# Templates for wavefront collapse map generator in hedgewars
-
-templates:
- - &template_00
- width: 3960
- height: 1920
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 40
- wrap: true
- edges:
- bottom:
- fill: "ff"
- top:
- fill: "ff"
- tiles: &template_00_tiles
- - name: "120_filled.png"
- edges: ["ff", "ff", "ff", "ff"]
- is_negative: true
- can_mirror: false
- can_flip: false
- can_rotate90: false
- can_rotate180: false
- can_rotate270: false
- - name: "120_bar.png"
- edges: ["ff", "fe", "ee", "ef"]
- is_negative: true
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "120_filled.png"
- edges: ["ee", "ee", "ee", "ee"]
- is_negative: false
- can_mirror: false
- can_flip: false
- can_rotate90: false
- can_rotate180: false
- can_rotate270: false
- - name: "120_corner.png"
- edges: ["fe", "ee", "ee", "ef"]
- is_negative: true
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "120_corner.png"
- edges: ["ef", "ff", "ff", "fe"]
- is_negative: false
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "120_two_corners.png"
- edges: ["fe", "ef", "fe", "ef"]
- is_negative: true
- can_mirror: true
- can_flip: false
- can_rotate90: false
- can_rotate180: false
- can_rotate270: false
-
- - &template_01
- width: 3960
- height: 1920
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 40
- wrap: false
- edges: &open_edges
- top:
- begin: "ee"
- fill: "ee"
- end: "ee"
- right:
- begin: "ee"
- fill: "ee"
- end: "ee"
- bottom:
- begin: "ef"
- fill: "ff"
- end: "fe"
- left:
- begin: "ee"
- fill: "ee"
- end: "ee"
- tiles: *template_00_tiles
-
- - &template_02
- width: 1200
- height: 600
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 24
- wrap: false
- edges: *open_edges
- tiles: *template_00_tiles
-
- - &template_03
- width: 720
- height: 7920
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 64
- wrap: false
- edges: *open_edges
- tiles: *template_00_tiles
-
-
- - &template_04
- width: 2200
- height: 960
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 24
- wrap: false
- edges: *open_edges
- tiles: *template_00_tiles
-
- - &template_05
- width: 3960
- height: 1920
- can_invert: false
- is_negative: false
- put_girders: true
- max_hedgehogs: 40
- wrap: true
- edges:
- bottom:
- fill: "ff"
- tiles: &rooms_tiles
- - name: "bend_120.png"
- 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: ["eef", "fee", "eee", "eee"]
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "corridor_120.png"
- 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: ["fff", "fee", "efe", "eef"]
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "empty_120.png"
- 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: ["eee", "eef", "fff", "fee"]
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "t_120.png"
- 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: ["efe", "efe", "eee", "eee"]
- can_mirror: false
- can_flip: false
- can_rotate90: true
- can_rotate180: true
- can_rotate270: true
- - name: "wall_120.png"
- edges: ["eee", "eee", "eee", "eee"]
- can_mirror: false
- can_flip: false
- can_rotate90: false
- can_rotate180: false
- can_rotate270: false
-
-template_types:
- small: [2]
- medium: [4]
- large: [1]
- cavern: [0, 5]
- wacky: [3]