saveload system

localstorage isn't supported by wasm, so playing online will probably just not have save games for a while
This commit is contained in:
Llywelwyn 2023-07-09 12:09:30 +01:00
parent dd91a8cca7
commit 51060f1a85
11 changed files with 290 additions and 63 deletions

View file

@ -1,14 +1,26 @@
use rltk::RGB;
use serde::{Deserialize, Serialize};
use specs::error::NoError;
use specs::prelude::*;
use specs::saveload::{ConvertSaveload, Marker};
use specs_derive::*;
#[derive(Component)]
// Serialization helper code. We need to implement ConvertSaveload for each type that contains an
// Entity.
pub struct SerializeMe;
// Special component that exists to help serialize the game data
#[derive(Component, Serialize, Deserialize, Clone)]
pub struct SerializationHelper {
pub map: super::map::Map,
}
#[derive(Component, ConvertSaveload, Clone)]
pub struct Position {
pub x: i32,
pub y: i32,
}
#[derive(Component)]
#[derive(Component, ConvertSaveload, Clone)]
pub struct Renderable {
pub glyph: rltk::FontCharType,
pub fg: RGB,
@ -16,28 +28,28 @@ pub struct Renderable {
pub render_order: i32,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Player {}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Monster {}
#[derive(Component)]
#[derive(Component, ConvertSaveload, Clone)]
pub struct Viewshed {
pub visible_tiles: Vec<rltk::Point>,
pub range: i32,
pub dirty: bool,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct Name {
pub name: String,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct BlocksTile {}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct CombatStats {
pub max_hp: i32,
pub hp: i32,
@ -45,12 +57,12 @@ pub struct CombatStats {
pub power: i32,
}
#[derive(Component, Debug, Clone)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct WantsToMelee {
pub target: Entity,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct SufferDamage {
pub amount: Vec<i32>,
}
@ -66,63 +78,63 @@ impl SufferDamage {
}
}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Item {}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct ProvidesHealing {
pub amount: i32,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct InflictsDamage {
pub amount: i32,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct Ranged {
pub range: i32,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct AOE {
pub radius: i32,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload, Clone)]
pub struct Confusion {
pub turns: i32,
}
#[derive(Component, Debug, Clone)]
#[derive(Component, Debug, ConvertSaveload)]
pub struct InBackpack {
pub owner: Entity,
}
#[derive(Component, Debug, Clone)]
#[derive(Component, Debug, ConvertSaveload)]
pub struct WantsToPickupItem {
pub collected_by: Entity,
pub item: Entity,
}
#[derive(Component, Debug, Clone)]
#[derive(Component, Debug, ConvertSaveload)]
pub struct WantsToDropItem {
pub item: Entity,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, ConvertSaveload)]
pub struct WantsToUseItem {
pub item: Entity,
pub target: Option<rltk::Point>,
}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Consumable {}
#[derive(Component, Debug)]
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
pub struct Destructible {}
#[derive(Component, Clone)]
#[derive(Component, Clone, ConvertSaveload)]
pub struct ParticleLifetime {
pub lifetime_ms: f32,
}