From b25bbfa6dddc939169581da8f0821b58812c3f8c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 22 May 2022 23:43:49 +0100 Subject: [PATCH] Support stack_pos on PickupDeck Signed-off-by: Ian Jackson --- docs/gamespec.rst | 3 +++ src/deck.rs | 8 +++++++- src/spec.rs | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/gamespec.rst b/docs/gamespec.rst index d1f13bdc..a47e3672 100644 --- a/docs/gamespec.rst +++ b/docs/gamespec.rst @@ -237,6 +237,9 @@ Honours ``edges``, ``edge_width``. Honours ``label``, displaying the number of of pieces in (on) this deck. + * ``stack_pos``: When stacking neatly, stack here relative to the + deck centre. [two numbers, ``[0,0]``] + Example:: [[pieces]] diff --git a/src/deck.rs b/src/deck.rs index ab460342..08137254 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -14,6 +14,7 @@ pub const ENABLED_DESC : HtmlLit = Html::lit("a pickup deck (enabled)"); struct Deck { shape: GenericSimpleShape<(), RectOutline>, label: Option, + stack_pos: Pos, } #[derive(Debug,Clone,Copy,Ord,PartialOrd,Eq,PartialEq)] @@ -60,6 +61,7 @@ impl PieceSpec for piece_specs::Deck { gpc.rotateable = false; let p = Box::new(Deck { shape, + stack_pos: PosC { coords: self.stack_pos }, label: self.label.load()?, }) as Box; SpecLoaded { @@ -196,7 +198,11 @@ impl PieceTrait for Deck { Disabled => None, Counting => Some(OccKG::Visible), Enabled => { - let displace = OccDisplacement::Stack { pos: gpc.pos }; + let pos = (|| { + (gpc.pos + self.stack_pos).ok()? + .clamped(gs.table_size).ok() + })().ok_or_else(|| Ia::PosOffTable)?; + let displace = OccDisplacement::Stack { pos }; let displace = (displace, gpc.zlevel.z.clone()); Some(OccKG::Displaced(displace)) }, diff --git a/src/spec.rs b/src/spec.rs index 7ba438cc..9fea2654 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -335,6 +335,7 @@ pub mod piece_specs { pub edge_width: Option, pub shape: Outline, pub label: Option, + #[serde(default)] pub stack_pos: [Coord; 2], } } -- 2.30.2