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 #109

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
13 changes: 13 additions & 0 deletions gui-src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,16 @@ button:hover {
content: "⚙️";
font-size: 18px;
}

/* Street Sign Styles */
.street-sign {
position: absolute;
background-color: #ffffff;
color: #000000;
padding: 2px 5px;
border: 1px solid #000000;
border-radius: 3px;
font-size: 12px;
white-space: nowrap;
transform: translate(-50%, -50%);
}
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">Street Names:</label>
<input type="checkbox" id="street-names-toggle" name="street-names-toggle">
</div>
</div>
</div>

Expand Down
27 changes: 27 additions & 0 deletions gui-src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function initSettings() {
const settingsModal = document.getElementById("settings-modal");
const slider = document.getElementById("scale-value-slider");
const sliderValue = document.getElementById("slider-value");
const streetNamesToggle = document.getElementById("street-names-toggle"); // P40d4

// Open settings modal
function openSettings() {
Expand All @@ -118,6 +119,18 @@ function initSettings() {
slider.addEventListener("input", () => {
sliderValue.textContent = parseFloat(slider.value).toFixed(2);
});

// Add event listener for street names toggle
streetNamesToggle.addEventListener("change", () => {
const isEnabled = streetNamesToggle.checked;
console.log("Street names toggle:", isEnabled);
// Implement logic to handle enabling/disabling street names as street signs
if (isEnabled) {
enableStreetNames();
} else {
disableStreetNames();
}
});
}

function initWorldPicker() {
Expand Down Expand Up @@ -297,6 +310,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 street_names = document.getElementById("street-names-toggle").checked; // P40d4

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

console.log("Generation process started.");
Expand All @@ -319,3 +334,15 @@ async function startGeneration() {
generationButtonEnabled = true;
}
}

// Function to enable street names as street signs
function enableStreetNames() {
console.log("Street names enabled");
// Implement logic to add street names as street signs at intersections
}

// Function to disable street names as street signs
function disableStreetNames() {
console.log("Street names disabled");
// Implement logic to remove street names as street signs at intersections
}
34 changes: 34 additions & 0 deletions src/element_processing/highways.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ pub fn generate_highways(
}
previous_node = Some((node.x, node.z));
}

// Add street names as street signs at intersections
if args.street_names {
for node in &way.nodes {
if let Some(prev) = previous_node {
let (x1, z1) = prev;
let x2: i32 = node.x;
let z2: i32 = node.z;

// Check if the node is an intersection
if is_intersection(x1, z1, x2, z2) {
let street_name = element.tags().get("name").unwrap_or(&"Unnamed Street".to_string());
add_street_sign(editor, x2, ground_level, z2, street_name);
}
}
previous_node = Some((node.x, node.z));
}
}
}
}
}
Expand Down Expand Up @@ -297,3 +315,19 @@ pub fn generate_siding(editor: &mut WorldEditor, element: &ProcessedWay, ground_
previous_node = Some((x, z));
}
}

/// Checks if the given coordinates represent an intersection
fn is_intersection(x1: i32, z1: i32, x2: i32, z2: i32) -> bool {
// Implement logic to determine if the coordinates represent an intersection
// For simplicity, let's assume an intersection occurs when the coordinates are equal
x1 == x2 && z1 == z2
}

/// Adds a street sign at the given coordinates with the specified street name
fn add_street_sign(editor: &mut WorldEditor, x: i32, ground_level: i32, z: i32, street_name: &str) {
// Implement logic to add a street sign with the given street name
// For simplicity, let's use a placeholder block for the street sign
editor.set_block(OAK_SIGN, x, ground_level + 1, z, None, None);
// Add the street name to the sign (this is a placeholder implementation)
println!("Added street sign at ({}, {}) with name: {}", x, z, street_name);
}
Loading