remove the GameImpl trait as it made no sense during development
This commit is contained in:
parent
529896a352
commit
295c9438af
2 changed files with 16 additions and 42 deletions
|
@ -10,40 +10,14 @@ pub mod chat_message;
|
|||
pub mod entry;
|
||||
pub mod scene;
|
||||
|
||||
pub trait GameImpl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>>
|
||||
{
|
||||
/// Creates a new game
|
||||
fn new() -> Self;
|
||||
|
||||
// Character management
|
||||
/// Creates a new character, returning the character id
|
||||
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>;
|
||||
// Scenes
|
||||
/// the list of available scenes
|
||||
fn scenes(&self) -> Vec<usize>;
|
||||
fn get_scene(&self, id: usize) -> Option<&Scene>;
|
||||
fn get_scene_mut(&mut self, id: usize) -> Option<&mut Scene>;
|
||||
fn create_scene(&mut self, title: String);
|
||||
fn scene_visible(&mut self, scene: usize, visible: bool);
|
||||
fn create_token(&mut self, scene_id: usize, character: String, img_source: String, x: f32, y: f32) -> usize;
|
||||
fn move_token(&mut self, scene_id: usize, token_id: usize, x: f32, y: f32) -> bool;
|
||||
fn token_info(&self, scene: usize, token_id: usize) -> Option<&TokenInfo>;
|
||||
fn available_tokens(&self, scene: usize) -> Vec<usize>;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Game<C: Character<A> + Serialize, A: entry::GameEntry + Serialize> {
|
||||
_a: PhantomData<A>,
|
||||
characters: Vec<(C, CharacterInfo)>,
|
||||
scenes: HashMap<usize, Scene>,
|
||||
}
|
||||
impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>>
|
||||
GameImpl<'a, C, A> for Game<C, A>
|
||||
{
|
||||
fn new() -> Self {
|
||||
impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Serialize + Deserialize<'a>> Game<C, A> {
|
||||
pub fn new() -> Self {
|
||||
let mut tokens = HashMap::new();
|
||||
tokens.insert(
|
||||
0,
|
||||
|
@ -98,11 +72,11 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
scenes,
|
||||
}
|
||||
}
|
||||
fn create_character(&mut self) -> usize {
|
||||
pub fn create_character(&mut self) -> usize {
|
||||
self.characters.push((C::default(), CharacterInfo::default()));
|
||||
self.characters.len() - 1
|
||||
}
|
||||
fn move_token(&mut self, scene: usize, token_id: usize, x: f32, y: f32) -> bool {
|
||||
pub fn move_token(&mut self, scene: usize, token_id: usize, x: f32, y: f32) -> bool {
|
||||
let token = self
|
||||
.scenes
|
||||
.get_mut(&scene)
|
||||
|
@ -118,7 +92,7 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
false
|
||||
}
|
||||
}
|
||||
fn token_info(&self, scene: usize, token_id: usize) -> Option<&TokenInfo> {
|
||||
pub fn token_info(&self, scene: usize, token_id: usize) -> Option<&TokenInfo> {
|
||||
let token = self
|
||||
.scenes
|
||||
.get(&scene)
|
||||
|
@ -129,7 +103,7 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
if let Some(ti) = token { Some(ti) } else { None }
|
||||
}
|
||||
|
||||
fn available_tokens(&self, scene: usize) -> Vec<usize> {
|
||||
pub fn available_tokens(&self, scene: usize) -> Vec<usize> {
|
||||
self.scenes
|
||||
.get(&scene)
|
||||
.map(|s| s.map.as_ref())
|
||||
|
@ -139,7 +113,7 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
.unwrap_or(Vec::new())
|
||||
}
|
||||
|
||||
fn create_token(&mut self, scene: usize, character: String, img_source: String, x: f32, y: f32) -> usize {
|
||||
pub fn create_token(&mut self, scene: usize, character: String, img_source: String, x: f32, y: f32) -> usize {
|
||||
let mut id = 0;
|
||||
let tokens = self
|
||||
.scenes
|
||||
|
@ -166,32 +140,32 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
}
|
||||
}
|
||||
|
||||
fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec<Option<(String, EntryType)>> {
|
||||
pub fn display_character(&self, character_id: usize, access: AccessLevel) -> Vec<Option<(String, EntryType)>> {
|
||||
self.characters
|
||||
.get(character_id)
|
||||
.map(|c| c.0.display(access))
|
||||
.unwrap_or(Vec::new())
|
||||
}
|
||||
|
||||
fn characters(&self) -> Vec<usize> {
|
||||
pub 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> {
|
||||
pub fn character_short(&self, character_id: usize) -> Option<CharacterShort> {
|
||||
self.characters.get(character_id).map(|c| c.0.short(character_id))
|
||||
}
|
||||
|
||||
fn scenes(&self) -> Vec<usize> {
|
||||
pub fn scenes(&self) -> Vec<usize> {
|
||||
self.scenes.keys().map(|k| *k).collect()
|
||||
}
|
||||
|
||||
fn get_scene(&self, id: usize) -> Option<&Scene> {
|
||||
pub fn get_scene(&self, id: usize) -> Option<&Scene> {
|
||||
self.scenes.get(&id)
|
||||
}
|
||||
|
||||
fn create_scene(&mut self, title: String) {
|
||||
pub fn create_scene(&mut self, title: String) {
|
||||
let id = self.scenes.keys().max().map(|k| k + 1).unwrap_or(0);
|
||||
self.scenes.insert(
|
||||
id,
|
||||
|
@ -204,13 +178,13 @@ impl<'a, C: Character<A> + Serialize + Deserialize<'a>, A: entry::GameEntry + Se
|
|||
);
|
||||
}
|
||||
|
||||
fn scene_visible(&mut self, scene: usize, visible: bool) {
|
||||
pub fn scene_visible(&mut self, scene: usize, visible: bool) {
|
||||
if let Some(scene) = self.scenes.get_mut(&scene) {
|
||||
scene.visible_to_users = visible;
|
||||
}
|
||||
}
|
||||
|
||||
fn get_scene_mut(&mut self, id: usize) -> Option<&mut Scene> {
|
||||
pub fn get_scene_mut(&mut self, id: usize) -> Option<&mut Scene> {
|
||||
self.scenes.get_mut(&id)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use api::game_actions::SpawnToken;
|
||||
use game::{
|
||||
Game, GameImpl,
|
||||
Game,
|
||||
chat_message::ChatMessage,
|
||||
entry::{ActionDefinition, DiceRoll},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue