mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Inventory manipulations are now only for input from the client, and are no longer directly sent as a server event. Slot manipulations do that instead.
This commit is contained in:
parent
1c83c5ee6f
commit
e033fe6bee
@ -600,9 +600,14 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn use_slot(&mut self, slot: Slot) {
|
pub fn use_slot(&mut self, slot: Slot) {
|
||||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
match slot {
|
||||||
InventoryManip::Use(slot),
|
Slot::Equip(equip) => {
|
||||||
)));
|
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Use(equip)))
|
||||||
|
},
|
||||||
|
Slot::Inventory(inv) => self.send_msg(ClientGeneral::ControlEvent(
|
||||||
|
ControlEvent::InventoryManip(InventoryManip::Use(inv)),
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swap_slots(&mut self, a: Slot, b: Slot) {
|
pub fn swap_slots(&mut self, a: Slot, b: Slot) {
|
||||||
@ -610,9 +615,11 @@ impl Client {
|
|||||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => {
|
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => {
|
||||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Swap(equip, slot)))
|
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Swap(equip, slot)))
|
||||||
},
|
},
|
||||||
_ => self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
(Slot::Inventory(inv1), Slot::Inventory(inv2)) => {
|
||||||
InventoryManip::Swap(a, b),
|
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||||
))),
|
InventoryManip::Swap(inv1, inv2),
|
||||||
|
)))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,9 +628,9 @@ impl Client {
|
|||||||
Slot::Equip(equip) => {
|
Slot::Equip(equip) => {
|
||||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Drop(equip)))
|
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Drop(equip)))
|
||||||
},
|
},
|
||||||
_ => self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
Slot::Inventory(inv) => self.send_msg(ClientGeneral::ControlEvent(
|
||||||
InventoryManip::Drop(slot),
|
ControlEvent::InventoryManip(InventoryManip::Drop(inv)),
|
||||||
))),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{
|
comp::{
|
||||||
inventory::slot::{EquipSlot, Slot},
|
inventory::slot::{EquipSlot, InvSlotId, Slot},
|
||||||
BuffKind,
|
BuffKind,
|
||||||
},
|
},
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
@ -17,6 +17,23 @@ pub const DEFAULT_HOLD_DURATION: Duration = Duration::from_millis(200);
|
|||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum InventoryManip {
|
pub enum InventoryManip {
|
||||||
|
Pickup(Uid),
|
||||||
|
Collect(Vec3<i32>),
|
||||||
|
Use(InvSlotId),
|
||||||
|
Swap(InvSlotId, InvSlotId),
|
||||||
|
Drop(InvSlotId),
|
||||||
|
CraftRecipe(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum LoadoutManip {
|
||||||
|
Use(EquipSlot),
|
||||||
|
Swap(EquipSlot, Slot),
|
||||||
|
Drop(EquipSlot),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum SlotManip {
|
||||||
Pickup(Uid),
|
Pickup(Uid),
|
||||||
Collect(Vec3<i32>),
|
Collect(Vec3<i32>),
|
||||||
Use(Slot),
|
Use(Slot),
|
||||||
@ -25,21 +42,31 @@ pub enum InventoryManip {
|
|||||||
CraftRecipe(String),
|
CraftRecipe(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
impl From<LoadoutManip> for SlotManip {
|
||||||
pub enum LoadoutManip {
|
|
||||||
Swap(EquipSlot, Slot),
|
|
||||||
Drop(EquipSlot),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<LoadoutManip> for InventoryManip {
|
|
||||||
fn from(loadout_manip: LoadoutManip) -> Self {
|
fn from(loadout_manip: LoadoutManip) -> Self {
|
||||||
match loadout_manip {
|
match loadout_manip {
|
||||||
|
LoadoutManip::Use(equip) => Self::Use(Slot::Equip(equip)),
|
||||||
LoadoutManip::Swap(equip, slot) => Self::Swap(Slot::Equip(equip), slot),
|
LoadoutManip::Swap(equip, slot) => Self::Swap(Slot::Equip(equip), slot),
|
||||||
LoadoutManip::Drop(equip) => Self::Drop(Slot::Equip(equip)),
|
LoadoutManip::Drop(equip) => Self::Drop(Slot::Equip(equip)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<InventoryManip> for SlotManip {
|
||||||
|
fn from(inv_manip: InventoryManip) -> Self {
|
||||||
|
match inv_manip {
|
||||||
|
InventoryManip::Pickup(pickup) => Self::Pickup(pickup),
|
||||||
|
InventoryManip::Collect(collect) => Self::Collect(collect),
|
||||||
|
InventoryManip::Use(inv) => Self::Use(Slot::Inventory(inv)),
|
||||||
|
InventoryManip::Swap(inv1, inv2) => {
|
||||||
|
Self::Swap(Slot::Inventory(inv1), Slot::Inventory(inv2))
|
||||||
|
},
|
||||||
|
InventoryManip::Drop(inv) => Self::Drop(Slot::Inventory(inv)),
|
||||||
|
InventoryManip::CraftRecipe(recipe) => Self::CraftRecipe(recipe),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum GroupManip {
|
pub enum GroupManip {
|
||||||
Invite(Uid),
|
Invite(Uid),
|
||||||
|
@ -46,7 +46,7 @@ pub use chat::{
|
|||||||
};
|
};
|
||||||
pub use controller::{
|
pub use controller::{
|
||||||
Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, Input,
|
Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, Input,
|
||||||
InventoryManip, LoadoutManip, MountState, Mounting,
|
InventoryManip, LoadoutManip, MountState, Mounting, SlotManip,
|
||||||
};
|
};
|
||||||
pub use energy::{Energy, EnergyChange, EnergySource};
|
pub use energy::{Energy, EnergyChange, EnergySource};
|
||||||
pub use group::Group;
|
pub use group::Group;
|
||||||
|
@ -46,7 +46,7 @@ pub enum ServerEvent {
|
|||||||
entity: EcsEntity,
|
entity: EcsEntity,
|
||||||
cause: comp::HealthSource,
|
cause: comp::HealthSource,
|
||||||
},
|
},
|
||||||
InventoryManip(EcsEntity, comp::InventoryManip),
|
InventoryManip(EcsEntity, comp::SlotManip),
|
||||||
GroupManip(EcsEntity, comp::GroupManip),
|
GroupManip(EcsEntity, comp::GroupManip),
|
||||||
Respawn(EcsEntity),
|
Respawn(EcsEntity),
|
||||||
Shoot {
|
Shoot {
|
||||||
|
@ -99,7 +99,7 @@ impl<'a> System<'a> for Sys {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ControlEvent::InventoryManip(manip) => {
|
ControlEvent::InventoryManip(manip) => {
|
||||||
server_emitter.emit(ServerEvent::InventoryManip(entity, manip));
|
server_emitter.emit(ServerEvent::InventoryManip(entity, manip.into()));
|
||||||
},
|
},
|
||||||
ControlEvent::GroupManip(manip) => {
|
ControlEvent::GroupManip(manip) => {
|
||||||
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
||||||
|
@ -37,7 +37,7 @@ pub fn snuff_lantern(storage: &mut WriteStorage<comp::LightEmitter>, entity: Ecs
|
|||||||
|
|
||||||
#[allow(clippy::blocks_in_if_conditions)]
|
#[allow(clippy::blocks_in_if_conditions)]
|
||||||
#[allow(clippy::same_item_push)] // TODO: Pending review in #587
|
#[allow(clippy::same_item_push)] // TODO: Pending review in #587
|
||||||
pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::InventoryManip) {
|
pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::SlotManip) {
|
||||||
let state = server.state_mut();
|
let state = server.state_mut();
|
||||||
let mut dropped_items = Vec::new();
|
let mut dropped_items = Vec::new();
|
||||||
let mut thrown_items = Vec::new();
|
let mut thrown_items = Vec::new();
|
||||||
@ -60,7 +60,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
};
|
};
|
||||||
|
|
||||||
match manip {
|
match manip {
|
||||||
comp::InventoryManip::Pickup(uid) => {
|
comp::SlotManip::Pickup(uid) => {
|
||||||
let picked_up_item: Option<comp::Item>;
|
let picked_up_item: Option<comp::Item>;
|
||||||
let item_entity = if let (Some((item, item_entity)), Some(mut inv)) = (
|
let item_entity = if let (Some((item, item_entity)), Some(mut inv)) = (
|
||||||
state
|
state
|
||||||
@ -133,7 +133,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
state.write_component(entity, event);
|
state.write_component(entity, event);
|
||||||
},
|
},
|
||||||
|
|
||||||
comp::InventoryManip::Collect(pos) => {
|
comp::SlotManip::Collect(pos) => {
|
||||||
let block = state.terrain().get(pos).ok().copied();
|
let block = state.terrain().get(pos).ok().copied();
|
||||||
|
|
||||||
if let Some(block) = block {
|
if let Some(block) = block {
|
||||||
@ -204,7 +204,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
comp::InventoryManip::Use(slot) => {
|
comp::SlotManip::Use(slot) => {
|
||||||
let mut inventories = state.ecs().write_storage::<comp::Inventory>();
|
let mut inventories = state.ecs().write_storage::<comp::Inventory>();
|
||||||
let mut inventory = if let Some(inventory) = inventories.get_mut(entity) {
|
let mut inventory = if let Some(inventory) = inventories.get_mut(entity) {
|
||||||
inventory
|
inventory
|
||||||
@ -405,7 +405,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
comp::InventoryManip::Swap(a, b) => {
|
comp::SlotManip::Swap(a, b) => {
|
||||||
let ecs = state.ecs();
|
let ecs = state.ecs();
|
||||||
|
|
||||||
if let Some(pos) = ecs.read_storage::<comp::Pos>().get(entity) {
|
if let Some(pos) = ecs.read_storage::<comp::Pos>().get(entity) {
|
||||||
@ -429,7 +429,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
comp::InventoryManip::Drop(slot) => {
|
comp::SlotManip::Drop(slot) => {
|
||||||
let item = match slot {
|
let item = match slot {
|
||||||
Slot::Inventory(slot) => state
|
Slot::Inventory(slot) => state
|
||||||
.ecs()
|
.ecs()
|
||||||
@ -462,7 +462,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
comp::InventoryManip::CraftRecipe(recipe) => {
|
comp::SlotManip::CraftRecipe(recipe) => {
|
||||||
if let Some(mut inv) = state
|
if let Some(mut inv) = state
|
||||||
.ecs()
|
.ecs()
|
||||||
.write_storage::<comp::Inventory>()
|
.write_storage::<comp::Inventory>()
|
||||||
|
Loading…
Reference in New Issue
Block a user