From f27c121539874ec4f5afc79a50fd1535c1a9d8f4 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 31 Jan 2023 00:06:34 -0700 Subject: [PATCH] take ref to weapon modifier --- src/entity/gateway/entitygateway.rs | 2 +- src/entity/gateway/inmemory.rs | 6 +++--- src/entity/gateway/postgres/postgres.rs | 6 +++--- src/ship/items/actions.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/entity/gateway/entitygateway.rs b/src/entity/gateway/entitygateway.rs index a8c47dc..db2f5f0 100644 --- a/src/entity/gateway/entitygateway.rs +++ b/src/entity/gateway/entitygateway.rs @@ -96,7 +96,7 @@ pub trait EntityGateway: Send + Sync { unimplemented!(); } - async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { + async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { unimplemented!(); } diff --git a/src/entity/gateway/inmemory.rs b/src/entity/gateway/inmemory.rs index db485e8..13b281c 100644 --- a/src/entity/gateway/inmemory.rs +++ b/src/entity/gateway/inmemory.rs @@ -104,7 +104,7 @@ impl EntityGateway for InMemoryGatewayTransaction { self.working_gateway.use_mag_cell(mag_item_id, mag_cell_id).await } - async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { + async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { self.working_gateway.add_weapon_modifier(item_id, modifier).await } @@ -528,11 +528,11 @@ impl EntityGateway for InMemoryGateway { Ok(()) } - async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { + async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { self.weapon_modifiers.lock().await .entry(*item_id) .or_insert_with(Vec::new) - .push(modifier); + .push(modifier.clone()); Ok(()) } diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index dbc49d4..bb8c018 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -380,7 +380,7 @@ async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, Ok(()) } -async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> +async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);") .bind(item_id.0) @@ -688,7 +688,7 @@ impl<'t> EntityGateway for PostgresGateway<'t> { use_mag_cell(&mut *self.pool.acquire().await?, mag_item_id, mag_cell_id).await } - async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { + async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { add_weapon_modifier(&mut *self.pool.acquire().await?, item_id, modifier).await } @@ -814,7 +814,7 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { use_mag_cell(&mut *self.pgtransaction.lock().await, mag_item_id, mag_cell_id).await } - async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { + async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { add_weapon_modifier(&mut *self.pgtransaction.lock().await, item_id, modifier).await } diff --git a/src/ship/items/actions.rs b/src/ship/items/actions.rs index be6748b..984fdbd 100644 --- a/src/ship/items/actions.rs +++ b/src/ship/items/actions.rs @@ -1006,7 +1006,7 @@ where match (&mut inventory_item.item, modifier) { (InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => { weapon.apply_modifier(&modifier); - transaction.gateway().add_weapon_modifier(entity_id, modifier).await?; + transaction.gateway().add_weapon_modifier(entity_id, &modifier).await?; }, _ => return Err(ItemStateError::InvalidModifier.into()) }