From 15431e7f7a4717cf979797eac5eb99bb3efc9cc5 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Wed, 23 Feb 2022 13:35:04 +0200 Subject: [PATCH] Dummy implementation for EntityConfig migration --- common/src/bin/asset_migrate.rs | 60 ++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/common/src/bin/asset_migrate.rs b/common/src/bin/asset_migrate.rs index 7ce50d5264..963a3eeed1 100644 --- a/common/src/bin/asset_migrate.rs +++ b/common/src/bin/asset_migrate.rs @@ -5,25 +5,37 @@ use std::{ io::Write, path::{Path, PathBuf}, }; -use veloren_common::comp::inventory::{ - loadout_builder::ItemSpec, - slot::{ArmorSlot, EquipSlot}, -}; +use veloren_common::comp::inventory::slot::{ArmorSlot, EquipSlot}; /// Old version. -mod v1 { +mod loadout_v1 { use super::*; pub type Config = LoadoutSpec; + #[derive(Debug, Deserialize, Serialize, Clone)] + pub enum ItemSpec { + /// One specific item. + /// Example: + /// Item("common.items.armor.steel.foot") + Item(String), + /// Choice from items with weights. + /// Example: + /// Choice([ + /// (1.0, Some(Item("common.items.lantern.blue_0"))), + /// (1.0, None), + /// ]) + Choice(Vec<(f32, Option)>), + } + #[derive(Debug, Deserialize, Clone)] pub struct LoadoutSpec(pub HashMap); } /// New version. -mod v2 { - use super::*; +mod loadout_v2 { + use super::{loadout_v1::ItemSpec, *}; - type OldConfig = super::v1::Config; + type OldConfig = super::loadout_v1::Config; pub type Config = LoadoutSpecNew; type Weight = u8; @@ -131,7 +143,7 @@ mod v2 { impl From for Config { fn from(old: OldConfig) -> Self { - let super::v1::LoadoutSpec(old) = old; + let super::loadout_v1::LoadoutSpec(old) = old; let to_new_item = |slot: &EquipSlot| -> Option { old.get(slot).cloned().map(|i| i.into()) }; @@ -176,6 +188,29 @@ mod v2 { } } +mod v1 { + use super::*; + pub type Config = EntityConfig; + + #[derive(Debug, Deserialize, Clone)] + pub struct EntityConfig; +} + +mod v2 { + use super::*; + pub type OldConfig = super::v1::Config; + pub type Config = EntityConfig; + + #[derive(Debug, Deserialize, Serialize, Clone, Default)] + pub struct EntityConfig; + + impl From for Config { + fn from(old: OldConfig) -> Self { + Self::default() + } + } +} + #[derive(Debug)] enum Walk { File(PathBuf), @@ -213,8 +248,7 @@ where OldV: DeserializeOwned, NewV: Serialize, { - use std::io::BufReader; - use std::io::BufRead; + use std::io::{BufRead, BufReader}; match tree { Walk::Dir { path, content } => { let target_dir = to.join(path); @@ -243,8 +277,8 @@ where // Write it all back let pretty_config = ron::ser::PrettyConfig::new() .extensions(ron::extensions::Extensions::IMPLICIT_SOME); - let config_string = ron::ser::to_string_pretty(&new, pretty_config) - .expect("serialize shouldn't fail"); + let config_string = + ron::ser::to_string_pretty(&new, pretty_config).expect("serialize shouldn't fail"); let comments_string = comments.join("\n"); let mut target = fs::File::create(to.join(&path))?;