mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
split toggle events
This commit is contained in:
@ -307,11 +307,49 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swap_loadout(&mut self) { self.control_action(ControlAction::SwapLoadout); }
|
pub fn swap_loadout(&mut self) {
|
||||||
|
let can_swap = self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<comp::CharacterState>()
|
||||||
|
.get(self.entity)
|
||||||
|
.map(|cs| cs.can_swap());
|
||||||
|
match can_swap {
|
||||||
|
Some(true) => self.control_action(ControlAction::SwapLoadout),
|
||||||
|
Some(false) => {},
|
||||||
|
None => warn!("Can't swap, client entity doesn't have a `CharacterState`"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toggle_wield(&mut self) { self.control_action(ControlAction::ToggleWield); }
|
pub fn toggle_wield(&mut self) {
|
||||||
|
let is_wielding = self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<comp::CharacterState>()
|
||||||
|
.get(self.entity)
|
||||||
|
.map(|cs| cs.is_wield());
|
||||||
|
|
||||||
pub fn toggle_sit(&mut self) { self.control_action(ControlAction::ToggleSit); }
|
match is_wielding {
|
||||||
|
Some(true) => self.control_action(ControlAction::Unwield),
|
||||||
|
Some(false) => self.control_action(ControlAction::Wield),
|
||||||
|
None => warn!("Can't toggle wield, client entity doesn't have a `CharacterState`"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn toggle_sit(&mut self) {
|
||||||
|
let is_sitting = self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<comp::CharacterState>()
|
||||||
|
.get(self.entity)
|
||||||
|
.map(|cs| matches!(cs, comp::CharacterState::Sit));
|
||||||
|
|
||||||
|
match is_sitting {
|
||||||
|
Some(true) => self.control_action(ControlAction::Stand),
|
||||||
|
Some(false) => self.control_action(ControlAction::Sit),
|
||||||
|
None => warn!("Can't toggle sit, client entity doesn't have a `CharacterState`"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn control_action(&mut self, control_action: ControlAction) {
|
fn control_action(&mut self, control_action: ControlAction) {
|
||||||
if let Some(controller) = self
|
if let Some(controller) = self
|
||||||
|
@ -18,8 +18,10 @@ pub enum ControlEvent {
|
|||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum ControlAction {
|
pub enum ControlAction {
|
||||||
SwapLoadout,
|
SwapLoadout,
|
||||||
ToggleWield,
|
Wield,
|
||||||
ToggleSit,
|
Unwield,
|
||||||
|
Sit,
|
||||||
|
Stand,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
@ -20,13 +20,13 @@ impl CharacterBehavior for Data {
|
|||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_wield(&self, data: &JoinData) -> StateUpdate {
|
fn wield(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
attempt_wield(data, &mut update);
|
attempt_wield(data, &mut update);
|
||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_sit(&self, data: &JoinData) -> StateUpdate {
|
fn sit(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
attempt_sit(data, &mut update);
|
attempt_sit(data, &mut update);
|
||||||
update
|
update
|
||||||
|
@ -21,13 +21,13 @@ impl CharacterBehavior for Data {
|
|||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_wield(&self, data: &JoinData) -> StateUpdate {
|
fn wield(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
attempt_wield(data, &mut update);
|
attempt_wield(data, &mut update);
|
||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_sit(&self, data: &JoinData) -> StateUpdate {
|
fn stand(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
// Try to Fall/Stand up/Move
|
// Try to Fall/Stand up/Move
|
||||||
update.character = CharacterState::Idle;
|
update.character = CharacterState::Idle;
|
||||||
|
@ -22,13 +22,13 @@ impl CharacterBehavior for Data {
|
|||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_sit(&self, data: &JoinData) -> StateUpdate {
|
fn sit(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
attempt_sit(data, &mut update);
|
attempt_sit(data, &mut update);
|
||||||
update
|
update
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_wield(&self, data: &JoinData) -> StateUpdate {
|
fn unwield(&self, data: &JoinData) -> StateUpdate {
|
||||||
let mut update = StateUpdate::from(data);
|
let mut update = StateUpdate::from(data);
|
||||||
update.character = CharacterState::Idle;
|
update.character = CharacterState::Idle;
|
||||||
update
|
update
|
||||||
|
@ -17,13 +17,17 @@ pub trait CharacterBehavior {
|
|||||||
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
||||||
// Impl these to provide behavior for these inputs
|
// Impl these to provide behavior for these inputs
|
||||||
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
fn swap_loadout(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
fn toggle_wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
fn toggle_sit(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
fn unwield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
|
fn sit(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
|
fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||||
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
||||||
match event {
|
match event {
|
||||||
ControlAction::SwapLoadout => self.swap_loadout(data),
|
ControlAction::SwapLoadout => self.swap_loadout(data),
|
||||||
ControlAction::ToggleWield => self.toggle_wield(data),
|
ControlAction::Wield => self.wield(data),
|
||||||
ControlAction::ToggleSit => self.toggle_sit(data),
|
ControlAction::Unwield => self.unwield(data),
|
||||||
|
ControlAction::Sit => self.sit(data),
|
||||||
|
ControlAction::Stand => self.stand(data),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fn init(data: &JoinData) -> CharacterState;
|
// fn init(data: &JoinData) -> CharacterState;
|
||||||
|
Reference in New Issue
Block a user