From f45a5aa1e584db9068749af47872524dd6f0b81b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 17 May 2022 02:11:04 +0100 Subject: [PATCH] currency: support label text recolouring Signed-off-by: Ian Jackson --- docs/gamespec.rst | 3 +++ src/currency.rs | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/gamespec.rst b/docs/gamespec.rst index b9e89f08..5fef0cfb 100644 --- a/docs/gamespec.rst +++ b/docs/gamespec.rst @@ -438,6 +438,9 @@ Parameters: * ``currency``: The currency, which defines which other banknotes this one can interchange with. + * ``label.colour``: Text colour to use for the value. + [string, default "black"] + Exammple:: [[pieces]] diff --git a/src/currency.rs b/src/currency.rs index c3260079..0b55ab9f 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -25,6 +25,12 @@ pub struct Spec { image: Box, qty: Qty, currency: String, + #[serde(default)] label: LabelSpec, +} + +#[derive(Debug,Default,Clone,Serialize,Deserialize)] +pub struct LabelSpec { + pub colour: Option, } #[derive(Debug,Clone,Serialize,Deserialize)] @@ -32,6 +38,7 @@ pub struct Banknote { itemname: String, image: Arc, currency: String, + label_colour: Colour, } #[derive(Debug,Serialize,Deserialize)] @@ -48,7 +55,10 @@ impl PieceSpec for Spec { fn load(&self, PLA { gpc,ig,depth,.. }: PLA) -> SpecLoaded { gpc.rotateable = false; - let Spec { ref image, ref currency, qty } = *self; + let Spec { ref image, ref currency, qty, + label: LabelSpec { colour: ref label_colour } } = *self; + + let label_colour = label_colour.resolve()?; let SpecLoadedInert { p: image, occultable:_ } = image.load_inert(ig, depth)?; @@ -67,7 +77,7 @@ impl PieceSpec for Spec { let bnote = Banknote { image: image.into(), currency: currency.clone(), - itemname, + itemname, label_colour, }; gpc.fastsplit = FastSplitId::new_placeholder(); @@ -111,9 +121,9 @@ impl PieceTrait for Banknote { let label_y_adj = label_font_size * SVG_FONT_Y_ADJUST_OF_FONT_SIZE; hwrite!(f, - r##"<{} text-align="center" text-anchor="middle" x="0" y="{}" font-size="{}">{}{}"##, + r##"<{} text-align="center" text-anchor="middle" x="0" y="{}" fill="{}" font-size="{}">{}{}"##, HTML_TEXT_LABEL_ELEM_START, - label_y_adj, label_font_size, + label_y_adj, &self.label_colour, label_font_size, value.qty, &self.currency)?; } -- 2.30.2