From 8b51f5e45df64158e2b369e5c699a67e98f4c3a3 Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 30 Apr 2022 18:18:05 -0600 Subject: [PATCH] reorder function --- src/ship/items/actions.rs | 43 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) 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,