diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index 7a28563..ee6c1fa 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -85,7 +85,7 @@ pub trait EntityGateway: Send + Sync + Clone { unimplemented!(); } - async fn get_items_by_character(&self, _char: &CharacterEntity) -> Result, GatewayError> { + async fn get_items_by_character(&self, _char_id: &CharacterEntityId) -> Result, GatewayError> { unimplemented!(); } } diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index 89a47e2..12d25e7 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -205,14 +205,14 @@ impl EntityGateway for InMemoryGateway { Ok(()) } - async fn get_items_by_character(&self, character: &CharacterEntity) -> Result, GatewayError> { + async fn get_items_by_character(&self, character_id: &CharacterEntityId) -> Result, GatewayError> { let items = self.items.lock().unwrap(); Ok(items .iter() .filter(|(_, k)| { match k.location { - ItemLocation::Inventory{character_id, ..} => character_id == character.id, - ItemLocation::Bank{character_id, ..} => character_id == character.id, + ItemLocation::Inventory{character_id, ..} => character_id == character_id, + ItemLocation::Bank{character_id, ..} => character_id == character_id, _ => false } }) diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 965bcf4..5318cc2 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -364,7 +364,7 @@ impl EntityGateway for PostgresGateway { Ok(()) } - async fn get_items_by_character(&self, char: &CharacterEntity) -> Result, GatewayError> { + async fn get_items_by_character(&self, char_id: &CharacterEntityId) -> Result, GatewayError> { let q = r#"select * from ( select distinct on (item_location.item) item.id, @@ -384,7 +384,7 @@ impl EntityGateway for PostgresGateway { or cast (location -> 'Bank' ->> 'character_id' as integer) = $1 "#; let items = sqlx::query_as::<_, PgItemWithLocation>(q) - .bind(char.id.0) + .bind(char_id.0) .fetch(&self.pool); Ok(join_all(items .filter_map(|item: Result| { diff --git a/src/ship/items/manager.rs b/src/ship/items/manager.rs index dbd91fe..ce80e77 100644 --- a/src/ship/items/manager.rs +++ b/src/ship/items/manager.rs @@ -116,7 +116,7 @@ impl ItemManager { // TODO: Result pub async fn load_character(&mut self, entity_gateway: &mut EG, character: &CharacterEntity) -> Result<(), ItemManagerError> { - let items = entity_gateway.get_items_by_character(&character).await?; + let items = entity_gateway.get_items_by_character(&character.id).await?; let inventory_items = items.clone().into_iter() .filter_map(|item| { match item.location { diff --git a/tests/test_bank.rs b/tests/test_bank.rs index 08bb984..7add54c 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -295,7 +295,7 @@ async fn test_deposit_individual_item() { && player_no_longer_has_item.amount == 0 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -364,7 +364,7 @@ async fn test_deposit_stacked_item() { && player_no_longer_has_item.amount == 3 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -433,7 +433,7 @@ async fn test_deposit_partial_stacked_item() { && player_no_longer_has_item.amount == 2 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -528,7 +528,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { && player_no_longer_has_item.amount == 2 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -604,7 +604,7 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -700,7 +700,7 @@ async fn test_deposit_individual_item_in_full_bank() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -793,7 +793,7 @@ async fn test_deposit_stacked_item_in_full_bank() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -899,7 +899,7 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { unknown: 0, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -1096,7 +1096,7 @@ async fn test_withdraw_individual_item() { if create_item.item_id == 0x20000 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let inventory_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Inventory{..} = item.location { @@ -1163,7 +1163,7 @@ async fn test_withdraw_stacked_item() { if create_item.item_id == 0x10002 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let inventory_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Inventory {..} = item.location { @@ -1230,7 +1230,7 @@ async fn test_withdraw_partial_stacked_item() { if create_item.item_id == 0x10002 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -1323,7 +1323,7 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { if create_item.item_id == 0x10000 )); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let inventory_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Inventory {..} = item.location { @@ -1399,7 +1399,7 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -1495,7 +1495,7 @@ async fn test_withdraw_individual_item_in_full_inventory() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -1588,7 +1588,7 @@ async fn test_withdraw_stacked_item_in_full_inventory() { assert!(packets.is_err()); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { @@ -1695,7 +1695,7 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { unknown: 0, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let bank_item_ids = items.iter() .filter_map(|item| { if let item::ItemLocation::Bank {..} = item.location { diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index ec77f62..51f1d47 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -80,7 +80,7 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 6); let p1_item_ids = p1_items.iter().map(|item| { @@ -149,7 +149,7 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 1); let first_item = p1_items.get(0).unwrap(); @@ -227,7 +227,7 @@ async fn test_pick_up_meseta_when_inventory_full() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 30); let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); @@ -324,7 +324,7 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 31); let monomate1 = p1_items.get(29).unwrap(); @@ -415,10 +415,10 @@ async fn test_can_not_pick_up_item_when_inventory_full() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 30); - let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap(); + let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap(); assert!(p2_items.len() == 0); ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem { @@ -429,7 +429,7 @@ async fn test_can_not_pick_up_item_when_inventory_full() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap(); + let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap(); assert!(p2_items.len() == 1); } @@ -544,10 +544,10 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { })))).await.unwrap().collect::>(); assert!(packets.len() == 0); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 6); - let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap(); + let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap(); assert!(p2_items.len() == 0); } @@ -726,7 +726,7 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items.len() == 3); let p1_item_ids = p1_items.iter().map(|item| { @@ -742,7 +742,7 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { }); assert!(all_items_are_monomates); - let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap(); + let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap(); assert!(p2_items.len() == 2); let p2_item_ids = p2_items.iter().map(|item| { diff --git a/tests/test_item_use.rs b/tests/test_item_use.rs index f1cff0b..bdee01f 100644 --- a/tests/test_item_use.rs +++ b/tests/test_item_use.rs @@ -49,7 +49,7 @@ async fn test_use_monomate() { item_id: 0x10000, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(items.iter().filter(|item| { if let item::ItemDetail::Tool(t) = item.item { t.tool == item::tool::ToolType::Monomate @@ -110,7 +110,7 @@ async fn test_use_monomate_twice() { item_id: 0x10000, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(items.iter().filter(|item| { if let item::ItemDetail::Tool(t) = item.item { t.tool == item::tool::ToolType::Monomate @@ -166,7 +166,7 @@ async fn test_use_last_monomate() { item_id: 0x10000, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(items.iter().filter(|item| { if let item::ItemDetail::Tool(t) = item.item { t.tool == item::tool::ToolType::Monomate @@ -218,7 +218,7 @@ async fn test_use_nonstackable_tool() { item_id: 0x10000, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(items.len() == 0); } @@ -269,7 +269,7 @@ async fn test_use_materials() { item_id: 0x10001, })))).await.unwrap().for_each(drop); - let items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(items.iter().filter(|item| { if let item::ItemDetail::Tool(t) = item.item { t.tool == item::tool::ToolType::PowerMaterial diff --git a/tests/test_mags.rs b/tests/test_mags.rs index f1b628d..a0f6fe8 100644 --- a/tests/test_mags.rs +++ b/tests/test_mags.rs @@ -60,7 +60,7 @@ async fn test_mag_feed() { })))).await.unwrap().for_each(drop); } - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let mag = p1_items.get(0).unwrap(); match &mag.item { item::ItemDetail::Mag(mag) => { @@ -128,7 +128,7 @@ async fn test_mag_change_owner() { unknown: [0; 3] })))).await.unwrap().for_each(drop); - let p2_items = entity_gateway.get_items_by_character(&char2).await.unwrap(); + let p2_items = entity_gateway.get_items_by_character(&char2.id).await.unwrap(); let mag = p2_items.get(0).unwrap(); match &mag.item { item::ItemDetail::Mag(mag) => { @@ -199,7 +199,7 @@ async fn test_mag_cell() { item_id: 0x10001, })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); let mag = p1_items.get(0).unwrap(); match &mag.item { item::ItemDetail::Mag(mag) => { diff --git a/tests/test_shops.rs b/tests/test_shops.rs index 74c4a33..0574947 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -135,7 +135,7 @@ async fn test_player_buys_from_weapon_shop() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert!(c1.meseta < 999999); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 1); } @@ -173,7 +173,7 @@ async fn test_player_buys_from_tool_shop() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert!(c1.meseta < 999999); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 1); } @@ -211,7 +211,7 @@ async fn test_player_buys_multiple_from_tool_shop() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert!(c1.meseta < 999999); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 5); } @@ -249,7 +249,7 @@ async fn test_player_buys_from_armor_shop() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert!(c1.meseta < 999999); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 1); } @@ -388,7 +388,7 @@ async fn test_buying_item_without_enough_mseseta() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert_eq!(c1.meseta, 0); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 0); } @@ -444,7 +444,7 @@ async fn test_player_double_buys_from_tool_shop() { let characters1 = entity_gateway.get_characters_by_user(&user1).await.unwrap(); let c1 = characters1.get(0).as_ref().unwrap().as_ref().unwrap(); assert!(c1.meseta < 999999); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert_eq!(p1_items.len(), 9); } @@ -502,7 +502,7 @@ async fn test_techs_disappear_from_shop_when_bought() { unknown1: 0, })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items[0].item != p1_items[1].item); } @@ -560,6 +560,6 @@ async fn test_units_disappear_from_shop_when_bought() { unknown1: 0, })))).await.unwrap().for_each(drop); - let p1_items = entity_gateway.get_items_by_character(&char1).await.unwrap(); + let p1_items = entity_gateway.get_items_by_character(&char1.id).await.unwrap(); assert!(p1_items[0].item != p1_items[1].item); }