working on character stuff
This commit is contained in:
parent
50976d0f3f
commit
5cdfe71528
5 changed files with 48 additions and 2 deletions
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
shit that needs to be done with characters handling:
|
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?)
|
[ ] view character list (all pc characters i think, or maybe only scene available characters?)
|
||||||
[ ] get character info
|
[ ] get character info
|
||||||
[ ] set character info
|
[ ] set character info
|
||||||
|
|
|
@ -45,6 +45,7 @@ pub enum Response {
|
||||||
GetChatHistory(Vec<ChatMessage>),
|
GetChatHistory(Vec<ChatMessage>),
|
||||||
MoveToken { token_id: usize, x: f32, y: f32 },
|
MoveToken { token_id: usize, x: f32, y: f32 },
|
||||||
SpawnToken(SpawnToken),
|
SpawnToken(SpawnToken),
|
||||||
|
|
||||||
Quit { id: String },
|
Quit { id: String },
|
||||||
Shutdown,
|
Shutdown,
|
||||||
|
|
||||||
|
|
|
@ -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<String>,
|
||||||
|
/// health, can be a number but is a string to allow stuff as `wounded`/`unharmed`
|
||||||
|
pub health: Option<String>,
|
||||||
|
pub level: Option<i32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum EntryType {
|
pub enum EntryType {
|
||||||
Number(i32),
|
Number(i32),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Game Parser and Data types
|
//! Game Parser and Data types
|
||||||
use std::{collections::HashMap, marker::PhantomData};
|
use std::{collections::HashMap, marker::PhantomData};
|
||||||
|
|
||||||
use character_sheet::Character;
|
use character_sheet::{AccessLevel, Character, CharacterShort, EntryType};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod character_sheet;
|
pub mod character_sheet;
|
||||||
|
@ -13,6 +13,9 @@ pub trait GameImpl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
/// Creates a new character, returning the character id
|
/// Creates a new character, returning the character id
|
||||||
fn create_character(&mut self) -> usize;
|
fn create_character(&mut self) -> usize;
|
||||||
|
fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec<Option<(String, EntryType)>>;
|
||||||
|
fn characters(&self) -> Vec<usize>;
|
||||||
|
fn character_short(&self, character_id: usize) -> Option<CharacterShort>;
|
||||||
fn create_token(&mut self, map_id: usize, character: String, img_source: String, x: f32, y: f32) -> usize;
|
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 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>;
|
fn token_info(&self, map_id: usize, token_id: usize) -> Option<&TokenInfo>;
|
||||||
|
@ -71,6 +74,24 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
||||||
self.tokens.insert(id, TokenInfo { character, map_id, img_source, x, y });
|
self.tokens.insert(id, TokenInfo { character, map_id, img_source, x, y });
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec<Option<(String, EntryType)>> {
|
||||||
|
self.characters
|
||||||
|
.get(character_id)
|
||||||
|
.map(|c| c.display(access))
|
||||||
|
.unwrap_or(Vec::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn characters(&self) -> Vec<usize> {
|
||||||
|
// 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<CharacterShort> {
|
||||||
|
// self.characters.get(character_id).map(|c| c.char)
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
|
@ -162,6 +162,7 @@ impl GameServer {
|
||||||
if self.users.get(&id).map(|a| *a).unwrap_or(false) {
|
if self.users.get(&id).map(|a| *a).unwrap_or(false) {
|
||||||
let new_id = self.game.create_character();
|
let new_id = self.game.create_character();
|
||||||
// return the new id with the character i think
|
// return the new id with the character i think
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
api::Request::Quit => {
|
api::Request::Quit => {
|
||||||
|
|
Loading…
Reference in a new issue