mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added inventory sync messages and InventoryUpdate component
This commit is contained in:
parent
a7fc872f1c
commit
5bb7998d5a
@ -421,6 +421,9 @@ impl Client {
|
||||
self.state.write_component(entity, action_state);
|
||||
}
|
||||
}
|
||||
ServerMsg::InventoryUpdate(inventory) => {
|
||||
self.state.write_component(self.entity, inventory)
|
||||
}
|
||||
ServerMsg::TerrainChunkUpdate { key, chunk } => {
|
||||
self.state.insert_chunk(key, *chunk);
|
||||
self.pending_chunks.remove(&key);
|
||||
|
@ -4,7 +4,7 @@ pub mod item;
|
||||
// Reexports
|
||||
pub use self::item::Item;
|
||||
|
||||
use specs::{Component, HashMapStorage};
|
||||
use specs::{Component, NullStorage, HashMapStorage};
|
||||
use specs_idvs::IDVStorage;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
@ -41,3 +41,11 @@ impl Default for Inventory {
|
||||
impl Component for Inventory {
|
||||
type Storage = HashMapStorage<Self>;
|
||||
}
|
||||
|
||||
// ForceUpdate
|
||||
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct InventoryUpdate;
|
||||
|
||||
impl Component for InventoryUpdate {
|
||||
type Storage = NullStorage<Self>;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub use controller::Controller;
|
||||
pub use inputs::{
|
||||
Attacking, CanBuild, Gliding, Jumping, MoveDir, OnGround, Respawning, Rolling, Wielding,
|
||||
};
|
||||
pub use inventory::{item, Inventory};
|
||||
pub use inventory::{item, Inventory, InventoryUpdate};
|
||||
pub use last::Last;
|
||||
pub use phys::{ForceUpdate, Ori, Pos, Vel};
|
||||
pub use player::Player;
|
||||
|
@ -55,6 +55,7 @@ pub enum ServerMsg {
|
||||
entity: u64,
|
||||
action_state: comp::ActionState,
|
||||
},
|
||||
InventoryUpdate(comp::Inventory),
|
||||
TerrainChunkUpdate {
|
||||
key: Vec2<i32>,
|
||||
chunk: Box<TerrainChunk>,
|
||||
|
@ -142,6 +142,7 @@ impl State {
|
||||
ecs.register::<comp::Pos>();
|
||||
ecs.register::<comp::Vel>();
|
||||
ecs.register::<comp::Ori>();
|
||||
ecs.register::<comp::Inventory>();
|
||||
|
||||
// Register client-local components
|
||||
ecs.register::<comp::AnimationInfo>();
|
||||
@ -156,6 +157,7 @@ impl State {
|
||||
ecs.register::<comp::Respawning>();
|
||||
ecs.register::<comp::Dying>();
|
||||
ecs.register::<comp::ForceUpdate>();
|
||||
ecs.register::<comp::InventoryUpdate>();
|
||||
ecs.register::<comp::Inventory>();
|
||||
// Controller effects
|
||||
ecs.register::<comp::MoveDir>();
|
||||
|
@ -191,6 +191,7 @@ impl Server {
|
||||
state.write_component(entity, comp::Vel(Vec3::zero()));
|
||||
state.write_component(entity, comp::Ori(Vec3::unit_y()));
|
||||
state.write_component(entity, comp::ActionState::default());
|
||||
state.write_component(entity, comp::Inventory::default());
|
||||
// Make sure physics are accepted.
|
||||
state.write_component(entity, comp::ForceUpdate);
|
||||
|
||||
@ -919,11 +920,27 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync inventories
|
||||
for (entity, inventory, _) in (
|
||||
&self.state.ecs().entities(),
|
||||
&self.state.ecs().read_storage::<comp::Inventory>(),
|
||||
&self.state.ecs().read_storage::<comp::InventoryUpdate>(),
|
||||
)
|
||||
.join()
|
||||
{
|
||||
self.clients
|
||||
.notify(entity, ServerMsg::InventoryUpdate(inventory.clone()));
|
||||
}
|
||||
|
||||
// Remove all force flags.
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.write_storage::<comp::ForceUpdate>()
|
||||
.clear();
|
||||
self.state
|
||||
.ecs_mut()
|
||||
.write_storage::<comp::InventoryUpdate>()
|
||||
.clear();
|
||||
}
|
||||
|
||||
pub fn generate_chunk(&mut self, key: Vec2<i32>) {
|
||||
|
Loading…
Reference in New Issue
Block a user