add sandbox and lock input in other levels
This commit is contained in:
parent
bbe5ab0868
commit
af66e68c5f
6 changed files with 21 additions and 2 deletions
10
levels/sandbox.json
Normal file
10
levels/sandbox.json
Normal file
|
@ -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": []
|
||||||
|
}
|
|
@ -413,6 +413,7 @@ impl Editor {
|
||||||
Rectangle::new(width as f32 - 205., 5., 200., 30.),
|
Rectangle::new(width as f32 - 205., 5., 200., 30.),
|
||||||
&mut input_text,
|
&mut input_text,
|
||||||
&mut self.input_text_selected,
|
&mut self.input_text_selected,
|
||||||
|
self.level.is_sandbox(),
|
||||||
) {
|
) {
|
||||||
self.machine.set_input(input_text.into_bytes());
|
self.machine.set_input(input_text.into_bytes());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ pub struct Level {
|
||||||
sort_order: i32,
|
sort_order: i32,
|
||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
|
#[serde(default)]
|
||||||
|
is_sandbox: bool,
|
||||||
init_board: Option<String>,
|
init_board: Option<String>,
|
||||||
inputs: Vec<u8>,
|
inputs: Vec<u8>,
|
||||||
outputs: Vec<u8>,
|
outputs: Vec<u8>,
|
||||||
|
@ -28,6 +30,10 @@ impl Level {
|
||||||
&self.description
|
&self.description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_sandbox(&self) -> bool {
|
||||||
|
self.is_sandbox
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init_board(&self) -> Option<String> {
|
pub fn init_board(&self) -> Option<String> {
|
||||||
self.init_board.clone()
|
self.init_board.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,6 +210,7 @@ impl Game {
|
||||||
bounds,
|
bounds,
|
||||||
&mut solution.name,
|
&mut solution.name,
|
||||||
&mut self.editing_solution_name,
|
&mut self.editing_solution_name,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
let button_x = level_list_width + entry_width + 20;
|
let button_x = level_list_width + entry_width + 20;
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl Board {
|
||||||
self.rows = new_rows;
|
self.rows = new_rows;
|
||||||
self.offset_y += len as isize;
|
self.offset_y += len as isize;
|
||||||
self.height += len;
|
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;
|
let new_height = p.y as usize + 1;
|
||||||
self.rows.resize(new_height, vec![Tile::Blank; self.width]);
|
self.rows.resize(new_height, vec![Tile::Blank; self.width]);
|
||||||
self.height = new_height;
|
self.height = new_height;
|
||||||
|
|
|
@ -90,6 +90,7 @@ pub fn text_input(
|
||||||
bounds: Rectangle,
|
bounds: Rectangle,
|
||||||
text: &mut String,
|
text: &mut String,
|
||||||
is_selected: &mut bool,
|
is_selected: &mut bool,
|
||||||
|
editable: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
let (bg, underline) = if *is_selected {
|
let (bg, underline) = if *is_selected {
|
||||||
|
@ -120,7 +121,7 @@ pub fn text_input(
|
||||||
Color::WHITE,
|
Color::WHITE,
|
||||||
);
|
);
|
||||||
let mouse_pos = d.get_mouse_position();
|
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)
|
&& (bounds.check_collision_point_rec(mouse_pos) || *is_selected)
|
||||||
{
|
{
|
||||||
*is_selected = !*is_selected;
|
*is_selected = !*is_selected;
|
||||||
|
|
Loading…
Reference in a new issue