chiark / gitweb /
special selection: wip key handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Apr 2021 20:44:38 +0000 (21:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 19:07:53 +0000 (20:07 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/macros.tera
templates/script.ts

index 854ca7e085d309d48b0f8211502a71a5ab5a3532..439ff23f07abf71b06aef17cda06e93a4ac6df72 100644 (file)
@@ -70,6 +70,8 @@ Hi {{nick | escape}}
 {% endmacro errors %}
 
 {% macro space() %}
+    <style id="space-cursor-style">
+    </style>
     <svg xmlns="http://www.w3.org/2000/svg"
          id="space" {{ space_attrs }} >
       <rect fill="{{ table_colour }}" x="0" y="0"
@@ -98,8 +100,9 @@ Hi {{nick | escape}}
     <div class="uos-mid" id="uos-mid"></div>
   </div>
   <div class="uos">
-    <div class="uokey"><strong>Mouse</strong> select/deselect/drag</div>
-    <div class="uokey"><strong>shift</strong> multiple selection</div>
+    <div class="uokey"><strong>Mouse</strong> select/deselect/drag
+                       <strong>shift</strong> multiple selection</div>
+    <div class="uokey"><strong>0-9</strong> special selection</div>
     <div class="uokey">Show
       <strong>H</strong> this help
       <strong>U</strong> players
index a1aa33bf0bd2fc19ec74475ada917c59b0b11a09..191939404ad3bc8cb7f4215b0fbb6cd9215c4497 100644 (file)
@@ -136,6 +136,7 @@ var zoom_btn : HTMLInputElement;
 var links_elem : HTMLElement;
 var wresting: boolean;
 var occregions: wasm_bindgen.RegionList;
+let special_count: number | null;
 
 var movehist_gen: number = 0;
 const MOVEHIST_ENDS = 2.5;
@@ -398,6 +399,19 @@ function some_keydown(e: KeyboardEvent) {
     return pane_switch(pane);
   }
 
+  let special_count_key = parseInt(e.key);
+  if (isFinite(special_count_key)) {
+    if (special_count == null) special_count = 0;
+    special_count *= 10;
+    special_count += special_count_key;
+    special_count %= 100;
+    special_count_reupdate();
+  }
+  if (e.key == ' ') {
+    special_count = null;
+    special_count_reupdate();
+  }
+
   let uo = uo_map[e.key];
   if (uo === undefined || uo === null) return;
 
@@ -436,6 +450,32 @@ function pane_switch(newpane: PaneName) {
   new_e.removeAttribute('style');
 }
 
+function special_count_reupdate() {
+  let style_elem = document.getElementById("space-cursor-style")!;
+  let style_text;
+  if (special_count == null) {
+    style_text = '';
+  } else {
+    let path = 'stroke-linecap="square" d="M -10 -10 10 10 M 10 -10 -10 10"';
+    let svg = 
+`<svg xmlns="http://www.w3.org/2000/svg"
+     viewBox="-15 0 85 65" width="100" height="65">
+  <g transform="translate(0 50)">
+    <path stroke-width="8" stroke="#fcf" ${path}/>
+    <path stroke-width="4" stroke="purple" ${path}/>
+    <text x="0" y="0" fill="purple" stroke="#fcf" stroke-width="2"
+       font-family="sans-serif" font-size="50">${special_count}</text>
+  </g></svg>`;
+    console.log(svg);
+    let svg_data = btoa(svg);
+    style_text =
+`svg[id=space] {
+  cursor: url(data:image/svg+xml;base64,${svg_data}) 15 50, text;
+}`;
+  }
+  style_elem.innerHTML = style_text;
+}
+
 keyops_local['left' ] = function (uo: UoRecord) { rotate_targets(uo, +1); }
 keyops_local['right'] = function (uo: UoRecord) { rotate_targets(uo, -1); }