From af66e68c5f6153039d4fcb7fb3dcf3bf70c9b060 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 7 Oct 2024 12:21:57 +0200 Subject: [PATCH] add sandbox and lock input in other levels --- levels/sandbox.json | 10 ++++++++++ src/editor.rs | 1 + src/level.rs | 6 ++++++ src/main.rs | 1 + src/marble_engine/board.rs | 2 +- src/util.rs | 3 ++- 6 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 levels/sandbox.json diff --git a/levels/sandbox.json b/levels/sandbox.json new file mode 100644 index 0000000..fa7bad4 --- /dev/null +++ b/levels/sandbox.json @@ -0,0 +1,10 @@ +{ + "id": "sandbox", + "sort_order": 100000, + "name": "Sandbox", + "description": "make whatever you want here", + "is_sandbox": true, + "init_board": null, + "inputs": [], + "outputs": [] +} \ No newline at end of file diff --git a/src/editor.rs b/src/editor.rs index bb17851..24aa9e6 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -413,6 +413,7 @@ impl Editor { Rectangle::new(width as f32 - 205., 5., 200., 30.), &mut input_text, &mut self.input_text_selected, + self.level.is_sandbox(), ) { self.machine.set_input(input_text.into_bytes()); } diff --git a/src/level.rs b/src/level.rs index 592195c..44f4384 100644 --- a/src/level.rs +++ b/src/level.rs @@ -6,6 +6,8 @@ pub struct Level { sort_order: i32, name: String, description: String, + #[serde(default)] + is_sandbox: bool, init_board: Option, inputs: Vec, outputs: Vec, @@ -28,6 +30,10 @@ impl Level { &self.description } + pub fn is_sandbox(&self) -> bool { + self.is_sandbox + } + pub fn init_board(&self) -> Option { self.init_board.clone() } diff --git a/src/main.rs b/src/main.rs index 74e6ad8..6c312bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,6 +210,7 @@ impl Game { bounds, &mut solution.name, &mut self.editing_solution_name, + true, ); let button_x = level_list_width + entry_width + 20; diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 83fb035..b3cc8ff 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -197,7 +197,7 @@ impl Board { self.rows = new_rows; self.offset_y += len as isize; self.height += len; - } else if p.y as usize > self.height { + } else if p.y as usize >= self.height { let new_height = p.y as usize + 1; self.rows.resize(new_height, vec![Tile::Blank; self.width]); self.height = new_height; diff --git a/src/util.rs b/src/util.rs index f686024..db83739 100644 --- a/src/util.rs +++ b/src/util.rs @@ -90,6 +90,7 @@ pub fn text_input( bounds: Rectangle, text: &mut String, is_selected: &mut bool, + editable: bool, ) -> bool { let mut changed = false; let (bg, underline) = if *is_selected { @@ -120,7 +121,7 @@ pub fn text_input( Color::WHITE, ); let mouse_pos = d.get_mouse_position(); - if d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) + if editable && d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) && (bounds.check_collision_point_rec(mouse_pos) || *is_selected) { *is_selected = !*is_selected;