diff --git a/assets/voxygen/voxel/sprite/repair_bench/repair_bench-0.vox b/assets/voxygen/voxel/sprite/repair_bench/repair_bench-0.vox new file mode 100644 index 0000000000..265b9eabb4 --- /dev/null +++ b/assets/voxygen/voxel/sprite/repair_bench/repair_bench-0.vox @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae8a36234e9ed125f1369d0fa396e35885f57c256d14d94149c383090678d326 +size 4692 diff --git a/assets/voxygen/voxel/sprite_manifest.ron b/assets/voxygen/voxel/sprite_manifest.ron index 6639b1bae9..e9f29976c3 100644 --- a/assets/voxygen/voxel/sprite_manifest.ron +++ b/assets/voxygen/voxel/sprite_manifest.ron @@ -3788,6 +3788,17 @@ CookingPot: Some(( ], wind_sway: 0.0, )), +// Repair Bench +RepairBench: Some(( + variations: [ + ( + model: "voxygen.voxel.sprite.repair_bench.repair_bench-0", + offset: (-7.0, -8.0, 0.0), + lod_axes: (0.0, 0.0, 0.0), + ), + ], + wind_sway: 0.0, +)), // Ensnaring Vines EnsnaringVines: Some(( variations: [ diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 990c696ee7..271d705b96 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -1228,11 +1228,7 @@ impl Item { } } - pub fn persistence_durability(&self) -> Option { - self.durability.map(|x| x.min(i32::MAX as u32) as i32) - } - - pub fn persistence_set_durability(&mut self, value: Option) { + pub fn persistence_set_durability(&mut self, value: Option) { // If changes have been made so that item no longer needs to track durability, // set to None if !self.has_durability() { @@ -1240,7 +1236,7 @@ impl Item { } else { // Set durability to persisted value, and if item previously had no durability, // set to Some(0) so that durability will be tracked - self.durability = Some(value.map_or(0, |x| x.max(0) as u32)); + self.durability = Some(value.unwrap_or(0)); } } diff --git a/server/src/migrations/V50__item_durability.sql b/server/src/migrations/V50__item_durability.sql index 482a175793..09fe315461 100644 --- a/server/src/migrations/V50__item_durability.sql +++ b/server/src/migrations/V50__item_durability.sql @@ -1 +1 @@ -ALTER TABLE item ADD durability INTEGER; \ No newline at end of file +ALTER TABLE item ADD properties TEXT NOT NULL DEFAULT '{}'; \ No newline at end of file diff --git a/server/src/persistence/character.rs b/server/src/persistence/character.rs index e7069b8b69..5a1b99bc1a 100644 --- a/server/src/persistence/character.rs +++ b/server/src/persistence/character.rs @@ -71,14 +71,14 @@ pub fn load_items(connection: &Connection, root: i64) -> Result, Persi item_definition_id, stack_size, position, - durability + properties ) AS ( SELECT item_id, parent_container_item_id, item_definition_id, stack_size, position, - durability + properties FROM item WHERE parent_container_item_id = ?1 UNION ALL @@ -87,7 +87,7 @@ pub fn load_items(connection: &Connection, root: i64) -> Result, Persi item.item_definition_id, item.stack_size, item.position, - item.durability + item.properties FROM item, items_tree WHERE item.parent_container_item_id = items_tree.item_id ) @@ -103,7 +103,7 @@ pub fn load_items(connection: &Connection, root: i64) -> Result, Persi item_definition_id: row.get(2)?, stack_size: row.get(3)?, position: row.get(4)?, - durability: row.get(5)?, + properties: row.get(5)?, }) })? .filter_map(Result::ok) @@ -394,7 +394,7 @@ pub fn create_character( parent_container_item_id: WORLD_PSEUDO_CONTAINER_ID, item_definition_id: CHARACTER_PSEUDO_CONTAINER_DEF_ID.to_owned(), position: character_id.to_string(), - durability: None, + properties: String::new(), }, Item { stack_size: 1, @@ -402,7 +402,7 @@ pub fn create_character( parent_container_item_id: character_id, item_definition_id: INVENTORY_PSEUDO_CONTAINER_DEF_ID.to_owned(), position: INVENTORY_PSEUDO_CONTAINER_POSITION.to_owned(), - durability: None, + properties: String::new(), }, Item { stack_size: 1, @@ -410,7 +410,7 @@ pub fn create_character( parent_container_item_id: character_id, item_definition_id: LOADOUT_PSEUDO_CONTAINER_DEF_ID.to_owned(), position: LOADOUT_PSEUDO_CONTAINER_POSITION.to_owned(), - durability: None, + properties: String::new(), }, ]; @@ -421,7 +421,7 @@ pub fn create_character( item_definition_id, stack_size, position, - durability) + properties) VALUES (?1, ?2, ?3, ?4, ?5, ?6)", )?; @@ -432,7 +432,7 @@ pub fn create_character( &pseudo_container.item_definition_id, &pseudo_container.stack_size, &pseudo_container.position, - &pseudo_container.durability, + &pseudo_container.properties, ])?; } drop(stmt); @@ -531,7 +531,7 @@ pub fn create_character( item_definition_id, stack_size, position, - durability) + properties) VALUES (?1, ?2, ?3, ?4, ?5, ?6)", )?; @@ -542,7 +542,7 @@ pub fn create_character( &item.model.item_definition_id, &item.model.stack_size, &item.model.position, - &item.model.durability, + &item.model.properties, ])?; } drop(stmt); @@ -1060,7 +1060,7 @@ pub fn update( item_definition_id, stack_size, position, - durability) + properties) VALUES (?1, ?2, ?3, ?4, ?5, ?6)", )?; @@ -1071,7 +1071,7 @@ pub fn update( &item.item_definition_id, &item.stack_size, &item.position, - &item.durability, + &item.properties, ])?; } } diff --git a/server/src/persistence/character/conversions.rs b/server/src/persistence/character/conversions.rs index 012c70b420..dbeb0eab61 100644 --- a/server/src/persistence/character/conversions.rs +++ b/server/src/persistence/character/conversions.rs @@ -5,7 +5,10 @@ use crate::persistence::{ use crate::persistence::{ error::PersistenceError, - json_models::{self, CharacterPosition, DatabaseAbilitySet, GenericBody, HumanoidBody}, + json_models::{ + self, CharacterPosition, DatabaseAbilitySet, DatabaseItemProperties, GenericBody, + HumanoidBody, + }, }; use common::{ character::CharacterId, @@ -165,6 +168,8 @@ pub fn convert_items_to_database_items( bfs_queue.push_back((format!("component_{}", i), Some(component), item_id)); } + let item_properties = json_models::item_properties_to_db_model(item); + let upsert = ItemModelPair { model: Item { item_definition_id: String::from(item.persistence_item_id()), @@ -176,7 +181,8 @@ pub fn convert_items_to_database_items( } else { 1 }, - durability: item.persistence_durability(), + properties: serde_json::to_string(&item_properties) + .expect("We probably want to crash if this gets triggered?"), }, // Continue to remember the atomic, in case we detect an error later and want // to roll back to preserve liveness. @@ -360,7 +366,10 @@ pub fn convert_inventory_from_database_items( item_indices.insert(db_item.item_id, i); let mut item = get_item_from_asset(db_item.item_definition_id.as_str())?; - item.persistence_set_durability(db_item.durability); + let item_properties = + serde_json::de::from_str::(&db_item.properties) + .expect("We probably want to crash if this gets triggered?"); + json_models::apply_db_item_properties(&mut item, &item_properties); // NOTE: Since this is freshly loaded, the atomic is *unique.* let comp = item.get_item_id_for_database(); @@ -462,7 +471,10 @@ pub fn convert_loadout_from_database_items( item_indices.insert(db_item.item_id, i); let mut item = get_item_from_asset(db_item.item_definition_id.as_str())?; - item.persistence_set_durability(db_item.durability); + let item_properties = + serde_json::de::from_str::(&db_item.properties) + .expect("We probably want to crash if this gets triggered?"); + json_models::apply_db_item_properties(&mut item, &item_properties); // NOTE: item id is currently *unique*, so we can store the ID safely. let comp = item.get_item_id_for_database(); diff --git a/server/src/persistence/json_models.rs b/server/src/persistence/json_models.rs index 5d0ba9b3ef..ac25843172 100644 --- a/server/src/persistence/json_models.rs +++ b/server/src/persistence/json_models.rs @@ -285,3 +285,20 @@ pub fn active_abilities_from_db_model( .collect::>(); comp::ability::ActiveAbilities::new(ability_sets) } + +#[derive(Serialize, Deserialize)] +pub struct DatabaseItemProperties { + #[serde(skip_serializing_if = "Option::is_none")] + durability: Option, +} + +pub fn item_properties_to_db_model(item: &comp::Item) -> DatabaseItemProperties { + DatabaseItemProperties { + durability: item.durability(), + } +} + +pub fn apply_db_item_properties(item: &mut comp::Item, properties: &DatabaseItemProperties) { + let DatabaseItemProperties { durability } = properties; + item.persistence_set_durability(*durability); +} diff --git a/server/src/persistence/models.rs b/server/src/persistence/models.rs index 1a82963cda..df1487422b 100644 --- a/server/src/persistence/models.rs +++ b/server/src/persistence/models.rs @@ -12,7 +12,7 @@ pub struct Item { pub item_definition_id: String, pub stack_size: i32, pub position: String, - pub durability: Option, + pub properties: String, } pub struct Body {