Skip to content

Commit

Permalink
Add Comments, Improve Style, Remove Unneeded Code
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Jul 18, 2022
1 parent 21fb9a8 commit fd0716e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 46 deletions.
17 changes: 12 additions & 5 deletions src/metadata/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ use crate::input::PlayerAction;
/// Global settings, stored and accessed through [`crate::platform::Storage`]
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Settings {
// The player controller bindings
pub player_controls: PlayerControlMethods,
}

impl Settings {
/// The key used to store the settings in the [`crate::platform::Storage`] resource.
pub const STORAGE_KEY: &'static str = "settings";
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct PlayerControlMethods {
/// Controls for game remotes
pub gamepad: PlayerControls,
/// Controls for keyboard player 1
pub keyboard1: PlayerControls,
/// Controls for keyboard player 2
pub keyboard2: PlayerControls,
}

impl PlayerControlMethods {
pub(crate) fn get_input_map(&self, player_idx: usize) -> InputMap<PlayerAction> {
/// Get the input map for the given player index
pub fn get_input_map(&self, player_idx: usize) -> InputMap<PlayerAction> {
let mut input_map = InputMap::default();

input_map.set_gamepad(Gamepad(player_idx));
Expand All @@ -42,14 +52,11 @@ impl PlayerControlMethods {
}
}

/// Binds inputs to player actions
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct PlayerControls {
pub movement: VirtualDPad,
pub flop_attack: InputKind,
pub throw: InputKind,
pub shoot: InputKind,
}

impl Settings {
pub const STORAGE_KEY: &'static str = "settings";
}
9 changes: 4 additions & 5 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_egui::{egui, EguiContext, EguiInput, EguiPlugin, EguiSettings};
use iyes_loopless::prelude::*;
use leafwing_input_manager::prelude::ActionState;

use crate::{assets::EguiFont, audio::*, input::MenuAction, metadata::GameMeta, GameState};
use crate::{assets::EguiFont, audio, input::MenuAction, metadata::GameMeta, GameState};

pub mod hud;
pub mod widgets;
Expand All @@ -22,9 +22,9 @@ impl Plugin for UIPlugin {
.add_plugin(EguiPlugin)
.add_system(handle_menu_input.run_if_resource_exists::<GameMeta>())
.add_enter_system(GameState::MainMenu, main_menu::spawn_main_menu_background)
.add_enter_system(GameState::MainMenu, play_menu_music)
.add_enter_system(GameState::MainMenu, audio::play_menu_music)
.add_exit_system(GameState::MainMenu, main_menu::despawn_main_menu_background)
.add_exit_system(GameState::MainMenu, stop_menu_music)
.add_exit_system(GameState::MainMenu, audio::stop_menu_music)
.add_system(hud::render_hud.run_in_state(GameState::InGame))
.add_system(update_egui_fonts)
.add_system(update_ui_scale.run_if_resource_exists::<GameMeta>())
Expand All @@ -43,7 +43,7 @@ impl Plugin for UIPlugin {
}
}

/// Resource that store which ui widgets are adjacent to which other widgets.
/// Resource that stores which ui widgets are adjacent to which other widgets.
///
/// This is used to figure out which widget to focus on next when you press a direction on the
/// gamepad, for instance.
Expand Down Expand Up @@ -86,7 +86,6 @@ pub struct WidgetAdjacencyEntry<'a> {
adjacencies: &'a mut WidgetAdjacencies,
}

#[allow(dead_code)] // We haven't used all these helpers yet
#[allow(clippy::wrong_self_convention)]
impl<'a> WidgetAdjacencyEntry<'a> {
pub fn to_left_of(self, resp: &egui::Response) -> Self {
Expand Down
Loading

0 comments on commit fd0716e

Please sign in to comment.