chiark / gitweb /
die: Prepare for extracting text template too
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Apr 2022 22:30:44 +0000 (23:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Apr 2022 22:30:44 +0000 (23:30 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.gitignore
Makefile
dice/overlay-template-extractor [moved from dice/cooldown-template-extractor with 94% similarity]
src/dice.rs

index b665e1091ff95801e627adcc4e59b76481665dc6..d9e68d79aedec074a056ed2fa4d243fa19a8b310 100644 (file)
@@ -7,7 +7,7 @@ templates/CC-BY-SA-3.0
 templates/CC-BY-SA-4.0
 templates/otter_wasm.ns.d.ts
 templates/shapelib.html
-nwtemplates/die-cooldown.tera
+nwtemplates/die-overlay.tera
 save/lock
 /examples/test-bundle.zip
 /examples/big-bundle
index 88f86e62b1ceb3c56dd22173d9118d88bd30de30..65fbe652a24eaaee0c795c71ef59c1e05b200db0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -130,7 +130,7 @@ TXTFILES= CC-BY-SA-3.0 CC-BY-SA-4.0
 FILEASSETS = $(addprefix templates/, libre shapelib.html script.js \
                        $(LITFILES) $(TXTFILES)) \
                $(wildcard templates/*.tera) \
-               nwtemplates/die-cooldown.tera
+               nwtemplates/die-overlay.tera
 
 WASM := wasm32-unknown-unknown
 # ^ todo: Is this still right after
@@ -371,7 +371,7 @@ templates/shapelib.html: $(TARGET_DIR)/debug/otterlib $(LIBRARY_FILES)
        --libs '$(addprefix $(PWD)/, $(addsuffix .toml, $(LIBRARIES)))' \
                preview >$@.tmp && mv -f $@.tmp $@
 
-nwtemplates/die-cooldown.tera: dice/cooldown-template-extractor dice/die.svg
+nwtemplates/die-overlay.tera: dice/overlay-template-extractor dice/die.svg
        ./$< <dice/die.svg >$@.tmp && mv -f $@.tmp $@
 
 #---------- examples ----------
similarity index 94%
rename from dice/cooldown-template-extractor
rename to dice/overlay-template-extractor
index 2179a1e10e7ee6fa3c1531f19317c8cb4850a5df..3ca02b8f9cc0340dfbc46cfc45d47f3c615923f6 100755 (executable)
@@ -24,7 +24,10 @@ sub process_node ($$) {
   die "$label ?" unless @$nodes == 1;
   $node = $nodes->[0];
   $fn->($node);
-  print $node->toString, "\n" or die $!;
+  print
+    "{% if cooldown_active %}",
+    $node->toString,
+    "{% endif %}\n" or die $!;
 }
 
 our $nom_radius;
index f9f6da792856322581222de87121babdeb364364..a368fdf339601d35d3c5f7f78c69706a78f7d70e 100644 (file)
@@ -75,7 +75,8 @@ impl PieceXData for State {
 }
 
 #[derive(Serialize, Debug)]
-struct CooldownTemplateContext<'c> {
+struct OverlayTemplateContext<'c> {
+  cooldown_active: bool,
   radius: f64,
   remprop: f64,
   path_d: &'c str,
@@ -342,23 +343,28 @@ impl InertPieceTrait for Die {
     self.image.svg(f, vpid, face, xdata)?;
 
     let remprop = self.cooldown_remprop(state)?;
-    if remprop != 0. {
 
+    let cooldown_active = remprop != 0.;
+
+    let (path_d, cd_elid) = if cooldown_active {
       let mut path_d = String::new();
       die_cooldown_path(&mut path_d, self.cooldown_radius, remprop)?;
-      let cd_elid = format!("def.{}.die.cd", vpid);
-
-      let tc = CooldownTemplateContext {
-        radius: self.cooldown_radius,
-        path_d: &path_d,
-        cd_elid: &cd_elid,
-        total_ms: self.cooldown_time.as_secs_f64() * 1000.,
-        remprop,
-      };
-
-      write!(f.as_html_string_mut(), "{}",
-             nwtemplates::render("die-cooldown.tera", &tc)?)?;
-    }
+      (path_d, format!("def.{}.die.cd", vpid))
+    } else {
+      default()
+    };
+
+    let tc = OverlayTemplateContext {
+      cooldown_active,
+      radius: self.cooldown_radius,
+      path_d: &path_d,
+      cd_elid: &cd_elid,
+      total_ms: self.cooldown_time.as_secs_f64() * 1000.,
+      remprop,
+    };
+
+    write!(f.as_html_string_mut(), "{}",
+           nwtemplates::render("die-overlay.tera", &tc)?)?;
   }
 
   // add throw operation