From 7aa4a6394fcbc66f4c390cfe1bfcd4847721dd66 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 20 Apr 2022 18:35:44 -0600 Subject: [PATCH] cleanup --- src/ship/items/state.rs | 103 +++------------------------------------- 1 file changed, 6 insertions(+), 97 deletions(-) diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index 6f1c550..d5a46f5 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -44,20 +44,6 @@ enum ItemStateError { GatewayError(#[from] GatewayError), } -enum GatewayActions { - ItemNote(ItemEntityId, ItemNote), -} - -/* -enum ItemStateChange { - Inventory(CharacterInventory), - Bank(CharacterBank), - CharacterMeseta(CharacterMeseta), - BankMeseta(BankMeseta), - SharedFloor(SharedFloor), - LocalFloor(LocalFloor), -} -*/ #[async_trait::async_trait] trait ItemAction { @@ -102,7 +88,6 @@ where _e: std::marker::PhantomData, prev: self, actionf: f, - //actionf: |s, t| f(s, ()), } } } @@ -110,7 +95,6 @@ where struct ItemActionStage where P: ItemAction, - //F: Fn(&mut S, P::Output) -> Result + for<'r> std::ops::Fn<(&'r mut S, T)>, F: Fn(S, P::Output) -> Pin> + Send>> + Send + Sync, { _s: std::marker::PhantomData, @@ -632,13 +616,9 @@ fn add_floor_item_to_inventory(character_id: CharacterEntityId) } -//hint R>(f: F) -> F {f} - - #[fix_hidden_lifetime_bug] async fn pick_up_item<'a, EG>( item_state: &'a mut ItemState, - //item_state: Arc>, entity_gateway: &'a mut EG, character_id: &CharacterEntityId, item_id: &ClientItemId) @@ -647,87 +627,16 @@ where 'a: 'static, EG: EntityGateway, { - /* - let transaction = entity_gateway.transaction().await.unwrap(); - - let item_state_proxy = ItemStateProxy::new(item_state, transaction); - let (mut item_state_proxy, result) = ItemStateAction::default() - .act(take_item_from_floor(*character_id, *item_id)) - .act(add_floor_item_to_inventory(*character_id)) - .commit(item_state_proxy) - .await?; - item_state_proxy.transaction.commit().await.unwrap(); - */ - - //drop(item_state_proxy); - //transaction.commit().await.unwrap(); - //item_state_proxy.entity_gateway.commit().await.unwrap(); - - let k: Result = entity_gateway.with_transaction(|transaction| async move { - let item_state_proxy = ItemStateProxy::new(item_state, transaction); - let (item_state_proxy, result) = ItemStateAction::default() + let result: Result = 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_id)) - .commit(item_state_proxy) + .commit((item_state_proxy, transaction)) .await?; - - //let u = transaction.get_user_by_id(crate::entity::account::UserAccountId(0)).await?; - //Ok((transaction, ())) - //drop(item_state_proxy); - Ok((item_state_proxy.transaction, result)) + Ok((transaction, result)) }).await; - - /* - //fn subaction(transaction: &mut dyn EntityGateway) -> Pin> + Send + 'static>> { - async fn subaction(transaction: &mut dyn EntityGateway) -> Result<(), GatewayError> { - let item_state_proxy = ItemStateProxy::new(item_state, transaction); - - Ok(()) - } - - //async fn action(item_state: &mut ItemState, entity_gateway: &mut EG) -> Result<(), GatewayError> { - fn action(item_state: &mut ItemState) - -> impl FnOnce(&mut dyn EntityGateway) -> Pin> + Send + 'static>> - { - /* - |transaction| Box::pin(async move { - Ok(()) - }) - */ - subaction - } - */ - - //let k: Result<(), GatewayError> = entity_gateway.with_transaction(action(item_state)).await; - - //let item_state = item_state.clone(); - /* - let k: Result<(), GatewayError> = entity_gateway.with_transaction(|transaction| async move { - let item_state_proxy = ItemStateProxy::new(item_state, transaction); - /* - let item_state = item_state.clone(); - let mut s = item_state.lock().await; - //let s = s.borrow_mut(); - let item_state_proxy = ItemStateProxy::new(&mut s, transaction); - ItemStateAction::default() - .act(take_item_from_floor(*character_id, *item_id)) - .act(add_floor_item_to_inventory(*character_id)) - .commit(item_state_proxy) - .await - */ - Ok(()) - }).await; - */ - - //let mut transaction = entity_gateway.transaction().await?; - - /*entity_gateway.with_transaction(|transaction| { - item_state_proxy.execute(&mut transaction)?.await - }).await?;*/ - - //Ok(result) - Ok(TriggerCreateItem::Yes) - //.exec_gateway(&mut entity_gateway) + Ok(result?) }