From 703ea57f6abf89db6544d28258882c9a0cfb8580 Mon Sep 17 00:00:00 2001 From: KyoZM Date: Tue, 8 Oct 2019 22:17:37 -0300 Subject: [PATCH 1/4] load structures from ron files / transfer static structure lists to ron files --- Cargo.lock | 2 + assets/world/manifests/acacias.ron | 24 ++ assets/world/manifests/fruit_trees.ron | 28 +++ assets/world/manifests/mangrove_trees.ron | 36 +++ assets/world/manifests/oak_stumps.ron | 40 ++++ assets/world/manifests/oaks.ron | 40 ++++ assets/world/manifests/palms.ron | 44 ++++ assets/world/manifests/pines.ron | 36 +++ assets/world/manifests/quirky.ron | 12 + assets/world/manifests/quirky_dry.ron | 16 ++ assets/world/manifests/snow_pines.ron | 36 +++ world/Cargo.toml | 2 + world/src/block/natural.rs | 254 +++++----------------- 13 files changed, 372 insertions(+), 198 deletions(-) create mode 100644 assets/world/manifests/acacias.ron create mode 100644 assets/world/manifests/fruit_trees.ron create mode 100644 assets/world/manifests/mangrove_trees.ron create mode 100644 assets/world/manifests/oak_stumps.ron create mode 100644 assets/world/manifests/oaks.ron create mode 100644 assets/world/manifests/palms.ron create mode 100644 assets/world/manifests/pines.ron create mode 100644 assets/world/manifests/quirky.ron create mode 100644 assets/world/manifests/quirky_dry.ron create mode 100644 assets/world/manifests/snow_pines.ron diff --git a/Cargo.lock b/Cargo.lock index 7c1fefb6a7..3386518162 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3662,6 +3662,8 @@ dependencies = [ "noise 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", "vek 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", "veloren-common 0.4.0", ] diff --git a/assets/world/manifests/acacias.ron b/assets/world/manifests/acacias.ron new file mode 100644 index 0000000000..20a86a4d06 --- /dev/null +++ b/assets/world/manifests/acacias.ron @@ -0,0 +1,24 @@ +( + [ + ( + specifier: "world.tree.acacia.1", + center: (16, 17, 1) + ), + ( + specifier: "world.tree.acacia.2", + center: (5, 6, 1) + ), + ( + specifier: "world.tree.acacia.3", + center: (5, 6, 1) + ), + ( + specifier: "world.tree.acacia.4", + center: (15, 16, 1) + ), + ( + specifier: "world.tree.acacia.5", + center: (19, 18, 1) + ), + ] +) diff --git a/assets/world/manifests/fruit_trees.ron b/assets/world/manifests/fruit_trees.ron new file mode 100644 index 0000000000..0e8d4262bf --- /dev/null +++ b/assets/world/manifests/fruit_trees.ron @@ -0,0 +1,28 @@ +( + [ + ( + specifier: "world.tree.fruit.1", + center: (5, 5, 7) + ), + ( + specifier: "world.tree.fruit.2", + center: (6, 6, 7) + ), + ( + specifier: "world.tree.fruit.3", + center: (6, 7, 7) + ), + ( + specifier: "world.tree.fruit.4", + center: (3, 3, 7) + ), + ( + specifier: "world.tree.fruit.5", + center: (6, 8, 7) + ), + ( + specifier: "world.tree.fruit.6", + center: (7, 7, 7) + ), + ] +) diff --git a/assets/world/manifests/mangrove_trees.ron b/assets/world/manifests/mangrove_trees.ron new file mode 100644 index 0000000000..525cdb9b41 --- /dev/null +++ b/assets/world/manifests/mangrove_trees.ron @@ -0,0 +1,36 @@ +( + [ + ( + specifier: "world.tree.mangroves.1", + center: (18, 18, 8) + ), + ( + specifier: "world.tree.mangroves.2", + center: (16, 17, 7) + ), + ( + specifier: "world.tree.mangroves.3", + center: (18, 18, 8) + ), + ( + specifier: "world.tree.mangroves.4", + center: (18, 16, 8) + ), + ( + specifier: "world.tree.mangroves.5", + center: (19, 20, 9) + ), + ( + specifier: "world.tree.mangroves.6", + center: (18, 18, 9) + ), + ( + specifier: "world.tree.mangroves.7", + center: (18, 17, 9) + ), + ( + specifier: "world.tree.mangroves.8", + center: (18, 18, 9) + ), + ] +) diff --git a/assets/world/manifests/oak_stumps.ron b/assets/world/manifests/oak_stumps.ron new file mode 100644 index 0000000000..888cb76d74 --- /dev/null +++ b/assets/world/manifests/oak_stumps.ron @@ -0,0 +1,40 @@ +( + [ + ( + specifier: "world.tree.oak_stump.1", + center: (15, 18, 10) + ), + ( + specifier: "world.tree.oak_stump.2", + center: (15, 18, 10) + ), + ( + specifier: "world.tree.oak_stump.3", + center: (16, 20, 10) + ), + ( + specifier: "world.tree.oak_stump.4", + center: (18, 21, 10) + ), + ( + specifier: "world.tree.oak_stump.5", + center: (18, 18, 10) + ), + ( + specifier: "world.tree.oak_stump.6", + center: (16, 21, 10) + ), + ( + specifier: "world.tree.oak_stump.7", + center: (20, 19, 10) + ), + ( + specifier: "world.tree.oak_stump.8", + center: (22, 20, 10) + ), + ( + specifier: "world.tree.oak_stump.9", + center:(26, 26, 10) + ), + ] +) diff --git a/assets/world/manifests/oaks.ron b/assets/world/manifests/oaks.ron new file mode 100644 index 0000000000..81301c48c1 --- /dev/null +++ b/assets/world/manifests/oaks.ron @@ -0,0 +1,40 @@ +( + [ + ( + specifier: "world.tree.oak_green.1", + center: (15, 18, 14) + ), + ( + specifier: "world.tree.oak_green.2", + center: (15, 18, 14) + ), + ( + specifier: "world.tree.oak_green.3", + center: (16, 20, 14) + ), + ( + specifier: "world.tree.oak_green.4", + center: (18, 21, 14) + ), + ( + specifier: "world.tree.oak_green.5", + center: (18, 18, 14) + ), + ( + specifier: "world.tree.oak_green.6", + center: (16, 21, 14) + ), + ( + specifier: "world.tree.oak_green.7", + center: (20, 19, 14) + ), + ( + specifier: "world.tree.oak_green.8", + center: (22, 20, 14) + ), + ( + specifier: "world.tree.oak_green.9", + center:(26, 26, 14) + ), + ] +) diff --git a/assets/world/manifests/palms.ron b/assets/world/manifests/palms.ron new file mode 100644 index 0000000000..2e6aa30758 --- /dev/null +++ b/assets/world/manifests/palms.ron @@ -0,0 +1,44 @@ +( + [ + ( + specifier: "world.tree.desert_palm.1", + center: (12, 12, 10) + ), + ( + specifier: "world.tree.desert_palm.2", + center: (12, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.3", + center: (12, 12, 10) + ), + ( + specifier: "world.tree.desert_palm.4", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.5", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.6", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.7", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.8", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.9", + center: (10, 10, 10) + ), + ( + specifier: "world.tree.desert_palm.10", + center: (10, 10, 10) + ), + ] +) diff --git a/assets/world/manifests/pines.ron b/assets/world/manifests/pines.ron new file mode 100644 index 0000000000..17d3de6ba1 --- /dev/null +++ b/assets/world/manifests/pines.ron @@ -0,0 +1,36 @@ +( + [ + ( + specifier: "world.tree.pine_green.1", + center: (15, 15, 14) + ), + ( + specifier: "world.tree.pine_green.2", + center: (15, 15, 14) + ), + ( + specifier: "world.tree.pine_green.3", + center: (17, 15, 12) + ), + ( + specifier: "world.tree.pine_green.4", + center: (10, 8, 12) + ), + ( + specifier: "world.tree.pine_green.5", + center: (12, 12, 12) + ), + ( + specifier: "world.tree.pine_green.6", + center: (11, 10, 12) + ), + ( + specifier: "world.tree.pine_green.7", + center: (16, 15, 12) + ), + ( + specifier: "world.tree.pine_green.8", + center: (12, 10, 12) + ), + ] +) diff --git a/assets/world/manifests/quirky.ron b/assets/world/manifests/quirky.ron new file mode 100644 index 0000000000..487c05d9c1 --- /dev/null +++ b/assets/world/manifests/quirky.ron @@ -0,0 +1,12 @@ +( + [ + ( + specifier: "world.structure.natural.tower-ruin", + center: (11, 14, 5) + ), + ( + specifier: "world.structure.natural.witch-hut", + center: (10, 13, 9) + ), + ] +) diff --git a/assets/world/manifests/quirky_dry.ron b/assets/world/manifests/quirky_dry.ron new file mode 100644 index 0000000000..cad8c89187 --- /dev/null +++ b/assets/world/manifests/quirky_dry.ron @@ -0,0 +1,16 @@ +( + [ + ( + specifier: "world.structure.natural.ribcage-small", + center: (7, 13, 4) + ), + ( + specifier: "world.structure.natural.ribcage-large", + center: (13, 19, 8) + ), + ( + specifier: "world.structure.natural.skull-large", + center: (15, 20, 4) + ), + ] +) diff --git a/assets/world/manifests/snow_pines.ron b/assets/world/manifests/snow_pines.ron new file mode 100644 index 0000000000..88561a9c20 --- /dev/null +++ b/assets/world/manifests/snow_pines.ron @@ -0,0 +1,36 @@ +( + [ + ( + specifier: "world.tree.snow_pine.1", + center: (15, 15, 14) + ), + ( + specifier: "world.tree.snow_pine.2", + center: (15, 15, 14) + ), + ( + specifier: "world.tree.snow_pine.3", + center: (17, 15, 12) + ), + ( + specifier: "world.tree.snow_pine.4", + center: (10, 8, 12) + ), + ( + specifier: "world.tree.snow_pine.5", + center: (12, 12, 12) + ), + ( + specifier: "world.tree.snow_pine.6", + center: (11, 10, 12) + ), + ( + specifier: "world.tree.snow_pine.7", + center: (16, 15, 12) + ), + ( + specifier: "world.tree.snow_pine.8", + center: (12, 10, 12) + ) + ], +) diff --git a/world/Cargo.toml b/world/Cargo.toml index 84cc850370..e356364917 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -13,6 +13,8 @@ lazy_static = "1.4.0" rand = "0.7.2" rand_chacha = "0.2.1" arr_macro = "0.1.2" +serde = "1.0.101" +ron = "0.5.1" [dev-dependencies] minifb = { git = "https://github.com/emoon/rust_minifb.git" } diff --git a/world/src/block/natural.rs b/world/src/block/natural.rs index 1009237b00..d98d7f3f8c 100644 --- a/world/src/block/natural.rs +++ b/world/src/block/natural.rs @@ -5,8 +5,13 @@ use crate::{ util::{RandomPerm, Sampler, SmallCache, UnitChooser}, CONFIG, }; +use common::assets::Asset; use common::{assets, terrain::Structure}; use lazy_static::lazy_static; +use ron; +use serde::Deserialize; +use std::fs::File; +use std::io::BufReader; use std::sync::Arc; use std::u32; use vek::*; @@ -76,101 +81,62 @@ pub fn structure_gen<'a>( }) } -fn st_asset(path: &str, offset: impl Into>) -> Arc { - assets::load_map(path, |s: Structure| s.with_center(offset.into())) - .expect("Failed to load structure asset") +#[derive(Deserialize)] +struct StructureSpec { + specifier: String, + center: [i32; 3], +} +#[derive(Deserialize)] +struct StructuresSpec(Vec); + +impl Asset for StructuresSpec { + const ENDINGS: &'static [&'static str] = &["ron"]; + fn parse(buf_reader: BufReader) -> Result { + Ok(ron::de::from_reader(buf_reader).expect("Error parsing structure specs")) + } +} + +fn convert(specifications: &StructuresSpec) -> Vec> { + return specifications + .0 + .iter() + .map(|sp| { + assets::load_map(&sp.specifier[..], |s: Structure| { + s.with_center(Vec3::from(sp.center)) + }) + .unwrap() + }) + .collect(); +} + +fn load_structures(specifier: &str) -> Vec> { + dbg!(specifier); + let spec = assets::load::(&["world.manifests.", specifier].concat()); + return convert(&spec.unwrap()); } lazy_static! { - pub static ref OAKS: Vec> = vec![ - // green oaks - assets::load_map("world.tree.oak_green.1", |s: Structure| s - .with_center(Vec3::new(15, 18, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.2", |s: Structure| s - .with_center(Vec3::new(15, 18, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.3", |s: Structure| s - .with_center(Vec3::new(16, 20, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.4", |s: Structure| s - .with_center(Vec3::new(18, 21, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.5", |s: Structure| s - .with_center(Vec3::new(18, 18, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.6", |s: Structure| s - .with_center(Vec3::new(16, 21, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.7", |s: Structure| s - .with_center(Vec3::new(20, 19, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.8", |s: Structure| s - .with_center(Vec3::new(22, 20, 14))) - .unwrap(), - assets::load_map("world.tree.oak_green.9", |s: Structure| s - .with_center(Vec3::new(26, 26, 14))) - .unwrap(), - ]; + pub static ref OAKS: Vec> = load_structures("oaks"); - pub static ref OAK_STUMPS: Vec> = vec![ - // oak stumps - assets::load_map("world.tree.oak_stump.1", |s: Structure| s - .with_center(Vec3::new(15, 18, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.2", |s: Structure| s - .with_center(Vec3::new(15, 18, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.3", |s: Structure| s - .with_center(Vec3::new(16, 20, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.4", |s: Structure| s - .with_center(Vec3::new(18, 21, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.5", |s: Structure| s - .with_center(Vec3::new(18, 18, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.6", |s: Structure| s - .with_center(Vec3::new(16, 21, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.7", |s: Structure| s - .with_center(Vec3::new(20, 19, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.8", |s: Structure| s - .with_center(Vec3::new(22, 20, 10))) - .unwrap(), - assets::load_map("world.tree.oak_stump.9", |s: Structure| s - .with_center(Vec3::new(26, 26, 10))) - .unwrap(), - ]; + pub static ref OAK_STUMPS: Vec> = load_structures("oak_stumps"); - pub static ref PINES: Vec> = vec![ - // green pines - assets::load_map("world.tree.pine_green.1", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world.tree.pine_green.2", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world.tree.pine_green.3", |s: Structure| s - .with_center(Vec3::new(17, 15, 12))) - .unwrap(), - assets::load_map("world.tree.pine_green.4", |s: Structure| s - .with_center(Vec3::new(10, 8, 12))) - .unwrap(), - assets::load_map("world.tree.pine_green.5", |s: Structure| s - .with_center(Vec3::new(12, 12, 12))) - .unwrap(), - assets::load_map("world.tree.pine_green.6", |s: Structure| s - .with_center(Vec3::new(11, 10, 12))) - .unwrap(), - assets::load_map("world.tree.pine_green.7", |s: Structure| s - .with_center(Vec3::new(16, 15, 12))) - .unwrap(), - assets::load_map("world.tree.pine_green.8", |s: Structure| s - .with_center(Vec3::new(12, 10, 12))) - .unwrap(), - /* + pub static ref PINES: Vec> = load_structures("pines"); + + pub static ref PALMS: Vec> = load_structures("palms"); + + pub static ref SNOW_PINES: Vec> = load_structures("snow_pines"); + + pub static ref ACACIAS: Vec> = load_structures("acacias"); + + pub static ref FRUIT_TREES: Vec> = load_structures("fruit_trees"); + + pub static ref MANGROVE_TREES: Vec> = load_structures("mangrove_trees"); + + pub static ref QUIRKY: Vec> = load_structures("quirky"); + + pub static ref QUIRKY_DRY: Vec> = load_structures("quirky_dry"); + + /* // green pines 2 assets::load_map("world/tree/pine_green_2/1", |s: Structure| s .with_center(Vec3::new(15, 15, 14))) @@ -222,7 +188,6 @@ lazy_static! { .with_center(Vec3::new(12, 10, 12))) .unwrap(), */ - ]; /* // temperate small assets::load_map("world/tree/temperate_small/1", |s: Structure| s @@ -312,72 +277,6 @@ lazy_static! { .with_center(Vec3::new(7, 7, 10))) .unwrap(), */ - - pub static ref PALMS: Vec> = vec![ - // palm trees - assets::load_map("world.tree.desert_palm.1", |s: Structure| s - .with_center(Vec3::new(12, 12, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.2", |s: Structure| s - .with_center(Vec3::new(12, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.3", |s: Structure| s - .with_center(Vec3::new(12, 12, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.4", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.5", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.6", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.7", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.8", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.9", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world.tree.desert_palm.10", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - ]; - - pub static ref SNOW_PINES: Vec> = vec![ - // snow pines - st_asset("world.tree.snow_pine.1", (15, 15, 14)), - st_asset("world.tree.snow_pine.2", (15, 15, 14)), - st_asset("world.tree.snow_pine.3", (17, 15, 12)), - st_asset("world.tree.snow_pine.4", (10, 8, 12)), - st_asset("world.tree.snow_pine.5", (12, 12, 12)), - st_asset("world.tree.snow_pine.6", (11, 10, 12)), - st_asset("world.tree.snow_pine.7", (16, 15, 12)), - st_asset("world.tree.snow_pine.8", (12, 10, 12)), - ]; - - pub static ref ACACIAS: Vec> = vec![ - // acias - st_asset("world.tree.acacia.1", (16, 17, 1)), - st_asset("world.tree.acacia.2", (5, 6, 1)), - st_asset("world.tree.acacia.3", (5, 6, 1)), - st_asset("world.tree.acacia.4", (15, 16, 1)), - st_asset("world.tree.acacia.5", (19, 18, 1)), - ]; - - pub static ref FRUIT_TREES: Vec> = vec![ - // fruit trees - st_asset("world.tree.fruit.1", (5, 5, 7)), - st_asset("world.tree.fruit.2", (6, 6, 7)), - st_asset("world.tree.fruit.3", (6, 7, 7)), - st_asset("world.tree.fruit.4", (3, 3, 7)), - st_asset("world.tree.fruit.5", (6, 8, 7)), - st_asset("world.tree.fruit.6", (7, 7, 7)), - ]; - /* // snow birches -> need roots! assets::load_map("world/tree/snow_birch/1", |s: Structure| s @@ -425,45 +324,4 @@ lazy_static! { .unwrap(), ]; */ - - pub static ref MANGROVE_TREES: Vec> = vec![ - // oak stumps - assets::load_map("world.tree.mangroves.1", |s: Structure| s - .with_center(Vec3::new(18, 18, 8))) - .unwrap(), - assets::load_map("world.tree.mangroves.2", |s: Structure| s - .with_center(Vec3::new(16, 17, 7))) - .unwrap(), - assets::load_map("world.tree.mangroves.3", |s: Structure| s - .with_center(Vec3::new(18, 18, 8))) - .unwrap(), - assets::load_map("world.tree.mangroves.4", |s: Structure| s - .with_center(Vec3::new(18, 16, 8))) - .unwrap(), - assets::load_map("world.tree.mangroves.5", |s: Structure| s - .with_center(Vec3::new(19, 20, 9))) - .unwrap(), - assets::load_map("world.tree.mangroves.6", |s: Structure| s - .with_center(Vec3::new(18, 18, 9))) - .unwrap(), - assets::load_map("world.tree.mangroves.7", |s: Structure| s - .with_center(Vec3::new(18, 17, 9))) - .unwrap(), - assets::load_map("world.tree.mangroves.8", |s: Structure| s - .with_center(Vec3::new(18, 18, 9))) - .unwrap(), - ]; - - pub static ref QUIRKY: Vec> = vec![ - st_asset("world.structure.natural.tower-ruin", (11, 14, 5)), - st_asset("world.structure.natural.witch-hut", (10, 13, 9)), - ]; - - pub static ref QUIRKY_DRY: Vec> = vec![ - st_asset("world.structure.natural.ribcage-small", (7, 13, 4)), - st_asset("world.structure.natural.ribcage-large", (13, 19, 8)), - st_asset("world.structure.natural.skull-large", (15, 20, 4)), - ]; - - } From e8d81798995d31d667813938bd6ddc971d9eba4e Mon Sep 17 00:00:00 2001 From: KyoZM Date: Thu, 10 Oct 2019 20:47:29 -0300 Subject: [PATCH 2/4] remove unecessary comments --- world/src/block/natural.rs | 189 ------------------------------------- 1 file changed, 189 deletions(-) diff --git a/world/src/block/natural.rs b/world/src/block/natural.rs index d98d7f3f8c..a7808b1bd2 100644 --- a/world/src/block/natural.rs +++ b/world/src/block/natural.rs @@ -135,193 +135,4 @@ lazy_static! { pub static ref QUIRKY: Vec> = load_structures("quirky"); pub static ref QUIRKY_DRY: Vec> = load_structures("quirky_dry"); - - /* - // green pines 2 - assets::load_map("world/tree/pine_green_2/1", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/2", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/3", |s: Structure| s - .with_center(Vec3::new(17, 15, 12))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/4", |s: Structure| s - .with_center(Vec3::new(10, 8, 12))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/5", |s: Structure| s - .with_center(Vec3::new(12, 12, 12))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/6", |s: Structure| s - .with_center(Vec3::new(11, 10, 12))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/7", |s: Structure| s - .with_center(Vec3::new(16, 15, 12))) - .unwrap(), - assets::load_map("world/tree/pine_green_2/8", |s: Structure| s - .with_center(Vec3::new(12, 10, 12))) - .unwrap(), - // blue pines - assets::load_map("world/tree/pine_blue/1", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world/tree/pine_blue/2", |s: Structure| s - .with_center(Vec3::new(15, 15, 14))) - .unwrap(), - assets::load_map("world/tree/pine_blue/3", |s: Structure| s - .with_center(Vec3::new(17, 15, 12))) - .unwrap(), - assets::load_map("world/tree/pine_blue/4", |s: Structure| s - .with_center(Vec3::new(10, 8, 12))) - .unwrap(), - assets::load_map("world/tree/pine_blue/5", |s: Structure| s - .with_center(Vec3::new(12, 12, 12))) - .unwrap(), - assets::load_map("world/tree/pine_blue/6", |s: Structure| s - .with_center(Vec3::new(11, 10, 12))) - .unwrap(), - assets::load_map("world/tree/pine_blue/7", |s: Structure| s - .with_center(Vec3::new(16, 15, 12))) - .unwrap(), - assets::load_map("world/tree/pine_blue/8", |s: Structure| s - .with_center(Vec3::new(12, 10, 12))) - .unwrap(), - */ - /* - // temperate small - assets::load_map("world/tree/temperate_small/1", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - assets::load_map("world/tree/temperate_small/2", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - assets::load_map("world/tree/temperate_small/3", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - assets::load_map("world/tree/temperate_small/4", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - assets::load_map("world/tree/temperate_small/5", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - assets::load_map("world/tree/temperate_small/6", |s: Structure| s - .with_center(Vec3::new(4, 4, 7))) - .unwrap(), - // birch - assets::load_map("world/tree/birch/1", |s: Structure| s - .with_center(Vec3::new(12, 9, 10))) - .unwrap(), - assets::load_map("world/tree/birch/2", |s: Structure| s - .with_center(Vec3::new(11, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/3", |s: Structure| s - .with_center(Vec3::new(9, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/4", |s: Structure| s - .with_center(Vec3::new(9, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/5", |s: Structure| s - .with_center(Vec3::new(9, 11, 10))) - .unwrap(), - assets::load_map("world/tree/birch/6", |s: Structure| s - .with_center(Vec3::new(9, 9, 10))) - .unwrap(), - assets::load_map("world/tree/birch/7", |s: Structure| s - .with_center(Vec3::new(10, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/8", |s: Structure| s - .with_center(Vec3::new(9, 9, 10))) - .unwrap(), - assets::load_map("world/tree/birch/9", |s: Structure| s - .with_center(Vec3::new(9, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/10", |s: Structure| s - .with_center(Vec3::new(10, 9, 10))) - .unwrap(), - assets::load_map("world/tree/birch/11", |s: Structure| s - .with_center(Vec3::new(9, 10, 10))) - .unwrap(), - assets::load_map("world/tree/birch/12", |s: Structure| s - .with_center(Vec3::new(10, 9, 10))) - .unwrap(), - // poplar - assets::load_map("world/tree/poplar/1", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/2", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/3", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/4", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/5", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/6", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/7", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/8", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/9", |s: Structure| s - .with_center(Vec3::new(6, 6, 10))) - .unwrap(), - assets::load_map("world/tree/poplar/10", |s: Structure| s - .with_center(Vec3::new(7, 7, 10))) - .unwrap(), - */ - /* - // snow birches -> need roots! - assets::load_map("world/tree/snow_birch/1", |s: Structure| s - .with_center(Vec3::new(12, 9, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/2", |s: Structure| s - .with_center(Vec3::new(11, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/3", |s: Structure| s - .with_center(Vec3::new(9, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/4", |s: Structure| s - .with_center(Vec3::new(9, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/5", |s: Structure| s - .with_center(Vec3::new(9, 11, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/6", |s: Structure| s - .with_center(Vec3::new(9, 9, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/7", |s: Structure| s - .with_center(Vec3::new(10, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/8", |s: Structure| s - .with_center(Vec3::new(9, 9, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/9", |s: Structure| s - .with_center(Vec3::new(9, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/10", |s: Structure| s - .with_center(Vec3::new(10, 9, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/11", |s: Structure| s - .with_center(Vec3::new(9, 10, 4))) - .unwrap(), - assets::load_map("world/tree/snow_birch/12", |s: Structure| s - .with_center(Vec3::new(10, 9, 4))) - .unwrap(), - // willows - assets::load_map("world/tree/willow/1", |s: Structure| s - .with_center(Vec3::new(15, 14, 1))) - .unwrap(), - assets::load_map("world/tree/willow/2", |s: Structure| s - .with_center(Vec3::new(11, 12, 1))) - .unwrap(), - ]; - */ } From dbca8e3b092d571367d80a8cd1e89d54eec541bb Mon Sep 17 00:00:00 2001 From: KyoZM Date: Thu, 10 Oct 2019 20:52:52 -0300 Subject: [PATCH 3/4] refactor code to be smaller and clearer --- world/src/block/natural.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/world/src/block/natural.rs b/world/src/block/natural.rs index a7808b1bd2..36d0b994ed 100644 --- a/world/src/block/natural.rs +++ b/world/src/block/natural.rs @@ -96,8 +96,9 @@ impl Asset for StructuresSpec { } } -fn convert(specifications: &StructuresSpec) -> Vec> { - return specifications +fn load_structures(specifier: &str) -> Vec> { + let spec = assets::load::(&["world.manifests.", specifier].concat()); + return spec.unwrap() .0 .iter() .map(|sp| { @@ -109,12 +110,6 @@ fn convert(specifications: &StructuresSpec) -> Vec> { .collect(); } -fn load_structures(specifier: &str) -> Vec> { - dbg!(specifier); - let spec = assets::load::(&["world.manifests.", specifier].concat()); - return convert(&spec.unwrap()); -} - lazy_static! { pub static ref OAKS: Vec> = load_structures("oaks"); From 7f2439118705ce90c0e2eb286af2f9c2581e4583 Mon Sep 17 00:00:00 2001 From: KyoZM Date: Thu, 10 Oct 2019 21:00:19 -0300 Subject: [PATCH 4/4] format code --- world/src/block/natural.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/world/src/block/natural.rs b/world/src/block/natural.rs index 36d0b994ed..07e927302c 100644 --- a/world/src/block/natural.rs +++ b/world/src/block/natural.rs @@ -98,7 +98,8 @@ impl Asset for StructuresSpec { fn load_structures(specifier: &str) -> Vec> { let spec = assets::load::(&["world.manifests.", specifier].concat()); - return spec.unwrap() + return spec + .unwrap() .0 .iter() .map(|sp| { @@ -112,22 +113,13 @@ fn load_structures(specifier: &str) -> Vec> { lazy_static! { pub static ref OAKS: Vec> = load_structures("oaks"); - pub static ref OAK_STUMPS: Vec> = load_structures("oak_stumps"); - pub static ref PINES: Vec> = load_structures("pines"); - pub static ref PALMS: Vec> = load_structures("palms"); - pub static ref SNOW_PINES: Vec> = load_structures("snow_pines"); - pub static ref ACACIAS: Vec> = load_structures("acacias"); - pub static ref FRUIT_TREES: Vec> = load_structures("fruit_trees"); - pub static ref MANGROVE_TREES: Vec> = load_structures("mangrove_trees"); - pub static ref QUIRKY: Vec> = load_structures("quirky"); - pub static ref QUIRKY_DRY: Vec> = load_structures("quirky_dry"); }