From 66bda657a2804382bf3803d75d5fb4ecee61fd70 Mon Sep 17 00:00:00 2001 From: ShenMian Date: Wed, 17 Jan 2024 20:03:40 +0800 Subject: [PATCH] feat: support reset current level --- README.md | 3 ++- src/systems/input.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5588327..dd03f3e 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,13 @@ A sokoban with a solver. ### Keyboard | Key | Action | -|------------------------|-----------------------------------| +| ---------------------- | --------------------------------- | | `W`/`A`/`S`/`D` | Move the character | | Arrow keys | Move the character | | `[`/`]` | Switch to the previous/next level | | `Ctrl` + `Z` | Undo last push | | `Ctrl` + `Shift` + `Z` | Redo last push | +| `Esc` | Reset current level | | `-`/`=` | Zoom in/out | | `Ctrl` + `V` | Import levels from clipboard | | `Ctrl` + `C` | Export level to clipboard | diff --git a/src/systems/input.rs b/src/systems/input.rs index 9563c56..98b87f4 100644 --- a/src/systems/input.rs +++ b/src/systems/input.rs @@ -22,6 +22,7 @@ pub enum Action { Undo, Redo, + ResetLevel, PreviousLevel, NextLevel, @@ -95,6 +96,10 @@ impl Action { ]), Self::Redo, ), + ( + UserInput::Single(InputKind::Keyboard(KeyCode::Escape)), + Self::ResetLevel, + ), ( UserInput::Single(InputKind::Keyboard(KeyCode::BracketLeft)), Self::PreviousLevel, @@ -298,6 +303,10 @@ pub fn handle_other_action( settings.instant_move = !settings.instant_move; } + if action_state.just_pressed(Action::ResetLevel) { + **level_id = **level_id; + } + let database = database.lock().unwrap(); if action_state.just_pressed(Action::PreviousLevel) { player_movement.directions.clear();