+// pieces
use crate::imports::*;
}
}
-#[derive(Serialize,Deserialize)]
-#[derive(Debug,Default)]
-#[repr(transparent)]
-struct ColourSpec(String);
-
-impl TryFrom<&ColourSpec> for Colour {
- type Error = SE;
- #[throws(SE)]
- fn try_from(spec: &ColourSpec) -> Colour {
- // xxx check syntax
- spec.0.clone()
- }
-}
-
-#[derive(Debug,Serialize,Deserialize)]
-struct Disc {
- diam : Coord,
- faces : IndexVec<FaceId,ColourSpec>,
-}
-
-#[derive(Debug,Serialize,Deserialize)]
-struct Square {
- size : Vec<Coord>,
- faces : IndexVec<FaceId,ColourSpec>,
-}
-
#[throws(GameError)]
fn simple_resolve_spec_face(faces: &IndexSlice<FaceId,[ColourSpec]>,
face: Option<FaceId>)
}
#[typetag::serde]
-impl PieceSpec for Disc {
+impl PieceSpec for piece_specs::Disc {
#[throws(SE)]
fn load(&self) -> Box<dyn Piece> {
let unit_path =
}
#[typetag::serde]
-impl PieceSpec for Square {
+impl PieceSpec for piece_specs::Square {
#[throws(SE)]
fn load(&self) -> Box<dyn Piece> {
let (x, y) = match *self.size.as_slice() {
simple_resolve_spec_face(&self.faces, face)?
}
}
-
-#[allow(clippy::type_complexity)]
-pub fn xxx_make_pieces() -> Result<Vec<(Pos, Box<dyn Piece>)>,SE> {
- Ok(vec![
- ([ 90, 80 ],
- Disc {
- diam : 20,
- faces : index_vec![ ColourSpec("red".to_string()), ColourSpec("grey".to_string()) ],
- }.load()?),
- ([ 90, 60 ],
- Square {
- size : vec![20],
- faces : index_vec![ ColourSpec("blue".to_string()), ColourSpec("grey".to_string()) ],
- }.load()?),
- ])
-}
use serde::{Serialize,Deserialize};
use fehler::throws;
-use index_vec::define_index_type;
+use index_vec::{define_index_type,IndexVec,index_vec};
use crate::gamestate::PieceSpec;
use std::fmt::Debug;
use implementation::PlayerAccessSpec;
pub struct FaceId = u8;
}
+#[derive(Serialize,Deserialize)]
+#[derive(Debug,Default)]
+#[repr(transparent)]
+pub struct ColourSpec(String);
+
//---------- Table TOML file ----------
#[derive(Debug,Serialize,Deserialize)]
pub count : Option<u32>,
pub face : Option<FaceId>,
#[serde(flatten)]
- pub info : Box<dyn PieceSpec>, // see pieces.rs
+ pub info : Box<dyn PieceSpec>,
+}
+
+//---------- Piece specs ----------
+// the implementations are in pieces.rs
+
+pub mod piece_specs {
+ use super::*;
+
+ #[derive(Debug,Serialize,Deserialize)]
+ pub struct Disc {
+ pub diam : Coord,
+ pub faces : IndexVec<FaceId,ColourSpec>,
+ }
+
+ #[derive(Debug,Serialize,Deserialize)]
+ pub struct Square {
+ pub size : Vec<Coord>,
+ pub faces : IndexVec<FaceId,ColourSpec>,
+ }
+
}
-//---------- Implementation ----------
+//---------- Implementation ----------
mod implementation {
use super::*;
use crate::imports::*;
type Insn = crate::commands::MgmtGameInstruction;
+ type SE = SVGProcessingError;
#[typetag::serde(tag="access")]
pub trait PlayerAccessSpec : Debug {
}
}
}
+
+ impl TryFrom<&ColourSpec> for Colour {
+ type Error = SE;
+ #[throws(SE)]
+ fn try_from(spec: &ColourSpec) -> Colour {
+ // xxx check syntax
+ spec.0.clone()
+ }
+ }
+}
+
+#[allow(clippy::type_complexity)]
+pub fn xxx_make_pieces() -> Result<Vec<(Pos, Box<dyn crate::gamestate::Piece>)>,crate::pieces::SVGProcessingError> {
+ use crate::imports::*;
+ Ok(vec![
+ ([ 90, 80 ],
+ piece_specs::Disc {
+ diam : 20,
+ faces : index_vec![ ColourSpec("red".to_string()), ColourSpec("grey".to_string()) ],
+ }.load()?),
+ ([ 90, 60 ],
+ piece_specs::Square {
+ size : vec![20],
+ faces : index_vec![ ColourSpec("blue".to_string()), ColourSpec("grey".to_string()) ],
+ }.load()?),
+ ])
}