Browse Source

simplify the return type of item tasks

pull/124/head
jake 2 years ago
parent
commit
38070c9dfd
  1. 70
      src/ship/items/actions.rs

70
src/ship/items/actions.rs

@ -18,6 +18,8 @@ use crate::entity::item::ItemModifier;
use crate::ship::shops::ShopItem;
use crate::ship::drops::{ItemDrop, ItemDropType};
type BoxFuture<T> = Pin<Box<dyn Future<Output=T> + Send>>;
pub enum TriggerCreateItem {
Yes,
No
@ -27,7 +29,7 @@ pub(super) fn take_item_from_floor<EG, TR>(
character_id: CharacterEntityId,
item_id: ClientItemId
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
where
EG: EntityGateway + Send,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -46,7 +48,7 @@ where
pub(super) fn add_floor_item_to_inventory<EG, TR>(
character: &CharacterEntity
) -> impl Fn((ItemStateProxy, TR), FloorItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), TriggerCreateItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), TriggerCreateItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + Clone + 'static,
@ -96,7 +98,7 @@ pub(super) fn take_item_from_inventory<EG, TR>(
item_id: ClientItemId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -120,7 +122,7 @@ pub(super) fn add_inventory_item_to_shared_floor<EG, TR>(
map_area: MapArea,
drop_position: (f32, f32, f32),
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -153,7 +155,7 @@ pub(super) fn take_meseta_from_inventory<EG, TR>(
character_id: CharacterEntityId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -174,7 +176,7 @@ pub(super) fn add_meseta_to_inventory<EG, TR>(
character_id: CharacterEntityId,
amount: u32
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -197,7 +199,7 @@ pub(super) fn add_meseta_to_shared_floor<EG, TR>(
map_area: MapArea,
drop_position: (f32, f32)
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -226,7 +228,7 @@ pub(super) fn take_meseta_from_bank<EG, TR>(
character_id: CharacterEntityId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -246,7 +248,7 @@ pub(super) fn add_meseta_from_bank_to_inventory<EG, TR>(
character_id: CharacterEntityId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -267,7 +269,7 @@ pub(super) fn add_meseta_to_bank<EG, TR>(
character_id: CharacterEntityId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -289,7 +291,7 @@ pub(super) fn take_item_from_bank<EG, TR>(
item_id: ClientItemId,
amount: u32,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), BankItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), BankItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -309,7 +311,7 @@ where
pub(super) fn add_bank_item_to_inventory<EG, TR>(
character: &CharacterEntity,
) -> impl Fn((ItemStateProxy, TR), BankItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -360,7 +362,7 @@ where
pub(super) fn add_inventory_item_to_bank<EG, TR>(
character_id: CharacterEntityId,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -396,7 +398,7 @@ pub(super) fn equip_inventory_item<EG, TR>(
item_id: ClientItemId,
equip_slot: u8,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -418,7 +420,7 @@ pub(super) fn unequip_inventory_item<EG, TR>(
character_id: CharacterEntityId,
item_id: ClientItemId,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -441,7 +443,7 @@ pub(super) fn sort_inventory_items<EG, TR>(
character_id: CharacterEntityId,
item_ids: Vec<ClientItemId>,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), ()), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), ()), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -463,7 +465,7 @@ where
pub(super) fn use_consumed_item<EG, TR>(
character: CharacterEntity,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), Vec<ApplyItemAction>), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<ApplyItemAction>), ItemStateError>>
where
EG: EntityGateway + Clone + 'static,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -489,7 +491,7 @@ pub(super) fn feed_mag_item<EG, TR>(
character: CharacterEntity,
mag_item_id: ClientItemId,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), CharacterEntity), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), CharacterEntity), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -605,7 +607,7 @@ where
pub(super) fn sell_inventory_item<EG, TR>(
character_id: CharacterEntityId,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -645,7 +647,7 @@ where
T: Clone + Send + Sync,
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
FR: Fn((ItemStateProxy, TR), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), O), ItemStateError>> + Send>> + Send + Sync,
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
{
let item = match input.pop() {
Some(item) => item,
@ -661,11 +663,11 @@ where
Ok((state, output))
}
pub(super) fn iterate<'k, EG, TR, I, O, T, F, FR>(
pub(super) fn iterate<EG, TR, I, O, T, F, FR>(
input: Vec<I>,
func: F,
) -> impl Fn((ItemStateProxy, TR), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -674,7 +676,7 @@ where
T: Send + Clone + 'static + std::fmt::Debug,
F: Fn(I) -> FR + Send + Sync + Clone + 'static,
FR: Fn((ItemStateProxy, TR), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), O), ItemStateError>> + Send>> + Send + Sync,
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
T: Clone + Send + Sync,
{
move |(item_state, transaction), arg| {
@ -701,7 +703,7 @@ where
O: Send,
T: Clone + Send,
F: Fn((ItemStateProxy, TR), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), O), ItemStateError>> + Send>> + Send + Sync,
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync,
F: Clone,
{
let item = match input.pop() {
@ -717,17 +719,17 @@ where
Ok((state, output))
}
pub(super) fn foreach<'k, EG, TR, O, T, F>(
pub(super) fn foreach<EG, TR, O, T, F>(
func: F
) -> impl Fn((ItemStateProxy, TR), Vec<T>)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<O>), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
O: Send,
T: Send + Clone + 'static + std::fmt::Debug,
F: Fn((ItemStateProxy, TR), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), O), ItemStateError>> + Send>> + Send + Sync + 'static,
-> BoxFuture<Result<((ItemStateProxy, TR), O), ItemStateError>> + Send + Sync + 'static,
F: Clone,
T: Clone + Send + Sync,
{
@ -760,7 +762,7 @@ where
pub(super) fn add_item_to_inventory<EG, TR>(
character: CharacterEntity,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>> + Clone
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Clone
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -790,7 +792,7 @@ pub(super) fn record_trade<EG, TR>(
character_to: CharacterEntityId,
character_from: CharacterEntityId,
) -> impl Fn((ItemStateProxy, TR), Vec<InventoryItem>)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), Vec<InventoryItem>), ItemStateError>> + Send>> + Clone
-> BoxFuture<Result<((ItemStateProxy, TR), Vec<InventoryItem>), ItemStateError>> + Clone
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -816,7 +818,7 @@ where
pub(super) fn assign_new_item_id<EG, TR>(
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>> + Clone
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Clone
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -834,7 +836,7 @@ pub(super) fn convert_item_drop_to_floor_item<EG, TR>(
character_id: CharacterEntityId,
item_drop: ItemDrop,
) -> impl Fn((ItemStateProxy, TR), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Send>> + Clone
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Clone
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -935,7 +937,7 @@ where
pub(super) fn add_item_to_local_floor<EG, TR>(
character_id: CharacterEntityId,
) -> impl Fn((ItemStateProxy, TR), FloorItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), FloorItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), FloorItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -954,7 +956,7 @@ where
pub(super) fn apply_modifier_to_inventory_item<EG, TR>(
modifier: ItemModifier,
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), InventoryItem), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,
@ -977,7 +979,7 @@ where
pub(super) fn as_individual_item<EG, TR>(
) -> impl Fn((ItemStateProxy, TR), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, TR), IndividualItemDetail), ItemStateError>> + Send>>
-> BoxFuture<Result<((ItemStateProxy, TR), IndividualItemDetail), ItemStateError>>
where
EG: EntityGateway,
TR: EntityGatewayTransaction<ParentGateway = EG> + 'static,

Loading…
Cancel
Save