Browse Source

reorder function

pull/112/head
jake 3 years ago
committed by andy
parent
commit
bd6b8effcd
  1. 43
      src/ship/items/actions.rs

43
src/ship/items/actions.rs

@ -73,6 +73,27 @@ fn add_floor_item_to_inventory(character: &CharacterEntity)
} }
pub async fn pick_up_item<EG>(
item_state: &mut ItemState,
entity_gateway: &mut EG,
character: &CharacterEntity,
item_id: &ClientItemId)
-> Result<TriggerCreateItem, ItemStateError>
where
EG: EntityGateway,
{
entity_gateway.with_transaction(|transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), result) = ItemStateAction::default()
.act(take_item_from_floor(character.id, *item_id))
.act(add_floor_item_to_inventory(character))
.commit((item_state_proxy, transaction))
.await?;
item_state_proxy.commit();
Ok((transaction, result))
}).await
}
fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItemId) fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItemId)
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()) -> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>> -> Pin<Box<dyn Future<Output=Result<((ItemStateProxy, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
@ -119,28 +140,6 @@ fn add_inventory_item_to_shared_floor(character_id: CharacterEntityId, item_id:
} }
} }
pub async fn pick_up_item<EG>(
item_state: &mut ItemState,
entity_gateway: &mut EG,
character: &CharacterEntity,
item_id: &ClientItemId)
-> Result<TriggerCreateItem, ItemStateError>
where
EG: EntityGateway,
{
entity_gateway.with_transaction(|transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), result) = ItemStateAction::default()
.act(take_item_from_floor(character.id, *item_id))
.act(add_floor_item_to_inventory(character))
.commit((item_state_proxy, transaction))
.await?;
item_state_proxy.commit();
Ok((transaction, result))
}).await
}
pub async fn drop_item<EG>( pub async fn drop_item<EG>(
item_state: &mut ItemState, item_state: &mut ItemState,
entity_gateway: &mut EG, entity_gateway: &mut EG,

Loading…
Cancel
Save