From 3dd7ba75e18245a77588602bccd9e8859c36c348 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Apr 2022 00:12:42 +0100 Subject: [PATCH] dice: Actually display the labels Signed-off-by: Ian Jackson --- dice/overlay-template-extractor | 11 +++++++++++ src/dice.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/dice/overlay-template-extractor b/dice/overlay-template-extractor index 168cf324..0f2a9910 100755 --- a/dice/overlay-template-extractor +++ b/dice/overlay-template-extractor @@ -55,6 +55,17 @@ sub filter_circle () { $node->setAttribute('r', "{{radius}}"); } +sub filter_text () { + filter_element('text', qw(x y font-family text-align text-anchor)); + $node->setAttribute('font-size', "{{ label_font_size }}px"); + $node->setAttribute('y', "{{ label_font_size * 0.35 }}"); + $node->removeChildNodes(); + $node->appendText('{{ label_text }}'); +} +p "{% if label_text != \"\" %}\n"; +process_node('textlabel', \&filter_text); +p "{% endif %}\n"; + p "{% if cooldown_active %}\n"; process_node('timeblack', sub { $nom_radius = $node->getAttribute('r'); diff --git a/src/dice.rs b/src/dice.rs index c48353d3..349b6945 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -24,6 +24,8 @@ const COOLDOWN_EXTRA_RADIUS: f64 = 0.5 * (SELECT_STROKE_WIDTH + COOLDOWN_STROKE_WIDTH) + DEFAULT_EDGE_WIDTH; +const DEFAULT_LABEL_FONT_SIZE: f64 = 8.; + #[derive(Debug,Serialize,Deserialize)] pub struct Spec { // must be >1 faces on image, or >1 texts, and if both, same number @@ -76,6 +78,9 @@ impl PieceXData for State { #[derive(Serialize, Debug)] struct OverlayTemplateContext<'c> { + label_text: &'c str, + label_font_size: f64, + cooldown_active: bool, radius: f64, remprop: f64, @@ -342,6 +347,9 @@ impl InertPieceTrait for Die { let iface = if self.image.nfaces() == 1 { default() } else { face }; self.image.svg(f, vpid, iface, xdata)?; + let label = self.labels.get(face).map(|s| &**s).unwrap_or_else( + || self.labels.get(0).map(|s| &**s) .unwrap_or_default()); + let remprop = self.cooldown_remprop(state)?; let cooldown_active = remprop != 0.; @@ -355,6 +363,9 @@ impl InertPieceTrait for Die { }; let tc = OverlayTemplateContext { + label_text: &label, + label_font_size: DEFAULT_LABEL_FONT_SIZE, + cooldown_active, radius: self.cooldown_radius, path_d: &path_d, -- 2.30.2