From a00bfb928ad53401963117b35ff466090a10bdff Mon Sep 17 00:00:00 2001 From: ShenMian <70068015+ShenMian@users.noreply.github.com> Date: Wed, 14 Aug 2024 05:12:40 +0800 Subject: [PATCH] chore(deps): update leafwing-input-manager to v0.15 (#10) --- .gitignore | 1 - Cargo.lock | 41 +++- Cargo.toml | 2 +- README.md | 12 +- docs/auto_move.md | 21 +- docs/{customizing.md => customization.md} | 14 +- docs/level_management.md | 16 +- docs/levels.md | 2 +- docs/solver.md | 20 +- src/input_map.rs | 282 ++++++---------------- src/main.rs | 21 +- src/systems/input.rs | 6 +- 12 files changed, 164 insertions(+), 274 deletions(-) rename docs/{customizing.md => customization.md} (51%) diff --git a/.gitignore b/.gitignore index 94edc75..f4753ec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ /.fleet /.idea config.toml -keymap.toml db.sqlite3 diff --git a/Cargo.lock b/Cargo.lock index 021b61b..d2281b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1788,6 +1788,24 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "dyn-eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2d035d21af5cde1a6f5c7b444a5bf963520a9f142e5d06931178433d7d5388" + +[[package]] +name = "dyn-hash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a650a461c6a8ff1ef205ed9a2ad56579309853fecefc2423f73dced342f92258" + [[package]] name = "either" version = "1.13.0" @@ -2578,22 +2596,27 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leafwing-input-manager" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebb7f3227809906ca7ccc981aedf7805b5edb422b4265290cc749316c0faba4" +checksum = "10cfa701709bb37011dd09965a76ff981f6284ed5b8ac0e5089dcd311efeff49" dependencies = [ "bevy", "derive_more", + "dyn-clone", + "dyn-eq", + "dyn-hash", "itertools 0.13.0", "leafwing_input_manager_macros", + "once_cell", "serde", + "serde_flexitos", ] [[package]] name = "leafwing_input_manager_macros" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d065e4f0771d9cc597e76d648da18476ad01fd50cd60ee585ee500f9cd8d696" +checksum = "61ff6f0b220de1c284422f6af6a529acfaa5dab76ee86d6167eb2ee34502290c" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3946,6 +3969,16 @@ dependencies = [ "syn 2.0.74", ] +[[package]] +name = "serde_flexitos" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a95e8972debc2acae5fa208fd4ec9ba96ace41d2bdd4e715ad4082b822e955" +dependencies = [ + "erased-serde", + "serde", +] + [[package]] name = "serde_json" version = "1.0.124" diff --git a/Cargo.toml b/Cargo.toml index 1958b82..75cc5d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ image = "0.25" toml = "0.8" bevy = "0.14" -leafwing-input-manager = "0.14" +leafwing-input-manager = "0.15" bevy_kira_audio = "0.20" benimator = "4.1" winit = "0.30" # The version needs to be consistent with the one used in bevy diff --git a/README.md b/README.md index 8758098..948369b 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,16 @@ A sokoban with solver.

-- **Level management**: Levels and solutions are stored in the database. [More details](docs/level_management.md). -- **Customizing**: Options can be customized via configuration file. [More details](docs/customizing.md). -- **Map viewing**: Supports moving and zooming the map. When switching levels, the zoom will be automatically adjusted to fit the window size. -- **Player character animation**: Player character has smooth movement and animations in different directions. +- **Level management**: Levels and solutions are stored in a database. [More details](docs/level_management.md). +- **Customization**: Options can be customized via a configuration file. [More details](docs/customization.md). +- **Map viewing**: Supports moving and zooming the map. When switching levels, the zoom will automatically adjust to fit the window size. +- **Player character animation**: The player character has smooth movement and animations in different directions. - **Front-end and back-end separation**: Backend code (such as solvers) is decoupled from the frontend (such as Bevy). ## Acknowledgements - anian <>: For providing comprehensive answers to numerous inquiries regarding Sokoban and offering insightful recommendations. -- [@PaperPlaneLSY](https://github.com/PaperPlaneLSY): For testing, improving the skin, and additional support. +- [@PaperPlaneLSY](https://github.com/PaperPlaneLSY): For testing, improving the skin, and providing additional support. ## Keymap @@ -76,4 +76,4 @@ A sokoban with solver. | `X`/`Square` | Toggle instant move[^1] | | `Y`/`Triangle` | Toggle automatic solution | -[^1]: Turn off character and boxes movement animations. +[^1]: Disables character and box movement animations. diff --git a/docs/auto_move.md b/docs/auto_move.md index 711f415..96d7a35 100644 --- a/docs/auto_move.md +++ b/docs/auto_move.md @@ -4,8 +4,7 @@

-This feature can significantly assist users when playing larger levels. -At the same time, it also maintains the traditional control method. +This feature can significantly assist users when playing larger levels while maintaining the traditional control method. Clicking on a box will display all the points that the box can reach (without moving other boxes). @@ -13,28 +12,28 @@ Take Microban #155 as an example:

-Clicking on one of the points will automatically push the selected box to that position. +Clicking on one of these points will automatically push the selected box to that position. -In this case, the user can click on the target, and the character will automatically push the selected box to the target to complete the level. +In this case, the user can click on the target, and the character will automatically push the selected box to that target to complete the level. -Some areas where the boxes are reachable do not display points. This is because pushing the box to those positions will lead to a deadlock and the player will be unable to continue completing the level. +Some areas where the boxes are reachable do not display points. This is because pushing the box to those positions would lead to a deadlock, making it impossible for the player to continue and complete the level.

## Auto player move -Click to select the player and display the player's reachable area. Click on a position in the area and the player will automatically move to that position. +Click to select the player and display the player's reachable area. Clicking on a position within this area will make the player automatically move to that position.

-User can also directly click on the player's reachable area without selecting the player, and the player will automatically move to that position. +Users can also directly click on the player's reachable area without selecting the player, and the player will automatically move to that position. ## Controversial -This feature is a bit controversial, with some users saying it's akin to cheating. +This feature is somewhat controversial, with some users arguing that it is akin to cheating. -For simple levels, this does significantly reduce the level difficulty. An extreme example is a level with only a single box and target, which means the player can complete it without having to do any reasoning. +For simple levels, it does significantly reduce the difficulty. For example, a level with only a single box and target can be completed without any additional reasoning. -But for challenging levels, the difficulty mainly lies in the intricate pushing relationship between multiple boxes, rather than the pushing of a single box. This feature allows players to focus on more complex reasoning instead of repeating the simple work of pushing a single box. +However, for challenging levels, the difficulty mainly lies in the intricate relationships between multiple boxes, rather than the task of pushing a single box. This feature allows players to focus on more complex reasoning instead of repeatedly performing the simple task of pushing a single box. -In addition, this feature is **optional**. Users can still use the traditional control methods. +Additionally, this feature is **optional**. Users can still use the traditional control methods. diff --git a/docs/customizing.md b/docs/customization.md similarity index 51% rename from docs/customizing.md rename to docs/customization.md index 8834508..b5f2ccf 100644 --- a/docs/customizing.md +++ b/docs/customization.md @@ -1,19 +1,19 @@ -# Customizing +# Customization ## Configuration The user can configure settings by editing `config.toml` in the same directory. If the file does not exist, a default configuration file will be automatically generated when the program is run. ```toml -# Player movement animation speed, seconds per step. +# Player movement animation speed, in seconds per step. player_move_speed = 0.1 -# Make the floor look like a chessboard with alternating light square and dark square. +# Makes the floor look like a chessboard with alternating light and dark squares. even_square_shades = 0.1 # Audio volume. volume = 0.5 -# Disable player movement animation. +# Disables player movement animation. instant_move = false -# Enable auto switch to next unsolved level when the current level is solved. +# Enables automatic switching to the next unsolved level when the current level is solved. auto_switch_to_next_unsolved_level = true [solver] @@ -22,7 +22,3 @@ lower_bound_method = "MinimumMove" ``` For `solver` related configuration options, please refer to [Solver](./solver.md). - -## Keymap - -The user can configure keymap by editing `keymap.toml` in the same directory. If the file does not exist, a default keymap configuration file will be automatically generated when the program is run. diff --git a/docs/level_management.md b/docs/level_management.md index a92729f..10f7a92 100644 --- a/docs/level_management.md +++ b/docs/level_management.md @@ -10,22 +10,22 @@ | Box | `$` | | Box on target | `*` | | Target | `.` | -| Floor | ` `/`-`/`_` | +| Floor | ``/`-`/`_` | ## Import -Supports importing levels in XSB format (support run-length encoding) from files or system clipboard: +Supports importing levels in XSB format (including run-length encoding) from files or the system clipboard: -- Import from files: The user can drag single or multiple level files in XSB format into the window. -- Import from clipboard: If some levels in XSB format is already in the clipboard, it can be imported using the input action. +- Import from files: Users can drag single or multiple level files in XSB format into the window. +- Import from clipboard: If levels in XSB format are already in the clipboard, they can be imported using the input action. -The levels will first be standardized to prevent repeated import of the same or similar levels. The standardized levels are only used for deduplication, and the final imported levels are not standardized. +Levels are first standardized to prevent repeated imports of the same or similar levels. The standardized levels are used only for deduplication, and the final imported levels are not standardized. -Levels that meet the following conditions are considered similar: +Levels are considered similar if they meet the following conditions: -- The starting positions of the player characters are different, but in the same closed area. +- The starting positions of the player characters are different but within the same closed area. - After rotation and inversion. -- The difference is only in the decorations that are inaccessible to the character. These decorations can make the level more beautiful, but do not affect the solution of the level. +- The difference is only in decorations that are inaccessible to the character. While these decorations may enhance the appearance of the level, they do not affect the level's solution. ## Export diff --git a/docs/levels.md b/docs/levels.md index 3435503..e56c6b1 100644 --- a/docs/levels.md +++ b/docs/levels.md @@ -1,6 +1,6 @@ # Levels -The levels included in this sokoban game program are borrowed from various other sokoban games and are the intellectual property of their respective original designers. These levels are utilized within this program solely for the purpose of testing the solver. +The levels included in this Sokoban game program are borrowed from various other Sokoban games and are the intellectual property of their respective original designers. These levels are used in this program solely for the purpose of testing the solver. We do not claim ownership of these levels, and all rights remain with the original creators. | File | Author | diff --git a/docs/solver.md b/docs/solver.md index 3eaceb9..dc36a50 100644 --- a/docs/solver.md +++ b/docs/solver.md @@ -6,16 +6,16 @@ The solver can automatically solve levels of moderate complexity. ## Strategy -- `Fast`: Speed priority. -- `Mixed`: Balanced speed and steps. -- `OptimalMovePush`: Find move optimal solutions with best pushes. -- `OptimalPushMove`: Find push optimal solutions with best moves. +- `Fast`: Prioritizes speed. +- `Mixed`: Balances speed and steps. +- `OptimalMovePush`: Finds optimal move solutions with the fewest pushes. +- `OptimalPushMove`: Finds optimal push solutions with the fewest moves. ## Lower bound calculation method -- `MinimumPush`: Minimum push count to nearest target. -- `MinimumMove`: Minimum move count to nearest target. (This method is slow, especially on maps with many boxes or large areas) -- `ManhattanDistance`: Manhattan distance to nearest target. (This method is fast, suitable for maps with many boxes or large areas) +- `MinimumPush`: Counts the minimum number of pushes to the nearest target. +- `MinimumMove`: Counts the minimum number of moves to the nearest target. (This method is slow, especially on maps with many boxes or large areas) +- `ManhattanDistance`: Uses Manhattan distance to the nearest target. (This method is fast and suitable for maps with many boxes or large areas) ## Optimization @@ -38,9 +38,9 @@ Time limit: 10 seconds. ## Visualization -Supports visualizing the automatic solution process. This feature can be used to intuitively view the working status of the solver. +Supports visualizing the automatic solution process. This feature allows you to intuitively view the working status of the solver. -- Display the best state found by the solver. -- Display the lower bounds as a heat map. +- Displays the best state found by the solver. +- Displays lower bounds as a heat map.

diff --git a/src/input_map.rs b/src/input_map.rs index 54fee67..7408865 100644 --- a/src/input_map.rs +++ b/src/input_map.rs @@ -3,7 +3,7 @@ use leafwing_input_manager::prelude::*; use serde::{Deserialize, Serialize}; #[derive( - Actionlike, Component, Reflect, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize, + Actionlike, Component, Reflect, Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize, Debug, )] pub enum Action { MoveUp, @@ -32,208 +32,84 @@ pub enum Action { } pub fn default_input_map() -> InputMap { - use leafwing_input_manager::user_input::InputKind::*; - let mouse_input_map = InputMap::new([ - ( - Action::Undo, - UserInput::Single(Mouse(MouseButton::Other(1))), - ), - ( - Action::Redo, - UserInput::Single(Mouse(MouseButton::Other(2))), - ), - ( - Action::ZoomOut, - UserInput::Single(MouseWheel(MouseWheelDirection::Down)), - ), - ( - Action::ZoomIn, - UserInput::Single(MouseWheel(MouseWheelDirection::Up)), - ), - ]); - let keyboard_input_map = InputMap::new([ - ( - Action::MoveUp, - UserInput::Single(PhysicalKey(KeyCode::KeyW)), - ), - ( - Action::MoveDown, - UserInput::Single(PhysicalKey(KeyCode::KeyS)), - ), - ( - Action::MoveLeft, - UserInput::Single(PhysicalKey(KeyCode::KeyA)), - ), - ( - Action::MoveRight, - UserInput::Single(PhysicalKey(KeyCode::KeyD)), - ), - ( - Action::MoveUp, - UserInput::Single(PhysicalKey(KeyCode::ArrowUp)), - ), - ( - Action::MoveDown, - UserInput::Single(PhysicalKey(KeyCode::ArrowDown)), - ), - ( - Action::MoveLeft, - UserInput::Single(PhysicalKey(KeyCode::ArrowLeft)), - ), - ( - Action::MoveRight, - UserInput::Single(PhysicalKey(KeyCode::ArrowRight)), - ), - ( - Action::Undo, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::KeyZ), - ]), - ), - ( - Action::Redo, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::ShiftLeft), - PhysicalKey(KeyCode::KeyZ), - ]), - ), - ( - Action::ResetLevel, - UserInput::Single(PhysicalKey(KeyCode::Escape)), - ), - ( - Action::NextLevel, - UserInput::Single(PhysicalKey(KeyCode::BracketRight)), - ), - ( - Action::PreviousLevel, - UserInput::Single(PhysicalKey(KeyCode::BracketLeft)), - ), - ( - Action::NextUnsolvedLevel, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::BracketRight), - ]), - ), - ( - Action::PreviousUnsolvedLevel, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::BracketLeft), - ]), - ), - ( - Action::ZoomIn, - UserInput::Single(PhysicalKey(KeyCode::Equal)), - ), - ( - Action::ZoomOut, - UserInput::Single(PhysicalKey(KeyCode::Minus)), - ), - ( - Action::ToggleInstantMove, - UserInput::Single(PhysicalKey(KeyCode::KeyI)), - ), - ( - Action::ToggleAutomaticSolution, - UserInput::Single(PhysicalKey(KeyCode::KeyP)), - ), - ( - Action::ToggleFullscreen, - UserInput::Single(PhysicalKey(KeyCode::F11)), - ), - ( - Action::ImportLevelsFromClipboard, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::KeyV), - ]), - ), - ( - Action::ExportLevelToClipboard, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::KeyC), - ]), - ), - // PhysicalKey (Vim) - ( - Action::MoveUp, - UserInput::Single(PhysicalKey(KeyCode::KeyK)), - ), - ( - Action::MoveDown, - UserInput::Single(PhysicalKey(KeyCode::KeyJ)), - ), - ( - Action::MoveLeft, - UserInput::Single(PhysicalKey(KeyCode::KeyH)), - ), - ( - Action::MoveRight, - UserInput::Single(PhysicalKey(KeyCode::KeyL)), - ), - (Action::Undo, UserInput::Single(PhysicalKey(KeyCode::KeyU))), - ( - Action::Redo, - UserInput::Chord(vec![ - PhysicalKey(KeyCode::ControlLeft), - PhysicalKey(KeyCode::KeyR), - ]), - ), - ]); - let gamepad_input_map = InputMap::new([ - ( - Action::MoveUp, - UserInput::Single(GamepadButton(GamepadButtonType::DPadUp)), - ), - ( - Action::MoveDown, - UserInput::Single(GamepadButton(GamepadButtonType::DPadDown)), - ), - ( - Action::MoveLeft, - UserInput::Single(GamepadButton(GamepadButtonType::DPadLeft)), - ), - ( - Action::MoveRight, - UserInput::Single(GamepadButton(GamepadButtonType::DPadRight)), - ), - ( - Action::Undo, - UserInput::Single(GamepadButton(GamepadButtonType::East)), - ), - ( - Action::Redo, - UserInput::Single(GamepadButton(GamepadButtonType::South)), - ), - ( - Action::NextLevel, - UserInput::Single(GamepadButton(GamepadButtonType::RightTrigger)), - ), - ( - Action::PreviousLevel, - UserInput::Single(GamepadButton(GamepadButtonType::LeftTrigger)), - ), - ( - Action::ZoomIn, - UserInput::Single(GamepadButton(GamepadButtonType::RightTrigger2)), - ), - ( - Action::ZoomOut, - UserInput::Single(GamepadButton(GamepadButtonType::LeftTrigger2)), - ), - ( - Action::ToggleInstantMove, - UserInput::Single(GamepadButton(GamepadButtonType::West)), - ), - ( - Action::ToggleAutomaticSolution, - UserInput::Single(GamepadButton(GamepadButtonType::North)), - ), + let mouse_input_map = InputMap::default() + .with_multiple([ + (Action::Undo, MouseButton::Other(1)), + (Action::Redo, MouseButton::Other(2)), + ]) + .with_multiple([ + (Action::ZoomOut, MouseScrollDirection::DOWN), + (Action::ZoomIn, MouseScrollDirection::UP), + ]); + let keyboard_input_map = InputMap::default() + .with_multiple([ + (Action::MoveUp, KeyCode::KeyW), + (Action::MoveDown, KeyCode::KeyS), + (Action::MoveLeft, KeyCode::KeyA), + (Action::MoveRight, KeyCode::KeyD), + (Action::MoveUp, KeyCode::ArrowUp), + (Action::MoveDown, KeyCode::ArrowDown), + (Action::MoveLeft, KeyCode::ArrowLeft), + (Action::MoveRight, KeyCode::ArrowRight), + (Action::ResetLevel, KeyCode::Escape), + (Action::NextLevel, KeyCode::BracketRight), + (Action::PreviousLevel, KeyCode::BracketLeft), + (Action::ZoomIn, KeyCode::Equal), + (Action::ZoomOut, KeyCode::Minus), + (Action::ToggleInstantMove, KeyCode::KeyI), + (Action::ToggleAutomaticSolution, KeyCode::KeyP), + (Action::ToggleFullscreen, KeyCode::F11), + // Vim + (Action::MoveUp, KeyCode::KeyK), + (Action::MoveDown, KeyCode::KeyJ), + (Action::MoveLeft, KeyCode::KeyH), + (Action::MoveRight, KeyCode::KeyL), + (Action::Undo, KeyCode::KeyU), + ]) + .with_multiple([ + ( + Action::Undo, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::KeyZ]), + ), + ( + Action::Redo, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::ShiftLeft, KeyCode::KeyZ]), + ), + ( + Action::NextUnsolvedLevel, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::BracketRight]), + ), + ( + Action::PreviousUnsolvedLevel, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::BracketLeft]), + ), + ( + Action::ImportLevelsFromClipboard, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::KeyV]), + ), + ( + Action::ExportLevelToClipboard, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::KeyC]), + ), + // Vim + ( + Action::Redo, + ButtonlikeChord::new([KeyCode::ControlLeft, KeyCode::KeyR]), + ), + ]); + let gamepad_input_map = InputMap::default().with_multiple([ + (Action::MoveUp, GamepadButtonType::DPadUp), + (Action::MoveDown, GamepadButtonType::DPadDown), + (Action::MoveLeft, GamepadButtonType::DPadLeft), + (Action::MoveRight, GamepadButtonType::DPadRight), + (Action::Undo, GamepadButtonType::East), + (Action::Redo, GamepadButtonType::South), + (Action::NextLevel, GamepadButtonType::RightTrigger), + (Action::PreviousLevel, GamepadButtonType::LeftTrigger), + (Action::ZoomIn, GamepadButtonType::RightTrigger2), + (Action::ZoomOut, GamepadButtonType::LeftTrigger2), + (Action::ToggleInstantMove, GamepadButtonType::West), + (Action::ToggleAutomaticSolution, GamepadButtonType::North), ]); InputMap::default() .merge(&mouse_input_map) diff --git a/src/main.rs b/src/main.rs index 12a9aa0..3885248 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,9 +18,8 @@ use std::{fs, path::Path}; use events::*; use input_map::*; -use leafwing_input_manager::prelude::*; -use plugins::performance_matrix::*; -use plugins::version_information::*; +use leafwing_input_manager::{action_diff::ActionDiffEvent, prelude::*}; +use plugins::{performance_matrix::*, version_information::*}; use resources::*; use state::*; use systems::{audio::*, auto_move::*, auto_solve::*, input::*, level::*, render::*, ui::*}; @@ -30,7 +29,6 @@ use bevy::prelude::*; use bevy_kira_audio::prelude::*; const CONFIG_FILE_PATH: &str = "config.toml"; -const KEYMAP_FILE_PATH: &str = "keymap.toml"; fn load_config() -> Config { let config_toml = fs::read_to_string(CONFIG_FILE_PATH).unwrap(); @@ -38,17 +36,6 @@ fn load_config() -> Config { config } -fn load_input_map() -> InputMap { - if !Path::new(KEYMAP_FILE_PATH).is_file() { - let default_keymap_toml = toml::to_string(&default_input_map()).unwrap(); - fs::write(KEYMAP_FILE_PATH, default_keymap_toml).unwrap(); - } - let keymap_toml = fs::read_to_string(KEYMAP_FILE_PATH).unwrap(); - let input_map: InputMap = - toml::from_str(keymap_toml.as_str()).expect("failed to parse `keymap.toml`"); - input_map -} - fn save_config(config: &Config) { let config_toml = toml::to_string(&config).unwrap(); fs::write(CONFIG_FILE_PATH, config_toml).unwrap(); @@ -160,9 +147,9 @@ fn main() { .insert_resource(player_movement) .insert_resource(AutoMoveState::default()); - let input_map = load_input_map(); app.init_resource::>() - .insert_resource(input_map); + .insert_resource(default_input_map()) + .add_event::>(); app.add_event::() .add_event::() diff --git a/src/systems/input.rs b/src/systems/input.rs index be91932..8fbaf90 100644 --- a/src/systems/input.rs +++ b/src/systems/input.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, fs}; use bevy::{input::mouse::MouseMotion, prelude::*, window::WindowMode}; -use leafwing_input_manager::prelude::*; +use leafwing_input_manager::{action_diff::ActionDiffEvent, prelude::*}; use nalgebra::Vector2; use soukoban::{direction::Direction, Level, Tiles}; @@ -11,8 +11,8 @@ use crate::{ }; /// Clears the action state by consuming all stored actions. -pub fn clear_action_state(mut action_state: ResMut>) { - action_state.consume_all(); +pub fn clear_action_state(mut action_diff_events: EventReader>) { + action_diff_events.clear(); } pub fn handle_actions(