diff --git a/gavania-core/src/game/content/objects/hero.rs b/gavania-core/src/game/content/objects/hero.rs index c4ea0a8..7c86777 100644 --- a/gavania-core/src/game/content/objects/hero.rs +++ b/gavania-core/src/game/content/objects/hero.rs @@ -77,7 +77,6 @@ impl ComponentDebug for MainUser { #[derive(Clone)] pub struct Hero { name: String, - entity: Entity, } diff --git a/rpg_components/src/config/save_game.rs b/rpg_components/src/config/save_game.rs index 06d2903..dd1cd2d 100644 --- a/rpg_components/src/config/save_game.rs +++ b/rpg_components/src/config/save_game.rs @@ -1,8 +1,18 @@ +use anyhow::Result; use engine::prelude::*; -use crate::items::{ItemAffix, Rarities}; +use crate::{ + components::{ + ability_slots::AbilitySlots, attributes::Attributes, character_status::CharacterStatus, + crafting_materials::CraftingMaterials, inventory::Inventory, item_slots::ItemSlotContainer, + level::Level, statistics::Statistics, + }, + items::{ItemAffix, ItemSystem, Rarities}, +}; -use std::env::var; +use std::{env::var, sync::Arc}; + +use super::{attributes::AttributeSettings, experience::ExperienceSettings}; #[cfg(target_os = "windows")] pub fn save_game_dir(game: &str) -> String { @@ -347,3 +357,44 @@ create_settings_container!( passives: PassivesInfo, } ); + +impl SaveGame { + pub fn to_entity_object(self, engine: &Engine) -> Result { + let scene = engine.scene_mut(); + + let experience_settings = scene.resources.get::(); + let attribute_settings = scene.resources.get::(); + let item_system = scene.resources.get::>(); + + let mut entity_object = engine.assets().empty_entity(); + + entity_object.insert_component(Draw::new(Vec::new())); + entity_object.insert_component(Audio::new(engine.context(), None)?); + Location::new_and_setup(&mut entity_object); + + let level = Level::load(self.general.level, self.general.exp, experience_settings); + let mut attributes = Attributes::load( + self.general.strength, + self.general.agility, + self.general.intelligence, + ); + let inventory = Inventory::load(&self, &item_system)?; + let abilities = AbilitySlots::load(item_system.clone(), &self)?; + let crafting_materials = CraftingMaterials::load(&self); + let items = ItemSlotContainer::load()?; + let mut statistics = Statistics::default(); + statistics.update(&mut attributes, attribute_settings, &items); + let current_status = CharacterStatus::new_full(&statistics); + + entity_object.insert_component(level); + entity_object.insert_component(attributes); + entity_object.insert_component(inventory); + entity_object.insert_component(abilities); + entity_object.insert_component(crafting_materials); + entity_object.insert_component(items); + entity_object.insert_component(statistics); + entity_object.insert_component(current_status); + + scene.add_entity(entity_object) + } +}