diff --git a/Cargo.toml b/Cargo.toml index 79c76a4..d9c1bff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ async-trait = "0.1.41" lazy_static = "1.4.0" barrel = { version = "0.6.5", features = ["pg"] } refinery = { version = "0.3.0", features = ["postgres"] } -sqlx = { version = "0.4.0-beta.1", features = ["postgres", "json", "chrono"] } +sqlx = { version = "0.4.0", features = ["runtime-async-std-native-tls", "postgres", "json", "chrono"] } strum = "0.19.5" strum_macros = "0.19" anyhow = "1.0.33" diff --git a/src/entity/gateway/postgres/migrations/V0001__initial.sql b/src/entity/gateway/postgres/migrations/V0001__initial.sql index 98e2f63..b4cd507 100644 --- a/src/entity/gateway/postgres/migrations/V0001__initial.sql +++ b/src/entity/gateway/postgres/migrations/V0001__initial.sql @@ -122,27 +122,3 @@ create table mag_modifier ( modifier jsonb not null, created_at timestamptz default current_timestamp not null ); - -create table equipped ( - pchar integer references player_character (id) unique not null, - weapon integer references item (id), - armor integer references item (id), - shield integer references item (id), - unit0 integer references item (id), - unit1 integer references item (id), - unit2 integer references item (id), - unit3 integer references item (id), - mag integer references item (id) -); - -create table inventory ( - pchar integer references player_character (id) unique not null, - items jsonb not null -); - -create table bank ( - pchar integer references player_character (id) not null, - items jsonb not null, - name varchar(128) not null, - unique (pchar, name) -); diff --git a/src/entity/gateway/postgres/migrations/V0002__equips.sql b/src/entity/gateway/postgres/migrations/V0002__equips.sql new file mode 100644 index 0000000..a88a1e3 --- /dev/null +++ b/src/entity/gateway/postgres/migrations/V0002__equips.sql @@ -0,0 +1,23 @@ +create table equipped ( + pchar integer references player_character (id) unique not null, + weapon integer references item (id), + armor integer references item (id), + shield integer references item (id), + unit0 integer references item (id), + unit1 integer references item (id), + unit2 integer references item (id), + unit3 integer references item (id), + mag integer references item (id) +); + +create table inventory ( + pchar integer references player_character (id) unique not null, + items jsonb not null +); + +create table bank ( + pchar integer references player_character (id) not null, + items jsonb not null, + name varchar(128) not null, + unique (pchar, name) +); diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index a1aa305..22e2913 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -17,10 +17,10 @@ use crate::ship::drops::ItemDropType; pub struct ItemEntityId(pub u32); #[derive(Hash, PartialEq, Eq, Debug, Clone)] pub struct ItemId(u32); -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)] pub struct BankName(pub String); -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum ItemLocation { Inventory { character_id: CharacterEntityId, @@ -167,7 +167,7 @@ pub struct NewItemEntity { pub item: ItemDetail, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct ItemEntity { pub id: ItemEntityId, pub location: ItemLocation, @@ -175,7 +175,7 @@ pub struct ItemEntity { } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum InventoryItemEntity { Individual(ItemEntity), Stacked(Vec), diff --git a/src/login/character.rs b/src/login/character.rs index a991ed9..af796db 100644 --- a/src/login/character.rs +++ b/src/login/character.rs @@ -266,13 +266,13 @@ async fn new_character(entity_gateway: &mut EG, user: &UserAc items: vec![InventoryItemEntity::Individual(weapon.clone()), InventoryItemEntity::Individual(armor.clone()), InventoryItemEntity::Individual(mag.clone()), InventoryItemEntity::Stacked(monomates), InventoryItemEntity::Stacked(monofluids)], }; - entity_gateway.set_character_inventory(&character.id, &inventory); - entity_gateway.set_character_bank(&character.id, &BankEntity::default(), BankName("".into())); + entity_gateway.set_character_inventory(&character.id, &inventory).await; + entity_gateway.set_character_bank(&character.id, &BankEntity::default(), BankName("".into())).await; let mut equipped = EquippedEntity::default(); equipped.weapon = Some(weapon.id); equipped.armor = Some(armor.id); equipped.mag = Some(mag.id); - entity_gateway.set_character_equips(&character.id, &equipped); + entity_gateway.set_character_equips(&character.id, &equipped).await; } diff --git a/src/ship/items/mod.rs b/src/ship/items/mod.rs index 3268b04..d70a7f4 100644 --- a/src/ship/items/mod.rs +++ b/src/ship/items/mod.rs @@ -1,10 +1,11 @@ mod bank; mod floor; -mod inventory; +pub mod inventory; mod manager; pub mod use_tool; +use serde::{Serialize, Deserialize}; -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct ClientItemId(pub u32); // TODO: remove these and fix use statements in the rest of the codebase