chiark / gitweb /
PieceMoveable: Honour in JS
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 23:11:03 +0000 (23:11 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 23:11:03 +0000 (23:11 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index f971fe63b47a8ad39b55927e13d9d6b7b9b43a5b..f41d1b429cb5cc5a68fea5ab6a5c7d9206c3513f 100644 (file)
@@ -46,6 +46,7 @@ type UoKind = 'Client' | "Global"| "Piece" | "ClientExtra" | "GlobalExtra";
 type WhatResponseToClientOp = "Predictable" | "Unpredictable" | "UpdateSvg";
 type Timestamp = number; // unix time_t, will break in 285My
 type Layout = 'Portrait' | 'Landscape';
+type PieceMoveable = "No" | "IfWresting" | "Yes";
 
 type UoDescription = {
   kind: UoKind;
@@ -69,6 +70,7 @@ type PieceInfo = {
   zg : Generation,
   angle: number,
   pinned: boolean,
+  moveable: PieceMoveable,
   uos : UoDescription[],
   uelem : SVGGraphicsElement,
   delem : SVGGraphicsElement,
@@ -820,6 +822,19 @@ function drag_mousemove(e: MouseEvent) {
   var ddr2 = ddx*ddx + ddy*ddy;
   if (!(dragging & DRAGGING.YES)) {
     if (ddr2 > DRAGTHRESH) {
+      for (let dp of drag_pieces) {
+       let tpiece = dp.piece;
+       let tp = pieces[tpiece]!;
+       if (tp.moveable == "Yes") {
+         continue;
+       } else if (tp.moveable == "IfWresting") {
+         if (wresting) continue;
+         add_log_message('That piece can only be moved when Wresting.');
+       } else {
+         add_log_message('That piece cannot be moved at the moment.');
+       }
+       return ddr2;
+      }
       dragging |= DRAGGING.YES;
     }
   }
@@ -1035,6 +1050,7 @@ type PreparedPieceState = {
   pinned: boolean,
   angle: number,
   uos: UoDescription[],
+  moveable: PieceMoveable,
 }
 
 pieceops.ModifyQuiet = <PieceHandler>function
@@ -1069,6 +1085,7 @@ function piece_modify(piece: PieceId, p: PieceInfo, info: PreparedPieceState,
   p.uelem.setAttributeNS(null, "y", info.pos[1]+"");
   p.held = info.held;
   p.pinned = info.pinned;
+  p.moveable = info.moveable;
   p.angle = info.angle;
   piece_set_zlevel(piece,p, (oldtop_piece)=>{
     p.z  = info.z;