From 5d837d6285ef9c6df411456722b5dc7d1494ae16 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 25 Mar 2021 13:08:46 +0000 Subject: [PATCH] Rect[Shape]: rename from Rectangle and from Square Signed-off-by: Ian Jackson --- library/cards-oxymoron.toml | 2 +- library/edited.toml | 2 +- library/wikimedia.toml | 6 +++--- specs/demo.game.toml | 6 +++--- specs/mao.game.toml | 26 +++++++++++++------------- specs/penultima.game.toml | 10 +++++----- src/clock.rs | 4 ++-- src/deck.rs | 4 ++-- src/hand.rs | 4 ++-- src/pieces.rs | 20 ++++++++++++-------- src/prelude.rs | 1 + src/shapelib-toml.rs | 2 +- src/shapelib.rs | 24 ++++++++++++------------ src/spec.rs | 8 ++++---- 14 files changed, 62 insertions(+), 57 deletions(-) diff --git a/library/cards-oxymoron.toml b/library/cards-oxymoron.toml index f354e010..9b3b46b1 100644 --- a/library/cards-oxymoron.toml +++ b/library/cards-oxymoron.toml @@ -10,7 +10,7 @@ filename_suffix = ".gif" [group.clubs] item_prefix = "card-oxymoron-" -outline = "Square" +outline = "Rect" size = [73, 97] centre = [36.5, 48.5] scale = 0.25 diff --git a/library/edited.toml b/library/edited.toml index 34ce30fd..e2b5411c 100644 --- a/library/edited.toml +++ b/library/edited.toml @@ -8,7 +8,7 @@ method = "none" [group.chess-board] size = [242, 246] scale = 0.38 -outline = "Square" +outline = "Rect" files = """ chess-board - the chessboard """ diff --git a/library/wikimedia.toml b/library/wikimedia.toml index a2093f83..d26f95d0 100644 --- a/library/wikimedia.toml +++ b/library/wikimedia.toml @@ -112,7 +112,7 @@ files = """ """ [group.misc] -outline = "Square" +outline = "Rect" size = [448,326] centre = [224, 163] scale = 0.025 @@ -121,7 +121,7 @@ mgmt-library-load-marker Box_with_polygons a library load area marker """ [group.card-backs] -outline = "Square" +outline = "Rect" size = [73, 97] # sizes to match cards-oxymoron: @@ -136,7 +136,7 @@ card-rainbow Card_back_13 a rainbow card """ [group.cards-bellot] -outline = "Square" +outline = "Rect" size = [73, 97] # sizes to match cards-oxymoron: diff --git a/specs/demo.game.toml b/specs/demo.game.toml index 8ed1fb0f..c8cb6807 100644 --- a/specs/demo.game.toml +++ b/specs/demo.game.toml @@ -13,7 +13,7 @@ edges = ["black","white"] [[pieces]] pos = [90, 20] -type = "Square" +type = "Rect" size = [10] angle.Compass = 1 faces = ["blue", "grey"] @@ -33,7 +33,7 @@ item = "chess-b-N" [[pieces]] pos = [120, 30] -type = "Square" +type = "Rect" size = [10] angle.Compass = 1 faces = [ ] @@ -45,7 +45,7 @@ pos = [40, 40] type = "Hand" edge = "white" colour = "grey" -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [70,20] [[pieces]] diff --git a/specs/mao.game.toml b/specs/mao.game.toml index 57c4b3fa..cad206c2 100644 --- a/specs/mao.game.toml +++ b/specs/mao.game.toml @@ -12,7 +12,7 @@ faces = ["lightblue", "grey"] edges = ["black", "white"] label.colour = "black" label.place = "BottomLeftOutside" -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [25,30] [[pieces]] @@ -22,7 +22,7 @@ faces = ["lightblue", "grey"] edges = ["black", "white"] label.colour = "black" label.place = "BottomLeftOutside" -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [25,30] [[pieces]] @@ -32,7 +32,7 @@ faces = ["lightblue", "grey"] edges = ["black", "white"] label.place = "TopLeftOutside" label.colour = "black" -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [25,30] @@ -107,7 +107,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -119,7 +119,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -131,7 +131,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -143,7 +143,7 @@ label.colour = "black" type = "Hand" edge = "darkgrey" edge_width = 1.0 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -155,7 +155,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -167,7 +167,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -179,7 +179,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -191,7 +191,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -203,7 +203,7 @@ label.colour = "black" type = "Hand" edge = "white" edge_width = 0.75 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] [[pieces]] @@ -215,5 +215,5 @@ label.colour = "black" type = "Hand" edge = "darkgrey" edge_width = 1.0 -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [97,25] diff --git a/specs/penultima.game.toml b/specs/penultima.game.toml index 283ac981..f57902d1 100644 --- a/specs/penultima.game.toml +++ b/specs/penultima.game.toml @@ -55,7 +55,7 @@ count = 8 [[pieces]] pos = [20, 85] -type = "Square" +type = "Rect" faces = ["yellow","#f4f"] posd = [10, 0] size = [7,7] @@ -63,7 +63,7 @@ count = 8 [[pieces]] pos = [20, 95] -type = "Square" +type = "Rect" faces = ["#333"] posd = [10, 0] size = [9,1] @@ -71,7 +71,7 @@ count = 8 [[pieces]] pos = [20, 100] -type = "Square" +type = "Rect" faces = ["#333"] posd = [10, 0] size = [9,1] @@ -79,7 +79,7 @@ count = 8 [[pieces]] pos = [17, 110] -type = "Square" +type = "Rect" faces = ["#333"] posd = [5, 0] size = [1,9] @@ -190,7 +190,7 @@ pos = [20, 60] type = "Hand" edge = "white" colour = "grey" -shape.type = "Rectangle" +shape.type = "Rect" shape.xy = [20,10] [[pieces]] diff --git a/src/clock.rs b/src/clock.rs index 174f9133..0d7fedf4 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -3,7 +3,7 @@ // There is NO WARRANTY. use crate::prelude::*; -use shapelib::Rectangle; +use shapelib::RectShape; use nix::sys::time::TimeValLike as TVL; @@ -388,7 +388,7 @@ impl ThreadState { const W: Coord = 40; const H: Coord = 14; -const OUTLINE: Rectangle = Rectangle { xy: PosC::new(W as f64, H as f64) }; +const OUTLINE: RectShape = RectShape { xy: PosC::new(W as f64, H as f64) }; // ==================== piece management, loading, etc. ==================== diff --git a/src/deck.rs b/src/deck.rs index 5d6e3294..6a708e10 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -11,7 +11,7 @@ pub const ENABLED_DESC: &str = "a pickup deck (enabled)"; #[derive(Debug,Serialize,Deserialize)] struct Deck { - shape: GenericSimpleShape<(), shapelib::Rectangle>, + shape: GenericSimpleShape<(), RectShape>, label: Option, } @@ -46,7 +46,7 @@ impl PieceSpec for piece_specs::Deck { edge_width: self.edge_width, }; let shape = match self.shape { - Outline::Rectangle(r) => r, + Outline::RectShape(r) => r, _ => throw!(SpecError::UnsupportedShape), }; let shape = GenericSimpleShape::new( diff --git a/src/hand.rs b/src/hand.rs index ea74fe87..a49ebeee 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -16,7 +16,7 @@ struct MagicOwner { #[derive(Debug,Serialize,Deserialize)] struct Hand { - shape: GenericSimpleShape<(), shapelib::Rectangle>, + shape: GenericSimpleShape<(), RectShape>, label: Option, } @@ -59,7 +59,7 @@ impl PieceSpec for piece_specs::Hand { edge_width: self.edge_width, }; let shape = match self.shape { - Outline::Rectangle(r) => r, + Outline::RectShape(r) => r, _ => throw!(SpecError::UnsupportedShape), }; let shape = GenericSimpleShape::new( diff --git a/src/pieces.rs b/src/pieces.rs index fed4679e..f8f2a65c 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -152,7 +152,7 @@ impl PieceTrait for SimpleShape { impl piece_specs::PieceLabel { #[throws(IE)] pub fn svg(&self, f: &mut Html, - outline: &shapelib::Rectangle, + outline: &RectShape, def_colour: Option<&Colour>, text: &Html) { let colour = { @@ -281,7 +281,7 @@ pub trait SimplePieceSpec: Debug { impl SimplePieceSpec for piece_specs::Disc { #[throws(SpecError)] fn load_raw(&self) -> (SimpleShape, &SimpleCommon) { - let outline = shapelib::Circle { diam: self.diam as f64 }; + let outline = CircleShape { diam: self.diam as f64 }; (SimpleShape::new( Html::lit("disc"), outline.into(), @@ -300,7 +300,7 @@ impl PieceSpec for piece_specs::Disc { } } -impl piece_specs::Square { +impl piece_specs::Rect { #[throws(SpecError)] fn xy(&self) -> Pos { match *self.size.as_slice() { @@ -312,21 +312,25 @@ impl piece_specs::Square { } #[typetag::serde] -impl SimplePieceSpec for piece_specs::Square { +impl SimplePieceSpec for piece_specs::Rect { #[throws(SpecError)] fn load_raw(&self) -> (SimpleShape, &SimpleCommon) { - let outline = shapelib::Rectangle { xy: self.xy()?.map(|v| v as f64) }; + let outline = RectShape { xy: self.xy()?.map(|v| v as f64) }; + let desc = Html::lit( + if outline.xy.x() == outline.xy.y() + { "square" } else { "rectangle" } + ); (SimpleShape::new( - Html::lit("square"), + desc, outline.into(), - "simple-square", + "simple-rect", &self.common, )?, &self.common) } } #[typetag::serde] -impl PieceSpec for piece_specs::Square { +impl PieceSpec for piece_specs::Rect { #[throws(SpecError)] fn load(&self, _: usize, _: &mut GPiece, _ir: &InstanceRef) -> PieceSpecLoaded { diff --git a/src/prelude.rs b/src/prelude.rs index b927b0c3..523270cc 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -139,6 +139,7 @@ pub use crate::occultilks::*; pub use crate::pcrender::*; pub use crate::pieces::*; pub use crate::shapelib; +pub use crate::shapelib::{CircleShape, RectShape}; pub use crate::slotmap_slot_idx::*; pub use crate::spec::*; pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon}; diff --git a/src/shapelib-toml.rs b/src/shapelib-toml.rs index d36e2b05..ecbcbd04 100644 --- a/src/shapelib-toml.rs +++ b/src/shapelib-toml.rs @@ -153,7 +153,7 @@ pub struct GroupDetails { /// If specified, pieces in this group can be occulted. pub occulted: Option, - /// One of `"Circle"` or `"Square"`, to define the outline shape. + /// One of `"Circle"` or `"Rect"`, to define the outline shape. /// The size is taken from `size`. /// /// This value is a string, not some weird Rust type, despite diff --git a/src/shapelib.rs b/src/shapelib.rs index ae397939..e2b4bb35 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -735,10 +735,10 @@ pub fn load(libs: &Vec) { } #[derive(Clone,Copy,Debug,Serialize,Deserialize)] -pub struct Circle { pub diam: f64 } +pub struct CircleShape { pub diam: f64 } #[dyn_upcast] -impl OutlineTrait for Circle { +impl OutlineTrait for CircleShape { #[throws(IE)] fn outline_path(&self, scale: f64) -> Html { svg_circle_path(self.diam * scale)? @@ -761,7 +761,7 @@ impl OutlineDefn for CircleDefn { #[throws(LibraryLoadError)] fn check(&self, lgd: &GroupData) { Self::get_size(lgd)?; } fn load(&self, lgd: &GroupData) -> Result { - Ok(Circle { + Ok(CircleShape { diam: Self::get_size(lgd).map_err(|e| e.ought())?, }.into()) } @@ -778,9 +778,9 @@ impl CircleDefn { } #[derive(Clone,Copy,Debug,Serialize,Deserialize)] -pub struct Rectangle { pub xy: PosC } +pub struct RectShape { pub xy: PosC } -impl Rectangle { +impl RectShape { #[throws(CoordinateOverflow)] pub fn rect(&self, centre: Pos) -> RectC { let offset = (self.xy * 0.5)?; @@ -804,7 +804,7 @@ impl Rectangle { } #[dyn_upcast] -impl OutlineTrait for Rectangle { +impl OutlineTrait for RectShape { #[throws(IE)] fn outline_path(&self, scale: f64) -> Html { let xy = (self.xy * scale)?; @@ -827,9 +827,9 @@ impl OutlineTrait for Rectangle { } #[derive(Deserialize,Debug)] -struct SquareDefn { } -#[typetag::deserialize(name="Square")] -impl OutlineDefn for SquareDefn { +struct RectDefn { } +#[typetag::deserialize(name="Rect")] +impl OutlineDefn for RectDefn { #[throws(LibraryLoadError)] fn check(&self, lgd: &GroupData) { Self::get(lgd)?; } fn load(&self, lgd: &GroupData) -> Result { @@ -838,10 +838,10 @@ impl OutlineDefn for SquareDefn { ) } } -impl SquareDefn { +impl RectDefn { #[throws(LibraryLoadError)] - fn get(group: &GroupData) -> Rectangle { - Rectangle { xy: PosC{ coords: + fn get(group: &GroupData) -> RectShape { + RectShape { xy: PosC{ coords: match group.d.size.as_slice() { &[s] => [s,s], s if s.len() == 2 => s.try_into().unwrap(), diff --git a/src/spec.rs b/src/spec.rs index f1fa845c..fca2ab6b 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -193,14 +193,14 @@ pub struct CompassAngle(u8); mod outline { use super::*; use crate::prelude::*; - use crate::shapelib::{Circle, Rectangle}; + use crate::shapelib::{CircleShape, RectShape}; #[dyn_upcast(OutlineTrait)] #[enum_dispatch(OutlineTrait)] #[derive(Clone,Debug,Serialize,Deserialize)] #[serde(tag="type")] pub enum Outline { - Circle, - #[serde(alias="Square")] Rectangle, + #[serde(rename="Circle")] CircleShape, + #[serde(rename="Rect")] RectShape, } } pub use outline::*; @@ -226,7 +226,7 @@ pub mod piece_specs { } #[derive(Debug,Serialize,Deserialize)] - pub struct Square { + pub struct Rect { pub size: Vec, #[serde(flatten)] pub common: SimpleCommon, -- 2.30.2