Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add street names as street signs at intersections #110

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gui-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ <h2>Customization Settings</h2>
<label for="ground-level">Ground Level:</label>
<input type="number" id="ground-level" name="ground-level" min="-64" max="290" value="-62" style="width: 100px;" placeholder="Ground Level">
</div>

<!-- Street Names Toggle Button -->
<div class="street-names-toggle-container">
<label for="street-names-toggle">Add Street Names:</label>
<input type="checkbox" id="street-names-toggle" name="street-names-toggle">
</div>
</div>
</div>

Expand Down
9 changes: 9 additions & 0 deletions gui-src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ function initSettings() {
slider.addEventListener("input", () => {
sliderValue.textContent = parseFloat(slider.value).toFixed(2);
});

// Add event listener for the street names toggle
const streetNamesToggle = document.getElementById("street-names-toggle");
streetNamesToggle.addEventListener("change", () => {
const isChecked = streetNamesToggle.checked;
console.log("Street Names Toggle:", isChecked);
});
}

function initWorldPicker() {
Expand Down Expand Up @@ -297,6 +304,7 @@ async function startGeneration() {
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);
var add_street_names = document.getElementById("street-names-toggle").checked;

// Validate floodfill_timeout and ground_level
floodfill_timeout = isNaN(floodfill_timeout) || floodfill_timeout < 0 ? 20 : floodfill_timeout;
Expand All @@ -310,6 +318,7 @@ async function startGeneration() {
groundLevel: ground_level,
winterMode: winter_mode,
floodfillTimeout: floodfill_timeout,
addStreetNames: add_street_names,
});

console.log("Generation process started.");
Expand Down
6 changes: 5 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub struct Args {
/// Set floodfill timeout (seconds) (optional)
#[arg(long, value_parser = parse_duration)]
pub timeout: Option<Duration>,

/// Add street names as street signs (default: false)
#[arg(long, default_value_t = false)]
pub add_street_names: bool,
}

impl Args {
Expand Down Expand Up @@ -97,7 +101,7 @@ fn validate_bounding_box(bbox: &str) -> bool {
min_lng < max_lng && min_lat < max_lat
}

fn parse_duration(arg: &str) -> Result<std::time::Duration, std::num::ParseIntError> {
fn parse_duration(arg: &str) -> Result<std::.time::Duration, std::num::ParseIntError> {
let seconds = arg.parse()?;
Ok(std::time::Duration::from_secs(seconds))
}
6 changes: 6 additions & 0 deletions src/element_processing/highways.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::bresenham::bresenham_line;
use crate::floodfill::flood_fill_area;
use crate::osm_parser::{ProcessedElement, ProcessedWay};
use crate::world_editor::WorldEditor;
use crate::element_processing::street_signs::generate_street_signs;

pub fn generate_highways(
editor: &mut WorldEditor,
Expand Down Expand Up @@ -264,6 +265,11 @@ pub fn generate_highways(
}
previous_node = Some((node.x, node.z));
}

// Generate street signs at intersections if the option is enabled
if args.add_street_names {
generate_street_signs(editor, way, ground_level);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/element_processing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ pub mod tourisms;
pub mod tree;
pub mod water_areas;
pub mod waterways;
pub mod street_signs;
pub mod street_names;
56 changes: 56 additions & 0 deletions src/element_processing/street_signs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::block_definitions::*;
use crate::osm_parser::ProcessedWay;
use crate::world_editor::WorldEditor;

pub fn generate_street_signs(editor: &mut WorldEditor, way: &ProcessedWay, ground_level: i32) {
// Check if the way has a name tag
if let Some(street_name) = way.tags.get("name") {
// Iterate over the nodes in the way
for node in &way.nodes {
let x: i32 = node.x;
let z: i32 = node.z;

// Place a sign at the intersection
editor.set_block(OAK_SIGN, x, ground_level + 1, z, None, None);

// Embed the street name using blocks
let mut offset = 0;
for ch in street_name.chars() {
let block = match ch {
'A' => OAK_PLANKS,
'B' => BIRCH_PLANKS,
'C' => SPRUCE_PLANKS,
'D' => JUNGLE_PLANKS,
'E' => ACACIA_PLANKS,
'F' => DARK_OAK_PLANKS,
'G' => CRIMSON_PLANKS,
'H' => WARPED_PLANKS,
'I' => STONE,
'J' => COBBLESTONE,
'K' => SANDSTONE,
'L' => RED_SANDSTONE,
'M' => NETHER_BRICKS,
'N' => END_STONE_BRICKS,
'O' => PRISMARINE,
'P' => QUARTZ_BLOCK,
'Q' => PURPUR_BLOCK,
'R' => MAGMA_BLOCK,
'S' => SEA_LANTERN,
'T' => GLOWSTONE,
'U' => HONEY_BLOCK,
'V' => SLIME_BLOCK,
'W' => HAY_BLOCK,
'X' => BONE_BLOCK,
'Y' => COAL_BLOCK,
'Z' => IRON_BLOCK,
' ' => AIR,
_ => OAK_PLANKS,
};

// Place the block to form the letter
editor.set_block(block, x + offset, ground_level + 2, z, None, None);
offset += 1;
}
}
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ fn gui_start_generation(
ground_level: i32,
winter_mode: bool,
floodfill_timeout: u64,
add_street_names: bool,
) -> Result<(), String> {
tauri::async_runtime::spawn(async move {
if let Err(e) = tokio::task::spawn_blocking(move || {
Expand Down Expand Up @@ -342,6 +343,7 @@ fn gui_start_generation(
winter: winter_mode,
debug: false,
timeout: Some(std::time::Duration::from_secs(floodfill_timeout)),
add_street_names,
};

// Reorder bounding box coordinates for further processing
Expand Down
Loading