mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'sam/item-use-as-action' into 'master'
Item use is now goes through a control action rather than a control event. Closes #979 See merge request veloren/veloren!1839
This commit is contained in:
commit
f16c137635
@ -27,7 +27,7 @@ use common::{
|
||||
skills::Skill,
|
||||
slot::Slot,
|
||||
ChatMode, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip,
|
||||
InventoryManip, InventoryUpdateEvent, LoadoutManip,
|
||||
InventoryAction, InventoryEvent, InventoryUpdateEvent,
|
||||
},
|
||||
event::{EventBus, LocalEvent},
|
||||
grid::Grid,
|
||||
@ -621,24 +621,17 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn use_slot(&mut self, slot: Slot) {
|
||||
match 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)),
|
||||
)),
|
||||
}
|
||||
self.control_action(ControlAction::InventoryAction(InventoryAction::Use(slot)))
|
||||
}
|
||||
|
||||
pub fn swap_slots(&mut self, a: Slot, b: Slot) {
|
||||
match (a, b) {
|
||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Swap(equip, slot)))
|
||||
},
|
||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => self.control_action(
|
||||
ControlAction::InventoryAction(InventoryAction::Swap(equip, slot)),
|
||||
),
|
||||
(Slot::Inventory(inv1), Slot::Inventory(inv2)) => {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Swap(inv1, inv2),
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::Swap(inv1, inv2),
|
||||
)))
|
||||
},
|
||||
}
|
||||
@ -647,10 +640,10 @@ impl Client {
|
||||
pub fn drop_slot(&mut self, slot: Slot) {
|
||||
match slot {
|
||||
Slot::Equip(equip) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Drop(equip)))
|
||||
self.control_action(ControlAction::InventoryAction(InventoryAction::Drop(equip)))
|
||||
},
|
||||
Slot::Inventory(inv) => self.send_msg(ClientGeneral::ControlEvent(
|
||||
ControlEvent::InventoryManip(InventoryManip::Drop(inv)),
|
||||
ControlEvent::InventoryEvent(InventoryEvent::Drop(inv)),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -670,12 +663,12 @@ impl Client {
|
||||
|
||||
pub fn split_swap_slots(&mut self, a: comp::slot::Slot, b: comp::slot::Slot) {
|
||||
match (a, b) {
|
||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Swap(equip, slot)))
|
||||
},
|
||||
(Slot::Equip(equip), slot) | (slot, Slot::Equip(equip)) => self.control_action(
|
||||
ControlAction::InventoryAction(InventoryAction::Swap(equip, slot)),
|
||||
),
|
||||
(Slot::Inventory(inv1), Slot::Inventory(inv2)) => {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::SplitSwap(inv1, inv2),
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::SplitSwap(inv1, inv2),
|
||||
)))
|
||||
},
|
||||
}
|
||||
@ -684,10 +677,10 @@ impl Client {
|
||||
pub fn split_drop_slot(&mut self, slot: comp::slot::Slot) {
|
||||
match slot {
|
||||
Slot::Equip(equip) => {
|
||||
self.control_action(ControlAction::LoadoutManip(LoadoutManip::Drop(equip)))
|
||||
self.control_action(ControlAction::InventoryAction(InventoryAction::Drop(equip)))
|
||||
},
|
||||
Slot::Inventory(inv) => self.send_msg(ClientGeneral::ControlEvent(
|
||||
ControlEvent::InventoryManip(InventoryManip::SplitDrop(inv)),
|
||||
ControlEvent::InventoryEvent(InventoryEvent::SplitDrop(inv)),
|
||||
)),
|
||||
}
|
||||
}
|
||||
@ -701,8 +694,8 @@ impl Client {
|
||||
return;
|
||||
}
|
||||
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Pickup(uid),
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::Pickup(uid),
|
||||
)));
|
||||
}
|
||||
}
|
||||
@ -740,8 +733,8 @@ impl Client {
|
||||
|
||||
pub fn craft_recipe(&mut self, recipe: &str) -> bool {
|
||||
if self.can_craft_recipe(recipe) {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::CraftRecipe(recipe.to_string()),
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::CraftRecipe(recipe.to_string()),
|
||||
)));
|
||||
true
|
||||
} else {
|
||||
@ -1048,8 +1041,8 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn collect_block(&mut self, pos: Vec3<i32>) {
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryManip(
|
||||
InventoryManip::Collect(pos),
|
||||
self.send_msg(ClientGeneral::ControlEvent(ControlEvent::InventoryEvent(
|
||||
InventoryEvent::Collect(pos),
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,9 @@ use vek::*;
|
||||
pub const DEFAULT_HOLD_DURATION: Duration = Duration::from_millis(200);
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum InventoryManip {
|
||||
pub enum InventoryEvent {
|
||||
Pickup(Uid),
|
||||
Collect(Vec3<i32>),
|
||||
Use(InvSlotId),
|
||||
Swap(InvSlotId, InvSlotId),
|
||||
SplitSwap(InvSlotId, InvSlotId),
|
||||
Drop(InvSlotId),
|
||||
@ -30,14 +29,14 @@ pub enum InventoryManip {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum LoadoutManip {
|
||||
Use(EquipSlot),
|
||||
pub enum InventoryAction {
|
||||
Swap(EquipSlot, Slot),
|
||||
Drop(EquipSlot),
|
||||
Use(Slot),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum SlotManip {
|
||||
pub enum InventoryManip {
|
||||
Pickup(Uid),
|
||||
Collect(Vec3<i32>),
|
||||
Use(Slot),
|
||||
@ -48,31 +47,30 @@ pub enum SlotManip {
|
||||
CraftRecipe(String),
|
||||
}
|
||||
|
||||
impl From<LoadoutManip> for SlotManip {
|
||||
fn from(loadout_manip: LoadoutManip) -> Self {
|
||||
match loadout_manip {
|
||||
LoadoutManip::Use(equip) => Self::Use(Slot::Equip(equip)),
|
||||
LoadoutManip::Swap(equip, slot) => Self::Swap(Slot::Equip(equip), slot),
|
||||
LoadoutManip::Drop(equip) => Self::Drop(Slot::Equip(equip)),
|
||||
impl From<InventoryAction> for InventoryManip {
|
||||
fn from(inv_action: InventoryAction) -> Self {
|
||||
match inv_action {
|
||||
InventoryAction::Use(slot) => Self::Use(slot),
|
||||
InventoryAction::Swap(equip, slot) => Self::Swap(Slot::Equip(equip), slot),
|
||||
InventoryAction::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) => {
|
||||
impl From<InventoryEvent> for InventoryManip {
|
||||
fn from(inv_event: InventoryEvent) -> Self {
|
||||
match inv_event {
|
||||
InventoryEvent::Pickup(pickup) => Self::Pickup(pickup),
|
||||
InventoryEvent::Collect(collect) => Self::Collect(collect),
|
||||
InventoryEvent::Swap(inv1, inv2) => {
|
||||
Self::Swap(Slot::Inventory(inv1), Slot::Inventory(inv2))
|
||||
},
|
||||
InventoryManip::SplitSwap(inv1, inv2) => {
|
||||
InventoryEvent::SplitSwap(inv1, inv2) => {
|
||||
Self::SplitSwap(Slot::Inventory(inv1), Slot::Inventory(inv2))
|
||||
},
|
||||
InventoryManip::Drop(inv) => Self::Drop(Slot::Inventory(inv)),
|
||||
InventoryManip::SplitDrop(inv) => Self::SplitDrop(Slot::Inventory(inv)),
|
||||
InventoryManip::CraftRecipe(recipe) => Self::CraftRecipe(recipe),
|
||||
InventoryEvent::Drop(inv) => Self::Drop(Slot::Inventory(inv)),
|
||||
InventoryEvent::SplitDrop(inv) => Self::SplitDrop(Slot::Inventory(inv)),
|
||||
InventoryEvent::CraftRecipe(recipe) => Self::CraftRecipe(recipe),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,7 +93,7 @@ pub enum ControlEvent {
|
||||
PerformTradeAction(TradeId, TradeAction),
|
||||
Mount(Uid),
|
||||
Unmount,
|
||||
InventoryManip(InventoryManip),
|
||||
InventoryEvent(InventoryEvent),
|
||||
GroupManip(GroupManip),
|
||||
RemoveBuff(BuffKind),
|
||||
Respawn,
|
||||
@ -104,7 +102,7 @@ pub enum ControlEvent {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub enum ControlAction {
|
||||
SwapEquippedWeapons,
|
||||
LoadoutManip(LoadoutManip),
|
||||
InventoryAction(InventoryAction),
|
||||
Wield,
|
||||
GlideWield,
|
||||
Unwield,
|
||||
|
@ -62,7 +62,7 @@ pub use self::{
|
||||
combo::Combo,
|
||||
controller::{
|
||||
Climb, ControlAction, ControlEvent, Controller, ControllerInputs, GroupManip, Input,
|
||||
InventoryManip, LoadoutManip, MountState, Mounting, SlotManip,
|
||||
InventoryAction, InventoryEvent, InventoryManip, MountState, Mounting,
|
||||
},
|
||||
energy::{Energy, EnergyChange, EnergySource},
|
||||
group::Group,
|
||||
|
@ -54,7 +54,7 @@ pub enum ServerEvent {
|
||||
entity: EcsEntity,
|
||||
cause: comp::HealthSource,
|
||||
},
|
||||
InventoryManip(EcsEntity, comp::SlotManip),
|
||||
InventoryManip(EcsEntity, comp::InventoryManip),
|
||||
GroupManip(EcsEntity, comp::GroupManip),
|
||||
Respawn(EcsEntity),
|
||||
Shoot {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
comp::{
|
||||
item::MaterialStatManifest, Beam, Body, CharacterState, Combo, ControlAction, Controller,
|
||||
ControllerInputs, Energy, Health, Inventory, LoadoutManip, Melee, Ori, PhysicsState, Pos,
|
||||
StateUpdate, Stats, Vel,
|
||||
ControllerInputs, Energy, Health, Inventory, InventoryAction, Melee, Ori, PhysicsState,
|
||||
Pos, StateUpdate, Stats, Vel,
|
||||
},
|
||||
resources::DeltaTime,
|
||||
uid::Uid,
|
||||
@ -18,7 +18,7 @@ pub trait CharacterBehavior {
|
||||
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
||||
// Impl these to provide behavior for these inputs
|
||||
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
fn manipulate_loadout(&self, data: &JoinData, _loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, _inv_action: InventoryAction) -> StateUpdate {
|
||||
StateUpdate::from(data)
|
||||
}
|
||||
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
||||
@ -32,9 +32,7 @@ pub trait CharacterBehavior {
|
||||
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
||||
match event {
|
||||
ControlAction::SwapEquippedWeapons => self.swap_equipped_weapons(data),
|
||||
ControlAction::LoadoutManip(loadout_manip) => {
|
||||
self.manipulate_loadout(data, loadout_manip)
|
||||
},
|
||||
ControlAction::InventoryAction(inv_action) => self.manipulate_loadout(data, inv_action),
|
||||
ControlAction::Wield => self.wield(data),
|
||||
ControlAction::GlideWield => self.glide_wield(data),
|
||||
ControlAction::Unwield => self.unwield(data),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{CharacterState, LoadoutManip, StateUpdate},
|
||||
comp::{CharacterState, InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -42,9 +42,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{slot::EquipSlot, CharacterState, EnergySource, LoadoutManip, StateUpdate},
|
||||
comp::{slot::EquipSlot, CharacterState, EnergySource, InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
|
||||
@ -69,9 +69,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{LoadoutManip, StateUpdate},
|
||||
comp::{InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
|
||||
@ -61,9 +61,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{CharacterState, LoadoutManip, StateUpdate},
|
||||
comp::{CharacterState, InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -42,9 +42,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{CharacterState, LoadoutManip, StateUpdate},
|
||||
comp::{CharacterState, InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
|
||||
@ -60,9 +60,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::utils::*;
|
||||
use crate::{
|
||||
comp::{CharacterState, LoadoutManip, StateUpdate},
|
||||
comp::{CharacterState, InventoryAction, StateUpdate},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -47,9 +47,9 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
item::{Hands, ItemKind, Tool, ToolKind},
|
||||
quadruped_low, quadruped_medium, quadruped_small,
|
||||
skills::Skill,
|
||||
theropod, Body, CharacterAbility, CharacterState, LoadoutManip, StateUpdate,
|
||||
theropod, Body, CharacterAbility, CharacterState, InventoryAction, StateUpdate,
|
||||
},
|
||||
consts::{FRIC_GROUND, GRAVITY},
|
||||
event::{LocalEvent, ServerEvent},
|
||||
@ -395,12 +395,11 @@ pub fn attempt_swap_equipped_weapons(data: &JoinData, update: &mut StateUpdate)
|
||||
pub fn handle_manipulate_loadout(
|
||||
data: &JoinData,
|
||||
update: &mut StateUpdate,
|
||||
loadout_manip: LoadoutManip,
|
||||
inv_action: InventoryAction,
|
||||
) {
|
||||
update.server_events.push_front(ServerEvent::InventoryManip(
|
||||
data.entity,
|
||||
loadout_manip.into(),
|
||||
));
|
||||
update
|
||||
.server_events
|
||||
.push_front(ServerEvent::InventoryManip(data.entity, inv_action.into()));
|
||||
}
|
||||
|
||||
/// Checks that player can wield the glider and updates `CharacterState` if so
|
||||
|
@ -2,7 +2,7 @@ use super::utils::*;
|
||||
use crate::{
|
||||
comp::{
|
||||
slot::{EquipSlot, Slot},
|
||||
CharacterState, LoadoutManip, StateUpdate,
|
||||
CharacterState, InventoryAction, StateUpdate,
|
||||
},
|
||||
states::behavior::{CharacterBehavior, JoinData},
|
||||
};
|
||||
@ -61,17 +61,17 @@ impl CharacterBehavior for Data {
|
||||
update
|
||||
}
|
||||
|
||||
fn manipulate_loadout(&self, data: &JoinData, loadout_manip: LoadoutManip) -> StateUpdate {
|
||||
fn manipulate_loadout(&self, data: &JoinData, inv_action: InventoryAction) -> StateUpdate {
|
||||
let mut update = StateUpdate::from(data);
|
||||
match loadout_manip {
|
||||
LoadoutManip::Drop(EquipSlot::Mainhand)
|
||||
| LoadoutManip::Swap(EquipSlot::Mainhand, _)
|
||||
| LoadoutManip::Swap(_, Slot::Equip(EquipSlot::Mainhand)) => {
|
||||
match inv_action {
|
||||
InventoryAction::Drop(EquipSlot::Mainhand)
|
||||
| InventoryAction::Swap(EquipSlot::Mainhand, _)
|
||||
| InventoryAction::Swap(_, Slot::Equip(EquipSlot::Mainhand)) => {
|
||||
update.character = CharacterState::Idle;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
handle_manipulate_loadout(&data, &mut update, loadout_manip);
|
||||
handle_manipulate_loadout(&data, &mut update, inv_action);
|
||||
update
|
||||
}
|
||||
}
|
||||
|
@ -93,8 +93,8 @@ impl<'a> System<'a> for Sys {
|
||||
server_emitter
|
||||
.emit(ServerEvent::ProcessTradeAction(entity, trade_id, action));
|
||||
},
|
||||
ControlEvent::InventoryManip(manip) => {
|
||||
server_emitter.emit(ServerEvent::InventoryManip(entity, manip.into()));
|
||||
ControlEvent::InventoryEvent(event) => {
|
||||
server_emitter.emit(ServerEvent::InventoryManip(entity, event.into()));
|
||||
},
|
||||
ControlEvent::GroupManip(manip) => {
|
||||
server_emitter.emit(ServerEvent::GroupManip(entity, manip))
|
||||
|
@ -39,7 +39,7 @@ pub fn snuff_lantern(storage: &mut WriteStorage<comp::LightEmitter>, entity: Ecs
|
||||
|
||||
#[allow(clippy::blocks_in_if_conditions)]
|
||||
#[allow(clippy::same_item_push)] // TODO: Pending review in #587
|
||||
pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::SlotManip) {
|
||||
pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::InventoryManip) {
|
||||
let state = server.state_mut();
|
||||
|
||||
let uid = state
|
||||
@ -76,7 +76,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
};
|
||||
|
||||
match manip {
|
||||
comp::SlotManip::Pickup(uid) => {
|
||||
comp::InventoryManip::Pickup(uid) => {
|
||||
let picked_up_item: Option<comp::Item>;
|
||||
let item_entity = if let (Some((item, item_entity)), Some(mut inv)) = (
|
||||
state
|
||||
@ -148,8 +148,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
|
||||
state.write_component(entity, event);
|
||||
},
|
||||
|
||||
comp::SlotManip::Collect(pos) => {
|
||||
comp::InventoryManip::Collect(pos) => {
|
||||
let block = state.terrain().get(pos).ok().copied();
|
||||
|
||||
if let Some(block) = block {
|
||||
@ -219,8 +218,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
comp::SlotManip::Use(slot) => {
|
||||
comp::InventoryManip::Use(slot) => {
|
||||
let mut inventories = state.ecs().write_storage::<comp::Inventory>();
|
||||
let mut inventory = if let Some(inventory) = inventories.get_mut(entity) {
|
||||
inventory
|
||||
@ -423,8 +421,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
state.write_component(entity, comp::InventoryUpdate::new(event));
|
||||
}
|
||||
},
|
||||
|
||||
comp::SlotManip::Swap(a, b) => {
|
||||
comp::InventoryManip::Swap(a, b) => {
|
||||
let ecs = state.ecs();
|
||||
|
||||
if let Some(pos) = ecs.read_storage::<comp::Pos>().get(entity) {
|
||||
@ -458,8 +455,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Swapped),
|
||||
);
|
||||
},
|
||||
|
||||
comp::SlotManip::SplitSwap(slot, target) => {
|
||||
comp::InventoryManip::SplitSwap(slot, target) => {
|
||||
let msm = state.ecs().read_resource::<MaterialStatManifest>();
|
||||
let mut inventories = state.ecs().write_storage::<comp::Inventory>();
|
||||
let mut inventory = if let Some(inventory) = inventories.get_mut(entity) {
|
||||
@ -507,8 +503,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Swapped),
|
||||
);
|
||||
},
|
||||
|
||||
comp::SlotManip::Drop(slot) => {
|
||||
comp::InventoryManip::Drop(slot) => {
|
||||
let item = match slot {
|
||||
Slot::Inventory(slot) => state
|
||||
.ecs()
|
||||
@ -540,8 +535,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Dropped),
|
||||
);
|
||||
},
|
||||
|
||||
comp::SlotManip::SplitDrop(slot) => {
|
||||
comp::InventoryManip::SplitDrop(slot) => {
|
||||
let msm = state.ecs().read_resource::<MaterialStatManifest>();
|
||||
let item = match slot {
|
||||
Slot::Inventory(slot) => state
|
||||
@ -571,8 +565,7 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Slo
|
||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Dropped),
|
||||
);
|
||||
},
|
||||
|
||||
comp::SlotManip::CraftRecipe(recipe) => {
|
||||
comp::InventoryManip::CraftRecipe(recipe) => {
|
||||
if let Some(mut inv) = state
|
||||
.ecs()
|
||||
.write_storage::<comp::Inventory>()
|
||||
|
Loading…
Reference in New Issue
Block a user