diff --git a/src/bin/main.rs b/src/bin/main.rs index 05305df..c2ace7d 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -358,9 +358,7 @@ fn main() { ).await.unwrap(); let item13 = entity_gateway.create_item( NewItemEntity { - item: ItemDetail::Mag( - item::mag::Mag::baby_mag(5) - ), + item: item::ItemDetail::Mag(item::mag::Mag::wrapped_baby_mag(5)), location: ItemLocation::Inventory { character_id: character.id, } diff --git a/src/entity/gateway/postgres/postgres.rs b/src/entity/gateway/postgres/postgres.rs index 9d02c52..da0067b 100644 --- a/src/entity/gateway/postgres/postgres.rs +++ b/src/entity/gateway/postgres/postgres.rs @@ -493,6 +493,14 @@ impl EntityGateway for PostgresGateway { Ok(()) } + async fn add_mag_modifier(&mut self, item_id: &ItemEntityId, modifier: mag::MagModifier) -> Result<(), GatewayError> { + sqlx::query("insert into mag_modifier (mag, modifier) values ($1, $2);") + .bind(item_id.0) + .bind(sqlx::types::Json(modifier)) + .execute(&self.pool).await?; + Ok(()) + } + /* async fn get_items_by_character(&self, char_id: &CharacterEntityId) -> Result, GatewayError> { let q = r#"select * from ( diff --git a/src/entity/item/mag.rs b/src/entity/item/mag.rs index 5a7bf8d..3dedef0 100644 --- a/src/entity/item/mag.rs +++ b/src/entity/item/mag.rs @@ -509,7 +509,7 @@ impl MagAttributeOrdering { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub enum MagModifier { FeedMag{ food: ItemEntityId, @@ -568,6 +568,24 @@ impl Mag { } } + pub fn wrapped_baby_mag(skin: u16) -> Mag { + Mag { + mag: MagType::Mag, + def: 500, + pow: 0, + dex: 0, + mnd: 0, + synchro: 20, + iq: 0, + photon_blast: [None; 3], + color: (skin % 18) as u8, + //modifiers: Vec::new(), + class: CharacterClass::HUmar, + id: SectionID::Viridia, + wrapping: WrappingPaper::from((skin % 10) as u8), + } + } + pub fn as_bytes(&self) -> [u8; 16] { let mut result = [0; 16]; result[0..3].copy_from_slice(&self.mag.value()); @@ -1117,7 +1135,7 @@ impl Mag { match modifier { MagModifier::WrapPresent => {self.wrapping = WrappingPaper::from(self.color % 10)}, // prevents mag color from crashing wrapping papers MagModifier::UnwrapPresent => {self.wrapping = None}, - _ => {}, // TODO: do mags use any other modifiers? + _ => {}, // TODO: other modifiers are already handled elsewhere. do they need to be moved here? } } }