Browse Source

cleanup

pull/112/head
jake 2 years ago
committed by andy
parent
commit
7aa4a6394f
  1. 103
      src/ship/items/state.rs

103
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<O, P, F, S, E>
where
P: ItemAction,
//F: Fn(&mut S, P::Output) -> Result<O, E> + for<'r> std::ops::Fn<(&'r mut S, T)>,
F: Fn(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O) , E>> + Send>> + Send + Sync,
{
_s: std::marker::PhantomData<S>,
@ -632,13 +616,9 @@ fn add_floor_item_to_inventory(character_id: CharacterEntityId)
}
//hint<R, F: FnOnce(&mut dyn EntityGateway) -> R>(f: F) -> F {f}
#[fix_hidden_lifetime_bug]
async fn pick_up_item<'a, EG>(
item_state: &'a mut ItemState,
//item_state: Arc<Mutex<ItemState>>,
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<TriggerCreateItem, ItemStateError> = 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<TriggerCreateItem, ItemStateError> = 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<Box<dyn Future<Output=Result<(), GatewayError>> + 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<Box<dyn Future<Output=Result<(), GatewayError>> + 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?)
}

Loading…
Cancel
Save