fn svg(&self, pr : &PiecedRecord) -> SvgData;
}
-#[derive(Debug)]
-pub struct PieceRecord {
- pos : Pos,
- p : Rc<dyn Piece>,
- held : Option<PlayerRef>,
-}
-
struct PlayerRecord {
nick : String,
}
-#[derive(Debug)]
pub struct GameState {
- pub pieces : Vec<Rc<PieceRecord>>,
pub players : Vec<PlayerRecord>,
}
#[derive(Debug)]
struct Game {
gen : Counter,
- gs : GameState,
log : VecDeque<LogEntry>,
}
}
fn main() {
- global::xxx_global_setup();
+ xxx_global_setup();
let helmet = SpaceHelmet::default()
.enable(NoSniff::Enable)
--- /dev/null
+
+use crate::imports::*;
+
+slotmap::new_key_type!{
+ pub struct PieceId;
+}
+
+pub trait Piece : Send + Debug {
+}
+
+#[derive(Debug)]
+pub struct PieceRecord {
+ pos : Pos,
+ p : Box<dyn Piece>,
+ face : FaceId,
+ held : Option<UserId>,
+}
+
+#[derive(Debug)]
+pub struct GameState {
+ pub pieces : DenseSlotMap<PieceId,PieceRecord>,
+}
+
+pub fn xxx_gamestate_init() -> GameState {
+ let mut pieces = DenseSlotMap::with_key();
+ for (pos, p) in xxx_make_pieces() {
+ let pr = PieceRecord {
+ pos, p,
+ face : 0.into(),
+ held : None,
+ };
+ pieces.insert(pr);
+ }
+ GameState { pieces }
+}
pub struct Instance {
/* game state goes here */
pub users : DenseSlotMap<UserId,User>,
+ pub gs : GameState,
}
#[derive(Clone)]
pub fn xxx_global_setup() {
let i = Instance {
users : Default::default(),
+ gs : xxx_gamestate_init(),
};
let i = Arc::new(Mutex::new(i));
let mut ig = i.lock().unwrap();
pub use std::io;
pub use std::io::{BufReader,Read};
+pub use std::fmt::Debug;
pub use std::thread;
pub use std::time::Duration;
pub use std::sync::{Arc,Mutex,RwLock};
pub use rocket::response;
pub use slotmap::dense::{DenseSlotMap};
+pub use index_vec::{define_index_type,index_vec,IndexVec};
-pub use crate::global;
-pub use crate::global::{lookup_token,InstanceAccess,InstanceAccessDetails};
-pub use crate::global::{Client,ClientId};
+pub use crate::global::*;
+pub use crate::gamestate::*;
+pub use crate::pieces::*;
pub type E = anyhow::Error;
pub mod imports;
pub mod global;
+pub mod pieces;
+pub mod gamestate;
--- /dev/null
+
+use crate::imports::*;
+
+define_index_type! {
+ pub struct FaceId = u8;
+}
+
+#[derive(Debug)]
+struct SimpleShape {
+ shape : String,
+ colours : IndexVec<FaceId,Colour>,
+}
+
+impl Piece for SimpleShape {
+}
+
+pub fn xxx_make_pieces() -> Vec<(Pos, Box<dyn Piece>)> {
+ vec![
+ ([ 50, 80 ],
+ Box::new(SimpleShape {
+ shape : r#"<circle cx="0" cy="0" r="10"/>"#.to_owned(),
+ colours : index_vec![ "red".to_string(), "grey".to_string() ],
+ })),
+ ([ 50, 60 ],
+ Box::new(SimpleShape {
+ shape : r#"<rect x="-10" y="-10" width="20" height="20"/>"#.to_owned(),
+ colours : index_vec![ "blue".to_string(), "grey".to_string() ],
+ })),
+ ]
+}