aex/src/entities/mod.rs

209 lines
4.4 KiB
Rust

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<f64>,
pub rarity: Option<String>,
pub rest: Map<String, Value>,
}
impl Item {
pub fn from_json (t: Value) -> Option<Self> {
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<String, Item>);
#[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 name: Name,
pub class: 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<InventoryEntry>);
#[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<f32>,
pub description: Option<String>,
pub tags: HashMap<String, String>,
}
#[derive(Clone, Debug, Store)]
pub struct QuestBook (pub Vec<Quest>);
#[derive(Clone, Debug, Store)]
pub struct Quest {
pub title: String,
pub location_taken: Option<String>,
pub location_task: Option<String>,
pub date_taken: Option<NaiveDate>,
pub date_by: Option<NaiveDate>,
pub description: Option<String>,
pub from: Option<Name>,
pub reward: Option<Balance>,
}
#[derive(Clone, Debug, Store)]
pub struct NoteBook (pub Vec<Note>);
#[derive(Clone, Debug, Store)]
pub struct Note {
pub content: String,
pub date_ingame: NaiveDate,
pub date_real: NaiveDateTime,
pub session: usize,
pub tags: HashSet<String>,
}
#[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<String>; 3]);
#[derive(Clone, Debug, Store)]
pub struct PreparedSpells (pub Vec<Spell>);
// @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<String, Contact>);
#[derive(Clone, Debug, Store)]
pub struct Contact {
pub name: Name,
pub image: Option<String>,
pub status: Option<ContactStatus>,
pub location: Option<String>,
pub notes: Option<String>,
}
#[derive(Clone, Debug, Store)]
pub enum ContactStatus {
Unknown,
DeadBygone,
Dead,
Alive,
}
#[derive(Clone, Debug, Store, Default)]
pub struct Name {
pub first: String,
pub last: String,
pub alias: String,
}
impl Name {
pub fn display_alias (&self) -> bool {
!self.alias.is_empty()
}
pub fn display_last (&self) -> bool {
!self.last.is_empty()
}
}