chiark / gitweb /
script: break out piece_xy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 16:38:13 +0000 (16:38 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Mar 2021 16:38:13 +0000 (16:38 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
templates/script.ts

index 96b8d1eb99f71968e3e88eb47e97119918f90ef9..2360b2f955c3f9d45a75b684dbe83427cc28869f 100644 (file)
@@ -676,11 +676,17 @@ var dcy : number | null;
 
 const DRAGTHRESH = 5;
 
+function piece_xy(p: PieceInfo): [number, number] {
+  return [ parseFloat(p.uelem.getAttributeNS(null,"x")!),
+          parseFloat(p.uelem.getAttributeNS(null,"y")!) ];
+}
+
 function drag_add_piece(piece: PieceId, p: PieceInfo) {
+  let [dox, doy] = piece_xy(p);
   drag_pieces.push({
     piece: piece,
-    dox: parseFloat(p.uelem.getAttributeNS(null,"x")!),
-    doy: parseFloat(p.uelem.getAttributeNS(null,"y")!),
+    dox: dox,
+    doy: doy,
   });
 }