diff --git a/README.md b/README.md index 135de52..46bbe6e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble - undo/redo - more levels - make direct power (gate -> machine) work, (needs storing power direction in machine tiles) +- story/lore - cut selections, copy to system clipboard - timestamps in solutions and blueprints - multiple input/output sets diff --git a/src/editor.rs b/src/editor.rs index 18a4510..1934a87 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -56,7 +56,8 @@ pub struct Editor { time_since_step: f32, exit_state: ExitState, exit_menu: bool, - popup: EndPopup, + complete_popup: Popup, + // fail_popup: Popup, score: Option, blueprints: Vec, selected_blueprint: usize, @@ -68,10 +69,9 @@ pub struct Editor { } #[derive(Debug, PartialEq)] -enum EndPopup { - None, - Success, - Failure, +enum Popup { + Start, + Visible, Dismissed, } @@ -135,7 +135,8 @@ impl Editor { level, exit_state: ExitState::Dont, exit_menu: false, - popup: EndPopup::None, + complete_popup: Popup::Start, + // fail_popup: Popup::Start, score: solution.score, blueprints: get_blueprints(), selected_blueprint: usize::MAX, @@ -189,25 +190,22 @@ impl Editor { fn step(&mut self) { self.machine.step(); - if self.popup != EndPopup::None { - self.popup = EndPopup::Dismissed; + if self.complete_popup == Popup::Visible { + self.complete_popup = Popup::Dismissed; } if !self.level.outputs().is_empty() - && self.popup == EndPopup::None + && self.level.outputs() == self.machine.output() + && self.complete_popup == Popup::Start { - if self.level.outputs() == self.machine.output() { - self.popup = EndPopup::Success; - println!("completed in {:?}", self.start_time.elapsed()); - self.exit_state = ExitState::Save; - self.sim_state = SimState::Stepping; - self.score = Some(Score { - cycles: self.machine.step_count(), - tiles: self.source_board.count_tiles(), - }); - } else if !self.level.outputs().starts_with(self.machine.output()) { - self.popup = EndPopup::Failure; - self.sim_state = SimState::Stepping; - } + self.complete_popup = Popup::Visible; + println!("completed in {:?}", self.start_time.elapsed()); + self.exit_state = ExitState::Save; + self.sim_state = SimState::Stepping; + self.score = Some(Score { + cycles: self.machine.step_count(), + tiles: self.source_board.count_tiles(), + area: 0, + }); } } @@ -335,7 +333,7 @@ impl Editor { pub fn update(&mut self, rl: &RaylibHandle) { if rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) { self.sim_state = SimState::Editing; - self.popup = EndPopup::None; + self.complete_popup = Popup::Start; } if self.sim_state == SimState::Running { self.time_since_step += rl.get_frame_time(); @@ -376,7 +374,7 @@ impl Editor { } SimState::Running => { self.sim_state = SimState::Editing; - self.popup = EndPopup::None; + self.complete_popup = Popup::Start; } SimState::Stepping => self.sim_state = SimState::Running, } @@ -513,7 +511,7 @@ impl Editor { } } - if self.popup == EndPopup::Success { + if self.complete_popup == Popup::Visible { let width = 320; let height = 165; let x = d.get_screen_width() / 2 - width / 2; @@ -522,12 +520,14 @@ impl Editor { d.draw_text("Level Complete!", x + 45, y + 10, 30, Color::LIME); if let Some(score) = &self.score { d.draw_text("cycles", x + 15, y + 45, 20, Color::WHITE); - draw_usize(d, textures, score.cycles, x + 10, y + 70, 9, 2); - d.draw_text("tiles", x + 215, y + 45, 20, Color::WHITE); - draw_usize(d, textures, score.tiles, x + 210, y + 70, 5, 2); + draw_usize(d, textures, score.cycles, x + 10, y + 70, 6, 2); + d.draw_text("tiles", x + 145, y + 45, 20, Color::WHITE); + draw_usize(d, textures, score.tiles, x + 140, y + 70, 4, 2); + d.draw_text("area", x + 155 + 80, y + 45, 20, Color::WHITE); + draw_usize(d, textures, score.area, x + 150 + 80, y + 70, 4, 2); } if simple_button(d, x + 10, y + 110, 140, 45) { - self.popup = EndPopup::Dismissed; + self.complete_popup = Popup::Dismissed; } d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE); @@ -542,20 +542,6 @@ impl Editor { Color::WHITE, ); } - - if self.popup == EndPopup::Failure { - let width = 320; - let height = 165; - let x = d.get_screen_width() / 2 - width / 2; - let y = d.get_screen_height() / 2 - height / 2; - d.draw_rectangle(x, y, width, height, BG_DARK); - d.draw_text("Level Failed!", x + 45, y + 10, 30, Color::RED); - d.draw_text("incorrect output", x + 45, y + 45, 20, Color::WHITE); - if simple_button(d, x + 10, y + 110, 300, 25) { - self.popup = EndPopup::Dismissed; - } - d.draw_text("ok :(", x + 15, y + 115, 20, Color::WHITE); - } } fn draw_top_bar(&mut self, d: &mut RaylibDrawHandle, textures: &Textures) { @@ -607,7 +593,7 @@ impl Editor { draw_scaled_texture(d, textures.get("pause"), 260, 4, 2.); if simple_button(d, 296, 4, 32, 32) { self.sim_state = SimState::Editing; - self.popup = EndPopup::None; + self.complete_popup = Popup::Start; } draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.); } @@ -618,7 +604,7 @@ impl Editor { draw_scaled_texture(d, textures.get("play"), 260, 4, 2.); if simple_button(d, 296, 4, 32, 32) { self.sim_state = SimState::Editing; - self.popup = EndPopup::None; + self.complete_popup = Popup::Start; } draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.); } diff --git a/src/solution.rs b/src/solution.rs index f3f7784..09fdee8 100644 --- a/src/solution.rs +++ b/src/solution.rs @@ -21,6 +21,7 @@ pub struct Solution { pub struct Score { pub cycles: usize, pub tiles: usize, + pub area: usize, } impl Solution { @@ -58,8 +59,8 @@ impl Solution { pub fn score_text(&self) -> String { if let Some(score) = &self.score { format!( - "C: {} T: {}", - score.cycles, score.tiles + "C: {} T: {} A: {}", + score.cycles, score.tiles, score.area ) } else { "unsolved".into()