From b00c2275c905ce366668af67ab5901932c7ea66d Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Mon, 2 Dec 2024 06:15:45 -0800 Subject: [PATCH] Actually display level names (#12) --- assets/levels/1.level.ron | 1 + assets/levels/10.level.ron | 1 + assets/levels/11.level.ron | 1 + assets/levels/12.level.ron | 1 + assets/levels/2.level.ron | 1 + assets/levels/3.level.ron | 1 + assets/levels/4.level.ron | 1 + assets/levels/5.level.ron | 1 + assets/levels/6.level.ron | 1 + assets/levels/7.level.ron | 1 + assets/levels/8.level.ron | 1 + assets/levels/9.level.ron | 1 + src/color.rs | 1 + src/level.rs | 2 +- src/main.rs | 35 ++++++++++++++++++++++++++++++++++- 15 files changed, 48 insertions(+), 2 deletions(-) diff --git a/assets/levels/1.level.ron b/assets/levels/1.level.ron index e94e161..dde82c6 100644 --- a/assets/levels/1.level.ron +++ b/assets/levels/1.level.ron @@ -1,5 +1,6 @@ Level( name: "Connection", + name_position: Vec2(-624.0, 336.0), layers: 1, terminuses: [ // left diff --git a/assets/levels/10.level.ron b/assets/levels/10.level.ron index 3b5cb1f..fae9b6e 100644 --- a/assets/levels/10.level.ron +++ b/assets/levels/10.level.ron @@ -1,5 +1,6 @@ Level( name: "Jumper", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // left diff --git a/assets/levels/11.level.ron b/assets/levels/11.level.ron index 48c84b6..2333a03 100644 --- a/assets/levels/11.level.ron +++ b/assets/levels/11.level.ron @@ -1,5 +1,6 @@ Level( name: "Scatter", + name_position: Vec2(-528.0, 336.0), layers: 2, terminuses: [ // tl diff --git a/assets/levels/12.level.ron b/assets/levels/12.level.ron index 5e64954..8a635d4 100644 --- a/assets/levels/12.level.ron +++ b/assets/levels/12.level.ron @@ -1,5 +1,6 @@ Level( name: "Layers 2", + name_position: Vec2(-528.0, 336.0), layers: 3, terminuses: [ // tl diff --git a/assets/levels/2.level.ron b/assets/levels/2.level.ron index f542845..0f11c61 100644 --- a/assets/levels/2.level.ron +++ b/assets/levels/2.level.ron @@ -1,5 +1,6 @@ Level( name: "Layers", + name_position: Vec2(-288.0, 336.0), layers: 2, terminuses: [ // left diff --git a/assets/levels/3.level.ron b/assets/levels/3.level.ron index 1aee20a..8bfaf5a 100644 --- a/assets/levels/3.level.ron +++ b/assets/levels/3.level.ron @@ -1,5 +1,6 @@ Level( name: "Traffic", + name_position: Vec2(-624.0, 336.0), layers: 1, terminuses: [ // left diff --git a/assets/levels/4.level.ron b/assets/levels/4.level.ron index ca5acb2..3bb8403 100644 --- a/assets/levels/4.level.ron +++ b/assets/levels/4.level.ron @@ -1,5 +1,6 @@ Level( name: "Crossings", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // left diff --git a/assets/levels/5.level.ron b/assets/levels/5.level.ron index c945d06..f1cd420 100644 --- a/assets/levels/5.level.ron +++ b/assets/levels/5.level.ron @@ -1,5 +1,6 @@ Level( name: "Delay Line", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // left diff --git a/assets/levels/6.level.ron b/assets/levels/6.level.ron index bc05887..f4276b3 100644 --- a/assets/levels/6.level.ron +++ b/assets/levels/6.level.ron @@ -1,5 +1,6 @@ Level( name: "Symmetry", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // inside diff --git a/assets/levels/7.level.ron b/assets/levels/7.level.ron index 6ac0f54..8c84c5c 100644 --- a/assets/levels/7.level.ron +++ b/assets/levels/7.level.ron @@ -1,5 +1,6 @@ Level( name: "Converge/Diverge", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ Terminus( diff --git a/assets/levels/8.level.ron b/assets/levels/8.level.ron index 7916111..76bfd41 100644 --- a/assets/levels/8.level.ron +++ b/assets/levels/8.level.ron @@ -1,5 +1,6 @@ Level( name: "Delay Line 2", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // left diff --git a/assets/levels/9.level.ron b/assets/levels/9.level.ron index 32e500a..a65f901 100644 --- a/assets/levels/9.level.ron +++ b/assets/levels/9.level.ron @@ -1,5 +1,6 @@ Level( name: "Wave-like", + name_position: Vec2(-624.0, 336.0), layers: 2, terminuses: [ // left diff --git a/src/color.rs b/src/color.rs index f295571..3f1cfb1 100644 --- a/src/color.rs +++ b/src/color.rs @@ -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); diff --git a/src/level.rs b/src/level.rs index 75eb164..8445910 100644 --- a/src/level.rs +++ b/src/level.rs @@ -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, pub obstacles: Vec, diff --git a/src/main.rs b/src/main.rs index c37f7cb..a6532c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ use bevy::{ asset::AssetMetaCheck, ecs::schedule::ScheduleLabel, prelude::*, + sprite::Anchor, utils::{Duration, HashMap, HashSet}, window::CursorMoved, }; @@ -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; } @@ -1895,6 +1900,26 @@ fn spawn_obstacle(commands: &mut Commands, obstacle: &Obstacle) { } } +fn spawn_name( + commands: &mut Commands, + number: u32, + handles: &Res, + 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, @@ -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])