From da0c75fa39012fd069224d5c93356f01fccd6f03 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 Apr 2022 21:16:04 -0600 Subject: [PATCH] cleanup --- src/ship/items/state.rs | 195 +--------------------------------------- 1 file changed, 1 insertion(+), 194 deletions(-) diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index 323505d..6b78a8a 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -77,7 +77,6 @@ where { pub fn act(self, f: F) -> ItemActionStage, F, Fut, S, E> where - //F: FnOnce(S, ()) -> Pin> + Send>> + Send + Sync F: Fn(S, ()) -> Fut + Send + Sync, Fut: Future> + Send { @@ -95,7 +94,6 @@ where P: ItemAction, F: Fn(S, P::Output) -> Fut + Send + Sync, Fut: Future> + Send, - //F: FnOnce(S, P::Output) -> Pin> + Send>> + Send + Sync, { _s: std::marker::PhantomData, _e: std::marker::PhantomData, @@ -107,7 +105,6 @@ where impl ItemAction for ItemActionStage where P: ItemAction + ItemAction + Send + Sync, - //F: FnOnce(S, P::Output) -> Pin> + Send>> + Send + Sync, F: Fn(S, P::Output) -> Fut + Send + Sync, Fut: Future> + Send, S: Send + Sync, @@ -145,7 +142,6 @@ where pub fn act(self, g: G) -> ItemActionStage, G, GFut, S, E> where S: Send + Sync, - //G: FnOnce(S, as ItemAction>::Output) -> Pin> + Send>> + Send + Sync, G: Fn(S, as ItemAction>::Output) -> GFut + Send + Sync, GFut: Future> + 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 for FloorItem { - fn into(&self) -> InventoryItem { - InventoryItem { - item_id: self.item_id, - item: - } - } -} -*/ #[derive(Clone, Debug)] pub struct Inventory(Vec); -/* -#[derive(Clone, Debug)] -pub struct Inventory { - item_id_counter: u32, - items: Vec, - 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>>, - //character_bank: HashMap>, - //character_meseta: HashMap>, - //bank_meseta: HashMap>, - - character_room: RefCell>>, - character_floor: RefCell>>, - room_floor: RefCell>>, - - //room_item_id_counter: HashMap 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, //character_bank: HashMap>, @@ -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, - //entity_gateway: &'a mut Box, - //entity_gateway: &'a mut Box, proxied_state: ProxiedItemState, - - //gateway_actions: Vec, - - //_eg: std::marker::PhantomData, } -//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, proxy: &'a RefCell>>, key: K, err: fn(K) -> ItemStateError) -> Result + '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, proxy: &'a mut HashMap>, key: K, err: fn(K) -> ItemStateError) -> Result + '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(master: &HashMap, proxy: &mut HashMap, key: K, err: fn(K) -> ItemStateError) -> Result 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*/) -> 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 { - //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 { - 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(item_state: &mut ItemState, - entity_gateway: &mut EG, - character: &CharacterEntity, - item_drop: ItemDrop) - -> Result -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(item_state: &mut ItemState, - entity_gateway: &mut EG, - character_id: &CharacterEntityId, - item_id: &ClientItemId, - amount: usize) - -> Result -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) -} -*/ -