use chrono::{ NaiveDate, NaiveDateTime }; use reactive_stores::Store; use crate::prelude::*; mod mock; #[derive(Clone, Debug, Store)] pub struct Item { pub name: String, pub weight: Option, pub rarity: Option, pub rest: Map, } impl Item { pub fn from_json (t: Value) -> Option { let Value::String(name) = t["name"].clone() else { return None }; let weight = match t["weight"].clone() { Value::Number(t) => t.as_f64(), Value::String(t) => t.parse().ok(), _ => None }; let rarity = if let Value::String(ref rarity) = t["rarity"] { Some(rarity.clone()) } else { None }; let Value::Object(rest) = t else { return None }; Some(Self { name, weight, rarity, rest }) } } #[derive(Clone, Debug, Store)] pub struct ItemReferenceMap (pub HashMap); #[derive(Clone, Debug, Store)] pub struct Dashboard { pub campaign: String, pub campaign_image: String, pub session: usize, pub date: NaiveDate, pub player: PlayerData, pub common: CommonData, pub quest_book: QuestBook, pub notes: NoteBook, pub people: ContactBook, } #[derive(Clone, Debug, Store)] pub struct PlayerData { pub first_name: String, pub last_name: String, pub alias: String, pub image: String, pub level: u8, pub xp: u32, pub temp_hp: u16, pub hp: u16, pub max_hp: u16, pub balance: Balance, pub spell_slots: SpellSlots, pub inventory: Inventory, // pub consumables: Consumables, pub attunements: Attunements, pub prepared: PreparedSpells, pub hit_dice: HitDice, pub death_save_throws: DeathSaveThrows, } #[derive(Clone, Debug, Store)] pub struct CommonData { pub balance: Balance, pub inventory: Inventory, } #[derive(Clone, Debug, Store)] pub struct Balance { pub platinum: u32, pub gold: u32, pub electrum: u32, pub silver: u32, pub copper: u32, } #[derive(Clone, Debug, Store)] pub struct Inventory (pub Vec); #[derive(Clone, Debug, Store)] pub struct InventoryEntry { pub quantity: u32, pub item: InventoryItem, } #[derive(Clone, Debug, Store)] pub enum InventoryItem { Custom (CustomInventoryItem), Book (Item), } #[derive(Clone, Debug, Store)] pub struct CustomInventoryItem { pub name: String, pub weight: Option, pub description: Option, pub tags: HashMap, } #[derive(Clone, Debug, Store)] pub struct QuestBook (pub Vec); #[derive(Clone, Debug, Store)] pub struct Quest { pub title: String, pub location_taken: Option, pub location_task: Option, pub date_taken: Option, pub date_by: Option, pub description: Option, pub from: Option, pub reward: Option, } #[derive(Clone, Debug, Store)] pub struct NoteBook (pub Vec); #[derive(Clone, Debug, Store)] pub struct Note { pub content: String, pub date_ingame: NaiveDate, pub date_real: NaiveDateTime, pub session: usize, pub tags: HashSet, } #[derive(Clone, Debug, Store)] pub struct SpellSlots (pub [SpellSlotLevel; 9]); #[derive(Clone, Debug, Store)] pub struct SpellSlotLevel { pub used: u8, pub total: u8, } #[derive(Clone, Debug, Store)] pub struct Attunements (pub [Option; 3]); #[derive(Clone, Debug, Store)] pub struct PreparedSpells (pub Vec); // @TODO #[derive(Clone, Debug, Store)] pub struct Spell { pub name: String } #[derive(Clone, Debug, Store)] pub struct HitDice { pub used: u8, pub total: u8, } #[derive(Clone, Debug, Store)] pub struct DeathSaveThrows { pub failed: u8, pub succeeded: u8, } #[derive(Clone, Debug, Store)] pub struct ContactBook (pub HashMap); #[derive(Clone, Debug, Store)] pub struct Contact { pub name: String, pub image: Option, pub alias: Option, pub status: Option, pub location: Option, pub notes: Option, } #[derive(Clone, Debug, Store)] pub enum ContactStatus { Unknown, DeadBygone, Dead, Alive, }