add SwapLoadout

This commit is contained in:
Adam Whitehurst 2020-03-21 10:26:38 -07:00
parent 7eaf6f664b
commit 180ec89060
6 changed files with 45 additions and 4 deletions

View File

@ -125,6 +125,7 @@ pub struct ControllerInputs {
pub wall_leap: Input,
pub respawn: Input,
pub toggle_wield: Input,
pub swap_loadout: Input,
pub charge: Input,
pub move_dir: Vec2<f32>,
pub look_dir: Vec3<f32>,
@ -151,6 +152,7 @@ impl ControllerInputs {
self.wall_leap.tick(dt);
self.respawn.tick(dt);
self.toggle_wield.tick(dt);
self.swap_loadout.tick(dt);
self.charge.tick(dt);
}

View File

@ -129,7 +129,7 @@ pub fn handle_climb(data: &JoinData, update: &mut StateUpdate) {
}
}
/// Checks that player can `Glide` and updates `CharacterState` if so
/// Checks that player can Unwield and updates `CharacterState` if so
pub fn handle_unwield(data: &JoinData, update: &mut StateUpdate) {
if let CharacterState::Wielding { .. } = update.character {
if data.inputs.toggle_wield.is_pressed() {
@ -138,6 +138,16 @@ pub fn handle_unwield(data: &JoinData, update: &mut StateUpdate) {
}
}
/// Checks that player can Swap and updates Loadout
pub fn handle_swap_loadout(data: &JoinData, update: &mut StateUpdate) {
if let CharacterState::Wielding { .. } = update.character {
if data.inputs.swap_loadout.is_pressed() {
//TODO
println!("YAH NAH");
}
}
}
/// Checks that player can glide and updates `CharacterState` if so
pub fn handle_glide(data: &JoinData, update: &mut StateUpdate) {
if let CharacterState::Idle { .. } | CharacterState::Wielding { .. } = update.character {

View File

@ -160,6 +160,9 @@ impl From<&crate::settings::GamepadSettings> for ControllerSettings {
map.entry(settings.game_buttons.toggle_wield)
.or_default()
.push(GameInput::ToggleWield);
map.entry(settings.game_buttons.swap_loadout)
.or_default()
.push(GameInput::SwapLoadout);
map.entry(settings.game_buttons.charge)
.or_default()
.push(GameInput::Charge);

View File

@ -319,6 +319,27 @@ impl PlayState for SessionState {
Event::InputUpdate(GameInput::WallLeap, state) => {
self.inputs.wall_leap.set_state(state)
},
// Event::InputUpdate(GameInput::ToggleWield, state) => {
// self.inputs.toggle_wield.set_state(state);
// },
Event::InputUpdate(GameInput::ToggleWield, state)
| Event::InputUpdate(GameInput::SwapLoadout, state) => {
let mut client = self.client.borrow_mut();
let entity = client.entity();
let loadout = client
.state()
.read_storage::<comp::Loadout>()
.get(entity)
.cloned();
if let Some(loadout) = loadout {
let mut new_loadout = loadout.clone();
new_loadout.second_item = loadout.active_item;
new_loadout.active_item = loadout.second_item;
client.state_mut().write_component(entity, new_loadout);
}
},
Event::InputUpdate(GameInput::Mount, true) => {
let mut client = self.client.borrow_mut();
if client.is_mounted() {
@ -384,9 +405,6 @@ impl PlayState for SessionState {
}
}
},
Event::InputUpdate(GameInput::ToggleWield, state) => {
self.inputs.toggle_wield.set_state(state)
},
Event::InputUpdate(GameInput::Charge, state) => {
self.inputs.charge.set_state(state);
},

View File

@ -50,6 +50,7 @@ pub struct ControlSettings {
pub respawn: KeyMouse,
pub interact: KeyMouse,
pub toggle_wield: KeyMouse,
pub swap_loadout: KeyMouse,
pub charge: KeyMouse,
}
@ -100,6 +101,7 @@ impl Default for ControlSettings {
respawn: KeyMouse::Key(VirtualKeyCode::Space),
interact: KeyMouse::Mouse(MouseButton::Right),
toggle_wield: KeyMouse::Key(VirtualKeyCode::T),
swap_loadout: KeyMouse::Key(VirtualKeyCode::LAlt),
charge: KeyMouse::Key(VirtualKeyCode::Key1),
}
}
@ -183,6 +185,7 @@ pub mod con_settings {
pub respawn: Button,
pub interact: Button,
pub toggle_wield: Button,
pub swap_loadout: Button,
pub charge: Button,
}
@ -268,6 +271,7 @@ pub mod con_settings {
respawn: Button::Simple(GilButton::RightTrigger2),
interact: Button::Simple(GilButton::LeftTrigger2),
toggle_wield: Button::Simple(GilButton::DPadLeft),
swap_loadout: Button::Simple(GilButton::Unknown),
charge: Button::Simple(GilButton::Unknown),
}
}

View File

@ -49,6 +49,7 @@ pub enum GameInput {
Interact,
ToggleWield,
Charge,
SwapLoadout,
}
/// Represents a key that the game menus recognise after input mapping
@ -455,6 +456,9 @@ impl Window {
map.entry(settings.controls.toggle_wield)
.or_default()
.push(GameInput::ToggleWield);
map.entry(settings.controls.swap_loadout)
.or_default()
.push(GameInput::SwapLoadout);
map.entry(settings.controls.charge)
.or_default()
.push(GameInput::Charge);