chiark / gitweb /
can pin
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Oct 2020 00:39:22 +0000 (01:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 3 Oct 2020 00:39:22 +0000 (01:39 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/api.rs
src/session.rs
templates/script.ts

index 1db1a8599fc3b96953b8ea9381ebc695491b1d1d..d218421cd8cebb52ca5fb9238f5266d83b01ac1b 100644 (file)
@@ -1,4 +1,4 @@
-p// Copyright 2020 Ian Jackson
+// Copyright 2020 Ian Jackson
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // There is NO WARRANTY.
 
@@ -391,6 +391,7 @@ pub fn mount(rocket_instance: Rocket) -> Rocket {
     api_raise,
     api_move,
     api_wrest,
+    api_pin,
     api_uo,
   ])
 }
index cb2203a6bf9d1941c244cc44e62ed5f7b94adc49..e24bd370d0613ba9267699f10eab3118defc6eb0 100644 (file)
@@ -29,6 +29,7 @@ struct SessionPieceLoadJson<'r> {
   held : &'r Option<PlayerId>,
   z : ZCoord,
   zg : Generation,
+  pinned : bool,
   uos: &'r [UoDescription],
 }
 
@@ -105,6 +106,7 @@ fn session(form : Json<SessionForm>) -> Result<Template,OE> {
         held : &pr.held,
         z  : pr.zlevel.z,
         zg : pr.zlevel.zg,
+        pinned : pr.pinned,
         uos : &p.ui_operations()?,
       };
 
index fa7ae345d1d65877ccc4d8cfd683088cac7fdc38..d40ac99ebce9ca5957b86b4dcfc8939aab542675 100644 (file)
@@ -359,6 +359,19 @@ keyops_local['wrest'] = function (uo: UoRecord) {
   recompute_keybindings();
 }
 
+keyops_local['pin'  ] = function (uo) { pin_unpin(uo, true ); }
+keyops_local['unpin'] = function (uo) { pin_unpin(uo, false); }
+
+function pin_unpin(uo: UoRecord, newpin: boolean) {
+  for (let piece of uo.targets!) {
+    let p = pieces[piece]!;
+    p.pinned = newpin;
+    api_piece(api, 'pin', piece,p, newpin);
+    redisplay_ancillaries(piece,p);
+  }
+  recompute_keybindings();
+}
+
 // ----- clicking/dragging pieces -----
 
 type DragInfo = {
@@ -491,7 +504,7 @@ function redisplay_ancillaries(piece: PieceId, p: PieceInfo) {
   } else if (p.last_seen_moved != null) {
     halo_colour = 'yellow';
   } else if (p.held != null && p.pinned) {
-    halo_colour = 'white';
+    halo_colour = '#8cf';
   }
   if (halo_colour != null) {
     let nelem = ancillary_node(piece, halo_colour);