From 2d5f83fab6e122ea3830e9fa39d11b3a1bc99c33 Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 9 Nov 2020 18:54:44 -0700 Subject: [PATCH 1/6] make inv item stuff serializable --- src/entity/item/mod.rs | 8 ++++---- src/ship/items/mod.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) 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/ship/items/mod.rs b/src/ship/items/mod.rs index 3268b04..facbc11 100644 --- a/src/ship/items/mod.rs +++ b/src/ship/items/mod.rs @@ -3,8 +3,9 @@ mod floor; 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 From c7a310391f176eada185cc5922cdf032ef26704b Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 9 Nov 2020 19:07:41 -0700 Subject: [PATCH 2/6] make inv mod pub --- src/ship/items/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ship/items/mod.rs b/src/ship/items/mod.rs index facbc11..d70a7f4 100644 --- a/src/ship/items/mod.rs +++ b/src/ship/items/mod.rs @@ -1,6 +1,6 @@ mod bank; mod floor; -mod inventory; +pub mod inventory; mod manager; pub mod use_tool; use serde::{Serialize, Deserialize}; From ceb632aec82ed552c020caba2e9836b308212484 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 11 Nov 2020 19:26:12 -0700 Subject: [PATCH 3/6] make equippedentity serializeable --- src/entity/item/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entity/item/mod.rs b/src/entity/item/mod.rs index 22e2913..7555296 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -217,7 +217,7 @@ impl InventoryItemEntity { } } -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct EquippedEntity { pub weapon: Option, pub armor: Option, From 4954dcb789af3660400426d03173cb6724ae5f7f Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 12 Nov 2020 17:13:42 -0700 Subject: [PATCH 4/6] should probably split this since theres already live data --- .../postgres/migrations/V0001__initial.sql | 24 ------------------- .../postgres/migrations/V0002__equips.sql | 23 ++++++++++++++++++ src/entity/item/mod.rs | 2 +- 3 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 src/entity/gateway/postgres/migrations/V0002__equips.sql 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 7555296..22e2913 100644 --- a/src/entity/item/mod.rs +++ b/src/entity/item/mod.rs @@ -217,7 +217,7 @@ impl InventoryItemEntity { } } -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default)] pub struct EquippedEntity { pub weapon: Option, pub armor: Option, From b34deba17f5211e82473b9f0f50db3704e11724b Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 12 Nov 2020 19:05:30 -0700 Subject: [PATCH 5/6] update sqlx --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From c384b134536a01e75684da8455d70b921e399953 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 12 Nov 2020 19:05:46 -0700 Subject: [PATCH 6/6] actually save new character stuff --- src/login/character.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; }