diff --git a/src/ship/items/actions.rs b/src/ship/items/actions.rs index 124b626..c8eb0d1 100644 --- a/src/ship/items/actions.rs +++ b/src/ship/items/actions.rs @@ -73,6 +73,27 @@ fn add_floor_item_to_inventory(character: &CharacterEntity) } +pub async fn pick_up_item( + item_state: &mut ItemState, + entity_gateway: &mut EG, + character: &CharacterEntity, + item_id: &ClientItemId) + -> Result +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) -> impl for<'a> Fn((ItemStateProxy<'a>, Box), ()) -> Pin), 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( - item_state: &mut ItemState, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_id: &ClientItemId) - -> Result -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( item_state: &mut ItemState, entity_gateway: &mut EG,