Browse Source

take ref to weapon modifier

pull/128/head
jake 2 years ago
parent
commit
f27c121539
  1. 2
      src/entity/gateway/entitygateway.rs
  2. 6
      src/entity/gateway/inmemory.rs
  3. 6
      src/entity/gateway/postgres/postgres.rs
  4. 2
      src/ship/items/actions.rs

2
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!();
}

6
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(())
}

6
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
}

2
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())
}

Loading…
Cancel
Save