mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Server events directly emitted in states now.
This commit is contained in:
parent
6a1e583d45
commit
f026aeb2dc
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
combat::Attack,
|
||||
comp::{Energy, LoadoutManip, Ori, Pos, Vel},
|
||||
comp::{Energy, Ori, Pos, Vel},
|
||||
event::{LocalEvent, ServerEvent},
|
||||
states::{behavior::JoinData, *},
|
||||
};
|
||||
@ -17,7 +17,6 @@ pub struct StateUpdate {
|
||||
pub ori: Ori,
|
||||
pub energy: Energy,
|
||||
pub swap_loadout: bool,
|
||||
pub modify_loadout: Option<LoadoutManip>,
|
||||
pub local_events: VecDeque<LocalEvent>,
|
||||
pub server_events: VecDeque<ServerEvent>,
|
||||
}
|
||||
@ -30,7 +29,6 @@ impl From<&JoinData<'_>> for StateUpdate {
|
||||
ori: *data.ori,
|
||||
energy: *data.energy,
|
||||
swap_loadout: false,
|
||||
modify_loadout: None,
|
||||
character: data.character.clone(),
|
||||
local_events: VecDeque::new(),
|
||||
server_events: VecDeque::new(),
|
||||
|
@ -44,7 +44,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
theropod, Body, CharacterState, LoadoutManip, StateUpdate,
|
||||
},
|
||||
consts::{FRIC_GROUND, GRAVITY},
|
||||
event::LocalEvent,
|
||||
event::{LocalEvent, ServerEvent},
|
||||
states::{behavior::JoinData, *},
|
||||
util::Dir,
|
||||
};
|
||||
@ -360,8 +360,17 @@ pub fn attempt_swap_loadout(data: &JoinData, update: &mut StateUpdate) {
|
||||
}
|
||||
|
||||
/// Handles inventory manipulations that affect the loadout
|
||||
pub fn handle_modify_loadout(update: &mut StateUpdate, loadout_manip: Option<LoadoutManip>) {
|
||||
update.modify_loadout = loadout_manip;
|
||||
pub fn handle_modify_loadout(
|
||||
data: &JoinData,
|
||||
update: &mut StateUpdate,
|
||||
loadout_manip: Option<LoadoutManip>,
|
||||
) {
|
||||
if let Some(loadout_manip) = loadout_manip {
|
||||
update.server_events.push_front(ServerEvent::InventoryManip(
|
||||
data.entity,
|
||||
loadout_manip.into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks that player can wield the glider and updates `CharacterState` if so
|
||||
|
@ -59,7 +59,7 @@ impl CharacterBehavior for Data {
|
||||
|
||||
fn modify_loadout(&self, data: &JoinData, loadout_manip: Option<LoadoutManip>) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_modify_loadout(&mut update, loadout_manip);
|
||||
handle_modify_loadout(&data, &mut update, loadout_manip);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -268,10 +268,6 @@ impl<'a> System<'a> for Sys {
|
||||
};
|
||||
local_emitter.append(&mut state_update.local_events);
|
||||
server_emitter.append(&mut state_update.server_events);
|
||||
if let Some(loadout_manip) = state_update.modify_loadout {
|
||||
server_emitter
|
||||
.emit(ServerEvent::InventoryManip(j.entity, loadout_manip.into()));
|
||||
}
|
||||
incorporate_update(&mut tuple, state_update);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user