diff --git a/gui-src/css/styles.css b/gui-src/css/styles.css index e89636b..73c7ed8 100644 --- a/gui-src/css/styles.css +++ b/gui-src/css/styles.css @@ -251,6 +251,14 @@ button:hover { margin: 15px 0; } +#fillground-toggle { + accent-color: #fecc44; +} + +.fillground-toggle-container, .scale-slider-container { + margin: 15px 0; +} + #winter-toggle { accent-color: #fecc44; } diff --git a/gui-src/index.html b/gui-src/index.html index fb560ef..1922913 100644 --- a/gui-src/index.html +++ b/gui-src/index.html @@ -91,7 +91,11 @@

Customization Settings

- + +
+ + +
diff --git a/gui-src/js/main.js b/gui-src/js/main.js index 168de5c..3707057 100644 --- a/gui-src/js/main.js +++ b/gui-src/js/main.js @@ -480,6 +480,7 @@ async function startGeneration() { var terrain = document.getElementById("terrain-toggle").checked; var winter_mode = document.getElementById("winter-toggle").checked; + var fill_ground = document.getElementById("fillground-toggle").checked; var scale = parseFloat(document.getElementById("scale-value-slider").value); var floodfill_timeout = parseInt(document.getElementById("floodfill-timeout").value, 10); var ground_level = parseInt(document.getElementById("ground-level").value, 10); @@ -496,7 +497,8 @@ async function startGeneration() { groundLevel: ground_level, winterMode: winter_mode, floodfillTimeout: floodfill_timeout, - terrainEnabled: terrain + terrainEnabled: terrain, + fillgroundEnabled: fill_ground }); console.log("Generation process started."); diff --git a/src/args.rs b/src/args.rs index 046c32d..59795a0 100644 --- a/src/args.rs +++ b/src/args.rs @@ -44,7 +44,9 @@ pub struct Args { /// Enable terrain (optional) #[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)] pub terrain: bool, - + /// Enable filling ground (optional) + #[arg(long, default_value_t = false, action = clap::ArgAction::SetFalse)] + pub fillground: bool, /// Enable debug mode (optional) #[arg(long, default_value_t = false, action = clap::ArgAction::SetTrue)] pub debug: bool, diff --git a/src/block_definitions.rs b/src/block_definitions.rs index 4128f85..2438b38 100644 --- a/src/block_definitions.rs +++ b/src/block_definitions.rs @@ -147,6 +147,9 @@ impl Block { 126 => "coarse_dirt", 127 => "iron_ore", 128 => "coal_ore", + 129 => "gold_ore", + 130 => "copper_ore", + 131 => "clay", _ => panic!("Invalid id"), } } @@ -411,6 +414,9 @@ pub const RAIL_SOUTH_WEST: Block = Block::new(125); pub const COARSE_DIRT: Block = Block::new(126); pub const IRON_ORE: Block = Block::new(127); pub const COAL_ORE: Block = Block::new(128); +pub const GOLD_ORE: Block = Block::new(129); +pub const COPPER_ORE: Block = Block::new(130); +pub const CLAY: Block = Block::new(131); // Variations for building corners pub fn building_corner_variations() -> Vec { diff --git a/src/data_processing.rs b/src/data_processing.rs index 1b9e49d..d5c2ead 100644 --- a/src/data_processing.rs +++ b/src/data_processing.rs @@ -1,5 +1,5 @@ use crate::args::Args; -use crate::block_definitions::{DIRT, GRASS_BLOCK, SNOW_BLOCK}; +use crate::block_definitions::{BEDROCK, DIRT, GRASS_BLOCK, SNOW_BLOCK, STONE}; use crate::cartesian::XZPoint; use crate::element_processing::*; use crate::ground::Ground; @@ -9,7 +9,7 @@ use crate::world_editor::WorldEditor; use colored::Colorize; use indicatif::{ProgressBar, ProgressStyle}; -const MIN_Y: i32 = -64; +pub const MIN_Y: i32 = -64; pub fn generate_world( elements: Vec, @@ -170,6 +170,11 @@ pub fn generate_world( editor.set_block(groundlayer_block, x, max_y, z, None, None); editor.set_block(DIRT, x, max_y - 1, z, None, None); editor.set_block(DIRT, x, max_y - 2, z, None, None); + // Fill underground with stone + if args.fillground { + editor.fill_blocks(STONE, x, MIN_Y + 1, z, x, max_y - 2, z, None, None); + } + editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK])); block_counter += 1; if block_counter % batch_size == 0 { @@ -196,6 +201,7 @@ pub fn generate_world( let ground_level = ground.level(XZPoint::new(x, z)); editor.set_block(groundlayer_block, x, ground_level, z, None, None); editor.set_block(DIRT, x, ground_level - 1, z, None, None); + editor.set_block(BEDROCK, x, MIN_Y, z, None, Some(&[BEDROCK])); block_counter += 1; if block_counter % batch_size == 0 { diff --git a/src/element_processing/landuse.rs b/src/element_processing/landuse.rs index 9ca3283..665c50d 100644 --- a/src/element_processing/landuse.rs +++ b/src/element_processing/landuse.rs @@ -1,6 +1,7 @@ use crate::args::Args; use crate::block_definitions::*; use crate::cartesian::XZPoint; +use crate::data_processing::MIN_Y; use crate::element_processing::tree::create_tree; use crate::floodfill::flood_fill_area; use crate::ground::Ground; @@ -45,15 +46,15 @@ pub fn generate_landuse( "military" => GRAY_CONCRETE, "railway" => GRAVEL, "landfill" => { - // Gravel if man_made = spoil_heap, coarse dirt else - let manmade = element.tags.get("man_made").unwrap_or(&binding); - if manmade == "spoil_heap" { + // Gravel if man_made = spoil_heap or heap, coarse dirt else + let manmade_tag = element.tags.get("man_made").unwrap_or(&binding); + if manmade_tag == "spoil_heap" || manmade_tag == "heap" { GRAVEL } else { COARSE_DIRT } } - "quarry" => STONE, // TODO: add ores + "quarry" => STONE, _ => { if args.winter { SNOW_BLOCK @@ -349,6 +350,26 @@ pub fn generate_landuse( } } } + "quarry" => { + if let Some(resource) = element.tags.get("resource") { + let ore_block = match resource.as_str() { + "iron_ore" => IRON_ORE, + "coal" => COAL_ORE, + "copper" => COPPER_ORE, + "gold" => GOLD_ORE, + "clay" | "kaolinite" => CLAY, + _ => STONE, + }; + let random_choice: i32 = rng.gen_range(0..100 + ground_level); // with more depth there's more resources + if random_choice < 5 { + editor.set_block(ore_block, x, ground_level, z, Some(&[STONE]), None); + } + // Fill everything with stone so dirt won't be there + if args.fillground { + editor.fill_blocks(STONE, x, MIN_Y + 1, z, x, ground_level, z, None, None); + } + } + } _ => {} } } diff --git a/src/main.rs b/src/main.rs index 7c27de2..f03dae9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -392,6 +392,7 @@ fn gui_check_for_updates() -> Result { #[cfg(feature = "gui")] #[tauri::command] +#[allow(clippy::too_many_arguments)] fn gui_start_generation( bbox_text: String, selected_world: String, @@ -400,6 +401,7 @@ fn gui_start_generation( winter_mode: bool, floodfill_timeout: u64, terrain_enabled: bool, + fillground_enabled: bool, ) -> Result<(), String> { tauri::async_runtime::spawn(async move { if let Err(e) = tokio::task::spawn_blocking(move || { @@ -427,6 +429,7 @@ fn gui_start_generation( scale: world_scale, ground_level, terrain: terrain_enabled, + fillground: fillground_enabled, winter: winter_mode, debug: false, timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),