2024-08-26 10:57:01 +00:00
|
|
|
use anyhow::Result;
|
2024-08-23 11:22:09 +00:00
|
|
|
use engine::prelude::*;
|
|
|
|
|
2024-08-26 10:57:01 +00:00
|
|
|
use crate::{
|
|
|
|
components::{
|
|
|
|
ability_slots::AbilitySlots, attributes::Attributes, character_status::CharacterStatus,
|
|
|
|
crafting_materials::CraftingMaterials, inventory::Inventory, item_slots::ItemSlotContainer,
|
|
|
|
level::Level, statistics::Statistics,
|
|
|
|
},
|
2025-02-28 07:39:15 +00:00
|
|
|
items::{ItemAffix, ItemSystem, Rarities, ability_book::Ability},
|
2024-08-26 10:57:01 +00:00
|
|
|
};
|
2024-08-23 11:22:09 +00:00
|
|
|
|
2024-08-26 13:44:19 +00:00
|
|
|
use std::env::var;
|
2024-08-26 10:57:01 +00:00
|
|
|
|
2024-08-26 11:29:24 +00:00
|
|
|
use super::{attributes::AttributeSettings, experience::ExperienceSettings, items::ItemSettings};
|
2024-08-23 11:22:09 +00:00
|
|
|
|
|
|
|
#[cfg(target_os = "windows")]
|
2024-08-24 13:36:58 +00:00
|
|
|
pub fn save_game_dir(game: &str) -> String {
|
2024-08-23 11:22:09 +00:00
|
|
|
let b = var("LOCALAPPDATA").expect("couldn't get local appdata variable");
|
|
|
|
|
2024-08-24 13:36:58 +00:00
|
|
|
format!("{b}\\{game}\\saves\\")
|
2024-08-23 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
2024-08-24 13:36:58 +00:00
|
|
|
pub fn save_game_dir(game: &str) -> String {
|
2024-08-23 11:22:09 +00:00
|
|
|
let b = var("HOME").expect("couldn't get HOME variable");
|
|
|
|
|
2024-08-24 13:36:58 +00:00
|
|
|
format!("{b}/.local/share/{game}/saves/")
|
2024-08-23 11:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
General,
|
|
|
|
"General",
|
|
|
|
{
|
|
|
|
level: u32,
|
|
|
|
exp: u32,
|
|
|
|
name: String,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
HelmetSlot,
|
|
|
|
"Helmet",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
ChestPlateSlot,
|
|
|
|
"ChestPlate",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
BeltSlot,
|
|
|
|
"Belt",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
GlovesSlot,
|
|
|
|
"Gloves",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
BootsSlot,
|
|
|
|
"Boots",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
FirstRingSlot,
|
|
|
|
"Ring0",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
SecondRingSlot,
|
|
|
|
"Ring1",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
ThirdRingSlot,
|
|
|
|
"Ring2",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
FourthRingSlot,
|
|
|
|
"Ring3",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
FirstAmuletSlot,
|
|
|
|
"Amulet0",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
SecondAmuletSlot,
|
|
|
|
"Amulet1",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
MainHandSlot,
|
|
|
|
"MainHand",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
OffHandSlot,
|
|
|
|
"OffHand",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
level: u32,
|
|
|
|
strength: u32,
|
|
|
|
agility: u32,
|
|
|
|
intelligence: u32,
|
|
|
|
rarity: Rarities,
|
|
|
|
[affixes: ItemAffix],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
InventorySave,
|
|
|
|
"Inventory",
|
|
|
|
{
|
|
|
|
[items: String],
|
|
|
|
[addons: String],
|
|
|
|
[books: String],
|
|
|
|
[jewels: String],
|
|
|
|
[maps: String],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
FirstAbilitySlot,
|
|
|
|
"FirstAbilitySlot",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
name: String,
|
|
|
|
rarity: Rarities,
|
|
|
|
level: u32,
|
|
|
|
[addons: String],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
SecondAbilitySlot,
|
|
|
|
"SecondAbilitySlot",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
name: String,
|
|
|
|
rarity: Rarities,
|
|
|
|
level: u32,
|
|
|
|
[addons: String],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
ThirdAbilitySlot,
|
|
|
|
"ThirdAbilitySlot",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
name: String,
|
|
|
|
rarity: Rarities,
|
|
|
|
level: u32,
|
|
|
|
[addons: String],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
FourthAbilitySlot,
|
|
|
|
"FourthAbilitySlot",
|
|
|
|
{
|
|
|
|
used: bool,
|
|
|
|
name: String,
|
|
|
|
rarity: Rarities,
|
|
|
|
level: u32,
|
|
|
|
[addons: String],
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
CraftingMaterialInfo,
|
|
|
|
"CraftingMaterials",
|
|
|
|
{
|
|
|
|
common: u32,
|
|
|
|
uncommon: u32,
|
|
|
|
magical: u32,
|
|
|
|
rare: u32,
|
|
|
|
epic: u32,
|
|
|
|
legendary: u32,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_section!(
|
|
|
|
PassivesInfo,
|
|
|
|
"Passives",
|
|
|
|
{
|
|
|
|
blood_mage: u32,
|
|
|
|
vampire: u32,
|
|
|
|
hermes: u32,
|
|
|
|
thick_skinned: u32,
|
|
|
|
super_brain: u32,
|
|
|
|
survivalist: u32,
|
|
|
|
soul_catcher: u32,
|
|
|
|
pyromancer: u32,
|
|
|
|
thunder_god: u32,
|
|
|
|
sea_monster: u32,
|
|
|
|
gladiator: u32,
|
|
|
|
lucky_devil: u32,
|
|
|
|
rogue: u32,
|
|
|
|
alchemist: u32,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
create_settings_container!(
|
|
|
|
SaveGame,
|
|
|
|
{
|
|
|
|
general: General,
|
|
|
|
|
|
|
|
// items
|
|
|
|
helmet: HelmetSlot,
|
|
|
|
chest_plate: ChestPlateSlot,
|
|
|
|
belt: BeltSlot,
|
|
|
|
gloves: GlovesSlot,
|
|
|
|
boots: BootsSlot,
|
|
|
|
|
|
|
|
// rings
|
|
|
|
ring_0: FirstRingSlot,
|
|
|
|
ring_1: SecondRingSlot,
|
|
|
|
ring_2: ThirdRingSlot,
|
|
|
|
ring_3: FourthRingSlot,
|
|
|
|
|
|
|
|
// amulets
|
|
|
|
amulet_0: FirstAmuletSlot,
|
|
|
|
amulet_1: SecondAmuletSlot,
|
|
|
|
|
|
|
|
// hands
|
|
|
|
main_hand: MainHandSlot,
|
|
|
|
off_hand: OffHandSlot,
|
|
|
|
|
|
|
|
// inventory
|
|
|
|
inventory: InventorySave,
|
|
|
|
|
|
|
|
// abilities
|
|
|
|
ability_0: FirstAbilitySlot,
|
|
|
|
ability_1: SecondAbilitySlot,
|
|
|
|
ability_2: ThirdAbilitySlot,
|
|
|
|
ability_3: FourthAbilitySlot,
|
|
|
|
|
|
|
|
crafting_materials: CraftingMaterialInfo,
|
|
|
|
|
|
|
|
passives: PassivesInfo,
|
|
|
|
}
|
|
|
|
);
|
2024-08-26 10:57:01 +00:00
|
|
|
|
|
|
|
impl SaveGame {
|
2024-08-27 12:06:06 +00:00
|
|
|
pub fn to_entity_object<A: Ability + 'static>(
|
|
|
|
self,
|
2025-02-28 07:39:15 +00:00
|
|
|
world: &mut World,
|
2024-08-27 12:06:06 +00:00
|
|
|
) -> Result<(Entity, String)> {
|
2025-02-28 07:39:15 +00:00
|
|
|
let mut entity_object = AssetHandler::create(world).empty_entity();
|
2024-08-26 10:57:01 +00:00
|
|
|
|
|
|
|
entity_object.insert_component(Draw::new(Vec::new()));
|
2025-02-28 07:39:15 +00:00
|
|
|
entity_object.insert_component(Audio::new(world.resources.get_mut::<Context>(), None)?);
|
2024-08-26 11:29:24 +00:00
|
|
|
Location::new_and_setup(&mut entity_object)?;
|
2024-08-26 10:57:01 +00:00
|
|
|
|
2025-02-28 07:39:15 +00:00
|
|
|
let experience_settings = world.resources.get::<ExperienceSettings>();
|
|
|
|
let attribute_settings = world.resources.get::<AttributeSettings>();
|
|
|
|
let item_settings = world.resources.get::<ItemSettings>();
|
|
|
|
let item_system = world.resources.get::<ItemSystem<A>>();
|
|
|
|
|
2024-08-26 10:57:01 +00:00
|
|
|
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)?;
|
2024-08-26 13:44:19 +00:00
|
|
|
let abilities = AbilitySlots::load(item_system, &self)?;
|
2024-08-26 10:57:01 +00:00
|
|
|
let crafting_materials = CraftingMaterials::load(&self);
|
2024-08-26 11:29:24 +00:00
|
|
|
let items = ItemSlotContainer::load(&self, &item_system)?;
|
2024-08-26 10:57:01 +00:00
|
|
|
let mut statistics = Statistics::default();
|
2024-08-26 11:29:24 +00:00
|
|
|
statistics.update(&mut attributes, attribute_settings, (&items, item_settings));
|
2024-08-26 10:57:01 +00:00
|
|
|
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);
|
|
|
|
|
2025-02-28 07:39:15 +00:00
|
|
|
Ok((world.add_entity(entity_object)?, self.general.name))
|
2024-08-26 10:57:01 +00:00
|
|
|
}
|
|
|
|
}
|