|
|
@ -559,3 +559,41 @@ where |
|
|
|
}).await
|
|
|
|
}
|
|
|
|
|
|
|
|
fn sort_inventory_items(character_id: CharacterEntityId, item_ids: Vec<ClientItemId>)
|
|
|
|
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
|
|
|
|
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
|
|
|
|
{
|
|
|
|
move |(mut item_state, mut transaction), _| {
|
|
|
|
let item_ids = item_ids.clone();
|
|
|
|
Box::pin(async move {
|
|
|
|
let mut inventory = item_state.inventory(&character_id)?;
|
|
|
|
inventory.sort(&item_ids);
|
|
|
|
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
|
|
|
|
item_state.set_inventory(inventory);
|
|
|
|
|
|
|
|
Ok(((item_state, transaction), ()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn sort_inventory<'a, EG> (
|
|
|
|
item_state: &'a mut ItemState,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
character: &CharacterEntity,
|
|
|
|
item_ids: Vec<ClientItemId>,
|
|
|
|
) -> Result<(), 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(sort_inventory_items(character.id, item_ids))
|
|
|
|
.commit((item_state_proxy, transaction))
|
|
|
|
.await?;
|
|
|
|
item_state_proxy.commit();
|
|
|
|
Ok((transaction, result))
|
|
|
|
}).await
|
|
|
|
}
|