Compare commits
2 commits
e3f8087a6b
...
70c745117f
Author | SHA1 | Date | |
---|---|---|---|
70c745117f | |||
14b87e6971 |
3 changed files with 47 additions and 35 deletions
|
@ -7,7 +7,6 @@ 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
|
||||
|
|
|
@ -56,8 +56,7 @@ pub struct Editor {
|
|||
time_since_step: f32,
|
||||
exit_state: ExitState,
|
||||
exit_menu: bool,
|
||||
complete_popup: Popup,
|
||||
// fail_popup: Popup,
|
||||
popup: EndPopup,
|
||||
score: Option<Score>,
|
||||
blueprints: Vec<Blueprint>,
|
||||
selected_blueprint: usize,
|
||||
|
@ -69,9 +68,10 @@ pub struct Editor {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum Popup {
|
||||
Start,
|
||||
Visible,
|
||||
enum EndPopup {
|
||||
None,
|
||||
Success,
|
||||
Failure,
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,7 @@ impl Editor {
|
|||
level,
|
||||
exit_state: ExitState::Dont,
|
||||
exit_menu: false,
|
||||
complete_popup: Popup::Start,
|
||||
// fail_popup: Popup::Start,
|
||||
popup: EndPopup::None,
|
||||
score: solution.score,
|
||||
blueprints: get_blueprints(),
|
||||
selected_blueprint: usize::MAX,
|
||||
|
@ -190,22 +189,25 @@ impl Editor {
|
|||
fn step(&mut self) {
|
||||
self.machine.step();
|
||||
|
||||
if self.complete_popup == Popup::Visible {
|
||||
self.complete_popup = Popup::Dismissed;
|
||||
if self.popup != EndPopup::None {
|
||||
self.popup = EndPopup::Dismissed;
|
||||
}
|
||||
if !self.level.outputs().is_empty()
|
||||
&& self.level.outputs() == self.machine.output()
|
||||
&& self.complete_popup == Popup::Start
|
||||
&& self.popup == EndPopup::None
|
||||
{
|
||||
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,
|
||||
});
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +335,7 @@ impl Editor {
|
|||
pub fn update(&mut self, rl: &RaylibHandle) {
|
||||
if rl.is_key_pressed(KeyboardKey::KEY_ESCAPE) {
|
||||
self.sim_state = SimState::Editing;
|
||||
self.complete_popup = Popup::Start;
|
||||
self.popup = EndPopup::None;
|
||||
}
|
||||
if self.sim_state == SimState::Running {
|
||||
self.time_since_step += rl.get_frame_time();
|
||||
|
@ -374,7 +376,7 @@ impl Editor {
|
|||
}
|
||||
SimState::Running => {
|
||||
self.sim_state = SimState::Editing;
|
||||
self.complete_popup = Popup::Start;
|
||||
self.popup = EndPopup::None;
|
||||
}
|
||||
SimState::Stepping => self.sim_state = SimState::Running,
|
||||
}
|
||||
|
@ -511,7 +513,7 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
if self.complete_popup == Popup::Visible {
|
||||
if self.popup == EndPopup::Success {
|
||||
let width = 320;
|
||||
let height = 165;
|
||||
let x = d.get_screen_width() / 2 - width / 2;
|
||||
|
@ -520,14 +522,12 @@ 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, 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);
|
||||
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);
|
||||
}
|
||||
if simple_button(d, x + 10, y + 110, 140, 45) {
|
||||
self.complete_popup = Popup::Dismissed;
|
||||
self.popup = EndPopup::Dismissed;
|
||||
}
|
||||
d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE);
|
||||
|
||||
|
@ -542,6 +542,20 @@ 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) {
|
||||
|
@ -593,7 +607,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.complete_popup = Popup::Start;
|
||||
self.popup = EndPopup::None;
|
||||
}
|
||||
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
||||
}
|
||||
|
@ -604,7 +618,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.complete_popup = Popup::Start;
|
||||
self.popup = EndPopup::None;
|
||||
}
|
||||
draw_scaled_texture(d, textures.get("stop"), 296, 4, 2.);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ pub struct Solution {
|
|||
pub struct Score {
|
||||
pub cycles: usize,
|
||||
pub tiles: usize,
|
||||
pub area: usize,
|
||||
}
|
||||
|
||||
impl Solution {
|
||||
|
@ -59,8 +58,8 @@ impl Solution {
|
|||
pub fn score_text(&self) -> String {
|
||||
if let Some(score) = &self.score {
|
||||
format!(
|
||||
"C: {} T: {} A: {}",
|
||||
score.cycles, score.tiles, score.area
|
||||
"C: {} T: {}",
|
||||
score.cycles, score.tiles
|
||||
)
|
||||
} else {
|
||||
"unsolved".into()
|
||||
|
|
Loading…
Add table
Reference in a new issue