[[pieces]]
pos = [40, 40]
type = "Hand"
-shape.type = "Square"
-shape.size = [70,20]
-shape.faces = ["grey"]
-shape.edges = ["white"]
+edge = "white"
+colour = "grey"
+shape.type = "Rectangle"
+shape.xy = [70,20]
let mut f = File::open(&filename).context("open")?;
let mut buf = String::new();
f.read_to_string(&mut buf).context("read")?;
- let spec: T = toml_de::from_str(&buf).context("parse")?;
+ let tv: toml::Value = buf.parse().context("parse TOML")?;
+ dbg!(&tv);
+ let spec: T = toml_de::from_value(&tv).context("parse value")?;
Ok::<_,AE>(spec)
})().with_context(|| format!("read {} {:?}", T::WHAT, &filename))?
}
#[derive(Debug,Serialize,Deserialize)]
struct Hand {
- shape: SimpleShape,
+ shape: GenericSimpleShape<()>,
}
#[derive(Debug,Clone,Default,Serialize,Deserialize)]
impl PieceSpec for piece_specs::Hand {
#[throws(SpecError)]
fn load(&self, _: usize) -> Box<dyn Piece> {
- let (mut shape, common) = self.shape.load_raw()?;
- if common.itemname.is_some() {
- throw!(SpecError::ItemnameSpecifiedWhereForbidden);
- }
- if shape.nfaces() != 1 {
- throw!(SpecError::MultifacetedMagic);
- }
- shape.itemname = "magic-hand".to_string();
+ let common = SimpleCommon {
+ itemname: None,
+ faces: index_vec![ColourSpec(self.colour.clone())],
+ edges: self.edge.iter().cloned().collect(),
+ edge_width: self.edge_width,
+ };
+ let shape = GenericSimpleShape::new(
+ (),
+ self.shape.clone(),
+ "magic-hand",
+ &common)?;
Box::new(Hand {
shape,
}) as Box<dyn Piece>
#[derive(Debug,Serialize,Deserialize)]
// todo: this serialisation is rather large
-pub struct SimpleShape {
- pub desc: Html,
+pub struct GenericSimpleShape<Desc> {
+ pub desc: Desc,
colours: ColourMap,
#[serde(default)] pub edges: ColourMap,
#[serde(default="default_edge_width")] pub edge_width: f64,
pub itemname: String,
pub outline: OutlineRepr,
}
+pub type SimpleShape = GenericSimpleShape<Html>;
pub const SELECT_SCALE: f64 = 1.1;
-x*0.5, -y*0.5, x, y, -x))
}
-impl Outline for SimpleShape {
+impl<Desc> Outline for GenericSimpleShape<Desc>
+ where Desc: Debug + Send + Sync + 'static
+{
delegate! {
to self.outline {
fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64)
}
fn nfaces(&self) -> RawFaceId { self.count_faces().try_into().unwrap() }
- fn itemname(&self) -> &str { &self.itemname }
+ fn itemname(&self) -> &str { self.itemname() }
}
-impl SimpleShape {
- fn count_faces(&self) -> usize { max(self.colours.len(), self.edges.len()) }
+impl<Desc> GenericSimpleShape<Desc>
+ where Desc: Debug + Send + Sync + 'static
+{
+ pub fn count_faces(&self) -> usize {
+ max(self.colours.len(), self.edges.len())
+ }
+ pub fn itemname(&self) -> &str { &self.itemname }
#[throws(SpecError)]
- fn new(desc: Html, outline: OutlineRepr,
+ pub fn new(desc: Desc, outline: OutlineRepr,
def_itemname: &'_ str,
common: &SimpleCommon)
- -> SimpleShape
+ -> GenericSimpleShape<Desc>
{
let itemname = common.itemname.clone()
.unwrap_or_else(|| def_itemname.to_string());
throw!(SpecError::SpecifiedWidthOfNoEdges);
}
- let shape = SimpleShape {
+ let shape = GenericSimpleShape {
desc, itemname, outline,
colours: cmap(&common.faces)?,
edges: cmap(&common.edges)?,
pub use crate::shapelib;
pub use crate::slotmap_slot_idx::*;
pub use crate::spec::*;
-pub use crate::spec::piece_specs::FaceColourSpecs;
+pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon};
pub use crate::sse;
pub use crate::toml_de;
pub use crate::tz::*;
}
#[derive(Serialize,Deserialize)]
-#[derive(Debug,Default)]
+#[derive(Debug,Default,Clone)]
#[repr(transparent)]
#[serde(transparent)]
pub struct ColourSpec(pub String);
#[derive(Debug,Serialize,Deserialize)]
pub struct Hand {
- pub shape: Box<dyn crate::pieces::SimplePieceSpec>,
+ pub colour: String,
+ pub edge: Option<ColourSpec>,
+ pub edge_width: Option<f64>,
+ pub shape: OutlineRepr,
}
}
(||{
let data = fs::read(&path).context("read")?;
let data = std::str::from_utf8(&data).context("convert from UTF-8")?;
- let data = toml_de::from_str(&data).context("parse")?;
+ let data: toml::Value = data.parse().context("parse TOM")?;
+ dbg!(&data);
+ let data = toml_de::from_value(&data).context("interperet TOML")?;
Ok::<_,AE>(data)
})()
.context(path)