Browse Source

cleanup

kill_counters
jake 3 years ago
committed by andy
parent
commit
46af418adb
  1. 195
      src/ship/items/state.rs

195
src/ship/items/state.rs

@ -77,7 +77,6 @@ where
{
pub fn act<O, F, Fut>(self, f: F) -> ItemActionStage<O, ItemStateAction<T, S, E>, F, Fut, S, E>
where
//F: FnOnce(S, ()) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync
F: Fn(S, ()) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O), E>> + Send
{
@ -95,7 +94,6 @@ where
P: ItemAction,
F: Fn(S, P::Output) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O) , E>> + Send,
//F: FnOnce(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O) , E>> + Send>> + Send + Sync,
{
_s: std::marker::PhantomData<S>,
_e: std::marker::PhantomData<E>,
@ -107,7 +105,6 @@ where
impl<O, P: ItemAction, F, Fut, S, E> ItemAction for ItemActionStage<O, P, F, Fut, S, E>
where
P: ItemAction + ItemAction<Start = S, Error = E> + Send + Sync,
//F: FnOnce(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync,
F: Fn(S, P::Output) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O), E>> + Send,
S: Send + Sync,
@ -145,7 +142,6 @@ where
pub fn act<O2, G, GFut>(self, g: G) -> ItemActionStage<O2, ItemActionStage<O, P, F, Fut, S, E>, G, GFut, S, E>
where
S: Send + Sync,
//G: FnOnce(S, <ItemActionStage<O, P, F, S, E> as ItemAction>::Output) -> Pin<Box<dyn Future<Output=Result<(S, O2), E>> + Send>> + Send + Sync,
G: Fn(S, <ItemActionStage<O, P, F, Fut, S, E> as ItemAction>::Output) -> GFut + Send + Sync,
GFut: Future<Output=Result<(S, O2), E>> + Send,
O2: Send + Sync,
@ -256,20 +252,6 @@ impl FloorItemDetail {
_ => None,
}
}
/*
fn mag<'a>(&'a self) -> Option<&'a IndividualItemDetail> {
match self {
FloorItemDetail::Individual(individual_item) => {
match individual_item.item {
ItemDetail::Mag(mag) => Some(mag),
_ => None,
}
},
_ => None
}
}
*/
}
#[derive(Clone)]
@ -320,28 +302,9 @@ impl FloorItem {
}
}
// meseta is a floor item
/*
impl Into<InventoryItem> for FloorItem {
fn into(&self) -> InventoryItem {
InventoryItem {
item_id: self.item_id,
item:
}
}
}
*/
#[derive(Clone, Debug)]
pub struct Inventory(Vec<InventoryItem>);
/*
#[derive(Clone, Debug)]
pub struct Inventory {
item_id_counter: u32,
items: Vec<InventoryItem>,
equipped: EquippedEntity,
}
*/
impl Inventory {
pub fn as_inventory_entity(&self, _character_id: &CharacterEntityId) -> InventoryEntity {
@ -514,36 +477,6 @@ impl Default for ItemState {
}
/*
struct ProxiedItemState {
character_inventory: RefCell<HashMap<CharacterEntityId, RefCell<Inventory>>>,
//character_bank: HashMap<CharacterEntityId, RefCell<Bank>>,
//character_meseta: HashMap<CharacterEntityId, RefCell<Meseta>>,
//bank_meseta: HashMap<CharacterEntityId, RefCell<Meseta>>,
character_room: RefCell<HashMap<CharacterEntityId, RefCell<RoomId>>>,
character_floor: RefCell<HashMap<CharacterEntityId, RefCell<RoomFloorItems>>>,
room_floor: RefCell<HashMap<RoomId, RefCell<RoomFloorItems>>>,
//room_item_id_counter: HashMap<RoomId, RefCell<Box<dyn FnMut() -> ClientItemId + Send>>>,
}
impl Default for ProxiedItemState {
fn default() -> Self {
ProxiedItemState {
character_inventory: RefCell::new(HashMap::new()),
//character_bank: HashMap::new(),
//character_meseta: HashMap::new(),
//bank_meseta: HashMap::new(),
character_floor: RefCell::new(HashMap::new()),
character_room: RefCell::new(HashMap::new()),
room_floor: RefCell::new(HashMap::new()),
//room_item_id_counter: HashMap::new(),
}
}
}
*/
struct ProxiedItemState {
character_inventory: HashMap<CharacterEntityId, Inventory>,
//character_bank: HashMap<CharacterEntityId, RefCell<Bank>>,
@ -575,19 +508,9 @@ impl Default for ProxiedItemState {
pub struct ItemStateProxy<'a> {
item_state: &'a mut ItemState,
//entity_gateway: &'a mut dyn EntityGateway,
//transaction: Box<dyn EntityGatewayTransaction>,
//entity_gateway: &'a mut Box<dyn EntityGateway>,
//entity_gateway: &'a mut Box<dyn EntityGateway>,
proxied_state: ProxiedItemState,
//gateway_actions: Vec<GatewayActions>,
//_eg: std::marker::PhantomData<EG>,
}
//impl<'a> Drop for ItemStateProxy<'a> {
// fn drop(&mut self) {
impl<'a> ItemStateProxy<'a> {
pub fn commit(self) {
self.item_state.character_inventory.extend(self.proxied_state.character_inventory.clone());
@ -598,34 +521,6 @@ impl<'a> ItemStateProxy<'a> {
}
}
/*
fn get_or_clone<'a, K, V>(master: &HashMap<K, V>, proxy: &'a RefCell<HashMap<K, RefCell<V>>>, key: K, err: fn(K) -> ItemStateError) -> Result<impl Deref<Target = V> + 'a, ItemStateError>
where
K: Eq + std::hash::Hash + Copy,
V: Clone
{
let existing_element = master.get(&key).ok_or_else(|| err(key))?;
Ok(proxy.borrow_mut().entry(key)
.or_insert(RefCell::new(existing_element.clone()))
.borrow_mut())
}
*/
/*
fn get_or_clone<'a, K, V>(master: &HashMap<K, V>, proxy: &'a mut HashMap<K, RefCell<V>>, key: K, err: fn(K) -> ItemStateError) -> Result<impl Deref<Target = V> + 'a, ItemStateError>
where
K: Eq + std::hash::Hash + Copy,
V: Clone
{
let existing_element = master.get(&key).ok_or_else(|| err(key))?;
Ok(proxy.entry(key)
.or_insert(RefCell::new(existing_element.clone()))
.borrow_mut())
}
*/
fn get_or_clone<K, V>(master: &HashMap<K, V>, proxy: &mut HashMap<K, V>, key: K, err: fn(K) -> ItemStateError) -> Result<V, ItemStateError>
where
@ -639,16 +534,10 @@ where
}
impl<'a> ItemStateProxy<'a> {
//fn new(item_state: &'a mut ItemState, entity_gateway: &'a mut EG) -> Self {
//fn new(item_state: &'a mut ItemState, entity_gateway: &'a mut dyn EntityGateway) -> Self {
pub fn new(item_state: &'a mut ItemState/*, transaction: Box<dyn EntityGatewayTransaction>*/) -> Self {
pub fn new(item_state: &'a mut ItemState) -> Self {
ItemStateProxy {
item_state,
//entity_gateway,
//transaction,
proxied_state: Default::default(),
//gateway_actions: Vec::new(),
//_eg: std::marker::PhantomData,
}
}
@ -681,89 +570,7 @@ impl<'a> ItemStateProxy<'a> {
}
pub fn new_item_id(&mut self) -> Result<ClientItemId, ItemStateError> {
//let room_id = get_or_clone(&self.item_state.character_room, &mut self.proxied_state.character_room, *character_id, |c| ItemStateError::NoCharacter(c))?;
self.item_state.room_item_id_counter += 1;
Ok(ClientItemId(self.item_state.room_item_id_counter))
/*
self.item_state.room_item_id_counter
.borrow_mut()
.get_mut(&room_id)
.ok_or(ItemStateError::NoRoom(room_id))
.map(|f| f())
*/
}
}
/*
fn record_item_drop(character_id: CharacterEntityId, item_drop: ItemDrop) -> impl Fn(&mut ItemStateProxy, ()) -> Result<(), ItemStateError> {
move |item_state, _| {
// how do I do this? I need EG to add_item_note but how should I kick that till later?
// general purpose vec in item_state `misc_gateway_actions`?
// can't quite use actions here as it relies on an ItemEntityId which at this point does not yet exist for the dropped item
//item_state.gateway_actions.push(GatewayAction::ItemNote(item_drop.))
Ok(())
}
}
*/
/*
fn map_drop_to_floor_item(character_id: CharacterEntityId, item_drop: ItemDrop) -> impl Fn(&mut ItemStateProxy, ()) -> Result<FloorItem, ItemStateError> {
move |item_state, _| {
match item_drop.item {
ItemDropType::Weapon(w) => FloorItem {
item_id: item_state.new_item_id(&character_id)?,
item: FloorItemDetail::Individual(item_drop.item)
},
ItemDropType::Armor(w) => ItemOrMeseta::Individual(ItemDetail::Armor(w)),
ItemDropType::Shield(w) => ItemOrMeseta::Individual(ItemDetail::Shield(w)),
ItemDropType::Unit(w) => ItemOrMeseta::Individual(ItemDetail::Unit(w)),
ItemDropType::TechniqueDisk(w) => ItemOrMeseta::Individual(ItemDetail::TechniqueDisk(w)),
ItemDropType::Mag(w) => ItemOrMeseta::Individual(ItemDetail::Mag(w)),
//ItemDropType::IndividualTool(t) => ItemOrMeseta::Individual(ItemDetail::Tool(t)),
//ItemDropType::StackedTool(t, _) => ItemOrMeseta::Stacked(t),
ItemDropType::Tool(t) if t.tool.is_stackable() => ItemOrMeseta::Stacked(t),
ItemDropType::Tool(t) if !t.tool.is_stackable() => ItemOrMeseta::Individual(ItemDetail::Tool(t)),
ItemDropType::Meseta(m) => ItemOrMeseta::Meseta(Meseta(m)),
_ => unreachable!() // rust isnt smart enough to see that the conditional on tool catches everything
}
}
}
fn enemy_drops_item<EG>(item_state: &mut ItemState,
entity_gateway: &mut EG,
character: &CharacterEntity,
item_drop: ItemDrop)
-> Result<FloorItem, ItemStateError>
where
EG: EntityGateway,
{
ItemStateAction::default()
.act(record_item_drop(character.id, item_drop.clone()))
.act(map_drop_to_floor_item(character.id, item_drop))
.act(add_item_drop_to_floor(character.id))
.commit(&mut ItemStateProxy::new(item_state))
}
*/
/*
fn sell_item<EG: EntityGateway>(item_state: &mut ItemState,
entity_gateway: &mut EG,
character_id: &CharacterEntityId,
item_id: &ClientItemId,
amount: usize)
-> Result<TriggerCreateItem, ItemStateError>
where
EG: EntityGateway,
{
ItemStateAction::default()
.act(take_item_from_inventory(*character_id, *item_id))
.act(sell_inventory_item(*character_id, *item_id))
.exec_state(&mut ItemStateProxy::new(item_state))
.exec_gateway(&mut entity_gateway)
}
*/
Loading…
Cancel
Save