Prepare save game conversion function

This commit is contained in:
hodasemi 2024-08-26 12:57:01 +02:00
parent fc19aad393
commit 53036fc3d0
2 changed files with 53 additions and 3 deletions

View file

@ -77,7 +77,6 @@ impl ComponentDebug for MainUser {
#[derive(Clone)]
pub struct Hero {
name: String,
entity: Entity,
}

View file

@ -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<Entity> {
let scene = engine.scene_mut();
let experience_settings = scene.resources.get::<ExperienceSettings>();
let attribute_settings = scene.resources.get::<AttributeSettings>();
let item_system = scene.resources.get::<Arc<ItemSystem>>();
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)
}
}