From 5cdfe7152854b01ade3d054672b9f6c88b71fb5a Mon Sep 17 00:00:00 2001 From: Rusty Striker Date: Wed, 16 Oct 2024 12:41:41 +0300 Subject: [PATCH] working on character stuff --- readme.md | 2 +- src/api/mod.rs | 1 + src/game/character_sheet.rs | 23 +++++++++++++++++++++++ src/game/mod.rs | 23 ++++++++++++++++++++++- src/lib.rs | 1 + 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 3fac625..2e7d41f 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ shit that needs to be done with characters handling: -[ ] Create character: admins only +[x] Create character: admins only [ ] view character list (all pc characters i think, or maybe only scene available characters?) [ ] get character info [ ] set character info diff --git a/src/api/mod.rs b/src/api/mod.rs index 45a0e5f..fc87804 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -45,6 +45,7 @@ pub enum Response { GetChatHistory(Vec), MoveToken { token_id: usize, x: f32, y: f32 }, SpawnToken(SpawnToken), + Quit { id: String }, Shutdown, diff --git a/src/game/character_sheet.rs b/src/game/character_sheet.rs index 27c5664..79f6bc6 100644 --- a/src/game/character_sheet.rs +++ b/src/game/character_sheet.rs @@ -40,6 +40,29 @@ impl AccessLevel { } } +/// Short character description to be shown in a simple small card, +/// any of the fields can be empty apart from title (as it makes no sense to omit that) +/// +/// following is a diagram of what it should look like (dots are part of title), tho actual looks depend +/// on the clients themselves +/// +/// ```text +/// _______________________ +/// | TITLE ... level | +/// | ......... | +/// | sub_title health | +/// |_______________________| +/// ``` +pub struct CharacterShort { + /// Main title, usually the name + pub title: String, + /// little title under the main title, probably a title or class + pub sub_title: Option, + /// health, can be a number but is a string to allow stuff as `wounded`/`unharmed` + pub health: Option, + pub level: Option, +} + #[derive(Debug, Serialize, Deserialize)] pub enum EntryType { Number(i32), diff --git a/src/game/mod.rs b/src/game/mod.rs index 3bd0ce5..73916f7 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -1,7 +1,7 @@ //! Game Parser and Data types use std::{collections::HashMap, marker::PhantomData}; -use character_sheet::Character; +use character_sheet::{AccessLevel, Character, CharacterShort, EntryType}; use serde::{Deserialize, Serialize}; pub mod character_sheet; @@ -13,6 +13,9 @@ pub trait GameImpl<'a, C: Character + Serialize + Deserialize<'a>, A: entry:: fn new() -> Self; /// Creates a new character, returning the character id fn create_character(&mut self) -> usize; + fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec>; + fn characters(&self) -> Vec; + fn character_short(&self, character_id: usize) -> Option; fn create_token(&mut self, map_id: usize, character: String, img_source: String, x: f32, y: f32) -> usize; fn move_token(&mut self, map_id: usize, token_id: usize, x: f32, y: f32) -> bool; fn token_info(&self, map_id: usize, token_id: usize) -> Option<&TokenInfo>; @@ -71,6 +74,24 @@ impl<'a, C: Character + Serialize + Deserialize<'a>, A: entry::GameEntry + Se self.tokens.insert(id, TokenInfo { character, map_id, img_source, x, y }); id } + + fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec> { + self.characters + .get(character_id) + .map(|c| c.display(access)) + .unwrap_or(Vec::new()) + } + + fn characters(&self) -> Vec { + // this is stupid i should redo the characters data struct to actually have ids rather than use an index + // (as deletion of a character f-s up the ids) + (0_usize..self.characters.len()).collect() + } + + fn character_short(&self, character_id: usize) -> Option { + // self.characters.get(character_id).map(|c| c.char) + todo!() + } } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/lib.rs b/src/lib.rs index 300e336..4ff6a0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,6 +162,7 @@ impl GameServer { if self.users.get(&id).map(|a| *a).unwrap_or(false) { let new_id = self.game.create_character(); // return the new id with the character i think + } }, api::Request::Quit => {