Skip to content

Commit

Permalink
Actually display level names (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rparrett authored Dec 2, 2024
1 parent 622abd2 commit b00c227
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions assets/levels/1.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Connection",
name_position: Vec2(-624.0, 336.0),
layers: 1,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/10.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Jumper",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/11.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Scatter",
name_position: Vec2(-528.0, 336.0),
layers: 2,
terminuses: [
// tl
Expand Down
1 change: 1 addition & 0 deletions assets/levels/12.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Layers 2",
name_position: Vec2(-528.0, 336.0),
layers: 3,
terminuses: [
// tl
Expand Down
1 change: 1 addition & 0 deletions assets/levels/2.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Layers",
name_position: Vec2(-288.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/3.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Traffic",
name_position: Vec2(-624.0, 336.0),
layers: 1,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/4.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Crossings",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/5.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Delay Line",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/6.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Symmetry",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// inside
Expand Down
1 change: 1 addition & 0 deletions assets/levels/7.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Converge/Diverge",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
Terminus(
Expand Down
1 change: 1 addition & 0 deletions assets/levels/8.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Delay Line 2",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions assets/levels/9.level.ron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Level(
name: "Wave-like",
name_position: Vec2(-624.0, 336.0),
layers: 2,
terminuses: [
// left
Expand Down
1 change: 1 addition & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const PIXIE: [Srgba; 6] = [

pub const BACKGROUND: Color = Color::srgb(0.05, 0.066, 0.09);
pub const GRID: Color = Color::srgb(0.086, 0.105, 0.133);
pub const NAME: Color = Color::srgb(0.16, 0.20, 0.25);
pub const OBSTACLE: Color = Color::srgb(0.086, 0.105, 0.133);
pub const BOTTOM_BAR_BACKGROUND: Color = Color::srgb(0.09, 0.11, 0.13);
pub const DIALOG_BACKGROUND: Color = Color::srgb(0.2, 0.2, 0.2);
Expand Down
2 changes: 1 addition & 1 deletion src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use serde::Deserialize;

#[derive(Deserialize, Debug, Asset, TypePath)]
pub struct Level {
#[allow(unused)]
pub name: String,
pub name_position: Vec2,
pub layers: u32,
pub terminuses: Vec<Terminus>,
pub obstacles: Vec<Obstacle>,
Expand Down
35 changes: 34 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bevy::{
asset::AssetMetaCheck,
ecs::schedule::ScheduleLabel,
prelude::*,
sprite::Anchor,
utils::{Duration, HashMap, HashSet},
window::CursorMoved,
};
Expand Down Expand Up @@ -1424,7 +1425,11 @@ fn mouse_movement_system(
if let Ok(pos) = camera.viewport_to_world_2d(camera_transform, event.position) {
mouse.position = pos;

mouse.snapped = snap_to_grid(mouse.position, GRID_SIZE);
let new = snap_to_grid(mouse.position, GRID_SIZE);
if mouse.snapped != new {
debug!("Cursor: {new}");
mouse.snapped = new;
}

mouse.window_position = event.position;
}
Expand Down Expand Up @@ -1895,6 +1900,26 @@ fn spawn_obstacle(commands: &mut Commands, obstacle: &Obstacle) {
}
}

fn spawn_name(
commands: &mut Commands,
number: u32,
handles: &Res<Handles>,
name: &String,
name_position: &Vec2,
) {
commands.spawn((
Text2d::new(format!("L{}: {}", number, name)),
TextFont {
font: handles.fonts[0].clone(),
font_size: 25.0,
..default()
},
TextColor(color::NAME),
Anchor::TopLeft,
Transform::from_translation((name_position + Vec2::new(8., -8.)).extend(layer::GRID)),
));
}

fn spawn_terminus(
commands: &mut Commands,
graph: &mut ResMut<RoadGraph>,
Expand Down Expand Up @@ -2214,6 +2239,14 @@ fn playing_enter_system(
spawn_obstacle(&mut commands, o);
}

spawn_name(
&mut commands,
selected_level.0,
&handles,
&level.name,
&level.name_position,
);

println!(
"{:?}",
Dot::with_config(&graph.graph, &[Config::EdgeNoLabel])
Expand Down

0 comments on commit b00c227

Please sign in to comment.