From 97cc1f012a2d90702f34c1b9aaf80be8ea4ec633 Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Sun, 14 Apr 2024 09:54:03 -0700
Subject: Import pan/zoom functions from external module
---
README.md | 4 +-
package-lock.json | 367 +----------
package.json | 3 +
public/map.css | 149 +++--
public/map.svg | 1817 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/index.js | 563 ++++++++---------
6 files changed, 2177 insertions(+), 726 deletions(-)
diff --git a/README.md b/README.md
index aee7c62..f6682a1 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,10 @@
## Install dev server packages
- docker run --rm -w /app -v $PWD:/app -u $(id -u):$(id -u) node bash -c "npm install"
+ docker run --rm -w /app -v $PWD:/app -u $(id -u):$(id -u) node npm install
## Start the dev server
- docker run --rm --init -it -w /app -v $PWD:/app -p 8080:8080 node bash -c "node dev-server.js"
+ docker run --rm --init -it -w /app -v $PWD:/app -p 8080:8080 node node dev-server.js
Visit `localhost:8080` to view.
diff --git a/package-lock.json b/package-lock.json
index d47231c..2d7e09b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -4,275 +4,21 @@
"requires": true,
"packages": {
"": {
+ "dependencies": {
+ "svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
+ },
"devDependencies": {
"esbuild": "^0.20.2",
"esbuild-server": "^0.3.0"
}
},
- "node_modules/@esbuild/aix-ppc64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.2.tgz",
- "integrity": "sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==",
- "cpu": [
- "ppc64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "aix"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/android-arm": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.20.2.tgz",
- "integrity": "sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==",
- "cpu": [
- "arm"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/android-arm64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.20.2.tgz",
- "integrity": "sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/android-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.20.2.tgz",
- "integrity": "sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "android"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/darwin-arm64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.20.2.tgz",
- "integrity": "sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/darwin-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.20.2.tgz",
- "integrity": "sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/freebsd-arm64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.20.2.tgz",
- "integrity": "sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "freebsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/freebsd-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.20.2.tgz",
- "integrity": "sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "freebsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-arm": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.20.2.tgz",
- "integrity": "sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==",
- "cpu": [
- "arm"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-arm64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.20.2.tgz",
- "integrity": "sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-ia32": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.20.2.tgz",
- "integrity": "sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==",
- "cpu": [
- "ia32"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-loong64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.20.2.tgz",
- "integrity": "sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==",
- "cpu": [
- "loong64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-mips64el": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.20.2.tgz",
- "integrity": "sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==",
- "cpu": [
- "mips64el"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-ppc64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.20.2.tgz",
- "integrity": "sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==",
- "cpu": [
- "ppc64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-riscv64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.20.2.tgz",
- "integrity": "sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==",
- "cpu": [
- "riscv64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/linux-s390x": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.20.2.tgz",
- "integrity": "sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==",
- "cpu": [
- "s390x"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "linux"
- ],
- "engines": {
- "node": ">=12"
- }
- },
"node_modules/@esbuild/linux-x64": {
"version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.20.2.tgz",
- "integrity": "sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==",
"cpu": [
"x64"
],
"dev": true,
+ "license": "MIT",
"optional": true,
"os": [
"linux"
@@ -281,108 +27,11 @@
"node": ">=12"
}
},
- "node_modules/@esbuild/netbsd-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.20.2.tgz",
- "integrity": "sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "netbsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/openbsd-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.20.2.tgz",
- "integrity": "sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "openbsd"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/sunos-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.20.2.tgz",
- "integrity": "sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "sunos"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-arm64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.20.2.tgz",
- "integrity": "sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==",
- "cpu": [
- "arm64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-ia32": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.20.2.tgz",
- "integrity": "sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==",
- "cpu": [
- "ia32"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
- "node_modules/@esbuild/win32-x64": {
- "version": "0.20.2",
- "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.20.2.tgz",
- "integrity": "sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==",
- "cpu": [
- "x64"
- ],
- "dev": true,
- "optional": true,
- "os": [
- "win32"
- ],
- "engines": {
- "node": ">=12"
- }
- },
"node_modules/esbuild": {
"version": "0.20.2",
- "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz",
- "integrity": "sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==",
"dev": true,
"hasInstallScript": true,
+ "license": "MIT",
"bin": {
"esbuild": "bin/esbuild"
},
@@ -417,15 +66,17 @@
},
"node_modules/esbuild-server": {
"version": "0.3.0",
- "resolved": "https://registry.npmjs.org/esbuild-server/-/esbuild-server-0.3.0.tgz",
- "integrity": "sha512-8RuzIdM13gs7MyYwxn/c88nDdx086aREBvzWDk4G3cC7nudF8480OTrvAvanVmFZ9anDv9U4cRX/OKbladaRVA==",
"dev": true,
+ "license": "MIT",
"engines": {
"node": ">=14"
},
"peerDependencies": {
"esbuild": ">=0.17.0"
}
+ },
+ "node_modules/svg-pan-zoom": {
+ "resolved": "git+ssh://git@github.com/webdevcat-me/svg-pan-zoom.git#119a1e207f0902becbf67caf30e564efb72b0b2a"
}
}
}
diff --git a/package.json b/package.json
index 8493051..54db50a 100644
--- a/package.json
+++ b/package.json
@@ -2,5 +2,8 @@
"devDependencies": {
"esbuild": "^0.20.2",
"esbuild-server": "^0.3.0"
+ },
+ "dependencies": {
+ "svg-pan-zoom": "github:webdevcat-me/svg-pan-zoom"
}
}
diff --git a/public/map.css b/public/map.css
index 7001821..b672ad9 100644
--- a/public/map.css
+++ b/public/map.css
@@ -10,27 +10,25 @@ text {
user-select: none;
}
-use[href="#point"], use[href="#hex"] {
+use[href="#hex"] {
opacity: 1;
fill: teal;
fill-opacity: 0.2;
stroke-width: 0.5px;
}
-use[href="#point"]:hover,
-use[href="#point"].hover,
-use[href="#hex"]:hover,
-use[href="#hex"].hover {
+use[href="#hex"]:hover, use[href="#hex"].hover
+ {
opacity: 1;
fill: orange;
stroke: orangered;
}
-use[href="#point"].active, use[href="#hex"].active {
+use[href="#hex"].active {
opacity: 0.2;
}
-use[href="#point"].sight-line-target, use[href="#hex"].sight-line-target {
+use[href="#hex"].sight-line-target {
opacity: 1;
stroke: orangered;
fill-opacity: 0.04;
@@ -46,10 +44,6 @@ polyline.move-trace {
fill: #bacae3;
}
-g#grid {
- transform: translate(19px, 31px) scale(4);
-}
-
#map2 {
transform-origin: 0px 0px;
transform: translate(-0.9px, -2.4px) scale(0.999, 1.007);
@@ -163,7 +157,7 @@ polygon.firing-arc[data-troop-allegiance="liao"] {
pointer-events: none;
}
-defs #point, #hex {
+#hex {
fill: inherit;
fill-opacity: inherit;
stroke: inherit;
@@ -180,19 +174,7 @@ use[href="#davion-1"]:hover {
transform: scale(2);
}
-g.col:hover {
- --scale: 0.97;
-}
-
-g.col:hover use[href="#hex"] {
- fill: orange;
- stroke: orangered;
-}
-
-g.col:hover use[href="#davion-1"] {
- transform: scale(1.5);
-}
-
+/* Inradius and circumradius values come from the hexagon */
.grid {
--inradius: 8.66px;
--circumradius: 10px;
@@ -201,26 +183,115 @@ g.col:hover use[href="#davion-1"] {
transform: translate(19px, 31px) scale(4);
}
-g.row {
+g[data-y] {
--translateX: 0;
- transform: translate(var(--translateX), calc(var(--y-step) * (var(--n) - 1)));
+ transform: translate(var(--translateX), calc(var(--y-step) * var(--i)));
}
-g.row:nth-child(odd) {
+g[data-y]:nth-child(odd) {
--translateX: calc(var(--inradius));
}
-g.row:nth-child(1) { --n: 1; }
-g.row:nth-child(2) { --n: 2; }
-g.row:nth-child(3) { --n: 3; }
-g.row:nth-child(4) { --n: 4; }
+g[data-x]:hover {
+ --scale: 0.97;
+}
-g.col {
- --scale: 1;
- transform: translateX(calc(var(--x-step) * (var(--n) - 1))) scale(var(--scale));
+g[data-x]:hover use[href="#hex"] {
+ fill: orange;
+ stroke: orangered;
}
-g.col:nth-child(1) { --n: 1; }
-g.col:nth-child(2) { --n: 2; }
-g.col:nth-child(3) { --n: 3; }
-g.col:nth-child(4) { --n: 4; }
\ No newline at end of file
+g[data-x]:hover use[href="#davion-1"] {
+ transform: scale(1.5);
+}
+
+g[data-x] {
+ --scale: 1;
+ transform: translateX(calc(var(--x-step) * var(--i))) scale(var(--scale));
+}
+
+g[data-y="0"] { --i: 0; }
+g[data-y="1"] { --i: 1; }
+g[data-y="2"] { --i: 2; }
+g[data-y="3"] { --i: 3; }
+g[data-y="4"] { --i: 4; }
+g[data-y="5"] { --i: 5; }
+g[data-y="6"] { --i: 6; }
+g[data-y="7"] { --i: 7; }
+g[data-y="8"] { --i: 8; }
+g[data-y="9"] { --i: 9; }
+g[data-y="10"] { --i: 10; }
+g[data-y="11"] { --i: 11; }
+g[data-y="12"] { --i: 12; }
+g[data-y="13"] { --i: 13; }
+g[data-y="14"] { --i: 14; }
+g[data-y="15"] { --i: 15; }
+g[data-y="16"] { --i: 16; }
+g[data-y="17"] { --i: 17; }
+g[data-y="18"] { --i: 18; }
+g[data-y="19"] { --i: 19; }
+g[data-y="20"] { --i: 20; }
+g[data-y="21"] { --i: 21; }
+g[data-y="22"] { --i: 22; }
+g[data-y="23"] { --i: 23; }
+g[data-y="24"] { --i: 24; }
+g[data-y="25"] { --i: 25; }
+g[data-y="26"] { --i: 26; }
+g[data-y="27"] { --i: 27; }
+g[data-y="28"] { --i: 28; }
+g[data-y="29"] { --i: 29; }
+g[data-y="30"] { --i: 30; }
+g[data-y="31"] { --i: 31; }
+g[data-y="32"] { --i: 32; }
+g[data-y="33"] { --i: 33; }
+g[data-y="34"] { --i: 34; }
+g[data-y="35"] { --i: 35; }
+g[data-y="36"] { --i: 36; }
+g[data-y="37"] { --i: 37; }
+g[data-y="38"] { --i: 38; }
+g[data-y="39"] { --i: 39; }
+g[data-y="40"] { --i: 40; }
+g[data-y="41"] { --i: 41; }
+g[data-y="42"] { --i: 42; }
+g[data-y="43"] { --i: 43; }
+g[data-y="44"] { --i: 44; }
+g[data-y="45"] { --i: 45; }
+g[data-y="46"] { --i: 46; }
+g[data-y="47"] { --i: 47; }
+g[data-y="48"] { --i: 48; }
+g[data-y="49"] { --i: 49; }
+g[data-y="50"] { --i: 50; }
+
+g[data-x="0"] { --i: 0; }
+g[data-x="1"] { --i: 1; }
+g[data-x="2"] { --i: 2; }
+g[data-x="3"] { --i: 3; }
+g[data-x="4"] { --i: 4; }
+g[data-x="5"] { --i: 5; }
+g[data-x="6"] { --i: 6; }
+g[data-x="7"] { --i: 7; }
+g[data-x="8"] { --i: 8; }
+g[data-x="9"] { --i: 9; }
+g[data-x="10"] { --i: 10; }
+g[data-x="11"] { --i: 11; }
+g[data-x="12"] { --i: 12; }
+g[data-x="13"] { --i: 13; }
+g[data-x="14"] { --i: 14; }
+g[data-x="15"] { --i: 15; }
+g[data-x="16"] { --i: 16; }
+g[data-x="17"] { --i: 17; }
+g[data-x="18"] { --i: 18; }
+g[data-x="19"] { --i: 19; }
+g[data-x="20"] { --i: 20; }
+g[data-x="21"] { --i: 21; }
+g[data-x="22"] { --i: 22; }
+g[data-x="23"] { --i: 23; }
+g[data-x="24"] { --i: 24; }
+g[data-x="25"] { --i: 25; }
+g[data-x="26"] { --i: 26; }
+g[data-x="27"] { --i: 27; }
+g[data-x="28"] { --i: 28; }
+g[data-x="29"] { --i: 29; }
+g[data-x="30"] { --i: 30; }
+g[data-x="31"] { --i: 31; }
+g[data-x="32"] { --i: 32; }
diff --git a/public/map.svg b/public/map.svg
index 3f869ce..3023271 100644
--- a/public/map.svg
+++ b/public/map.svg
@@ -1,10 +1,9 @@
-
diff --git a/src/index.js b/src/index.js
index 20a0623..9a114d7 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,3 +1,5 @@
+import { pan, zoom } from 'svg-pan-zoom';
+
function isEven(n) {
return n % 2 === 0;
}
@@ -23,10 +25,10 @@ function calculateAngle(xDiff, yDiff) {
function edgePoint(x1, y1, x2, y2, maxX, maxY) {
let pointCoords,
- xDiff = x2 - x1,
- yDiff = y2 - y1,
- xIntercept = y => (y - y1) * xDiff / yDiff + x1,
- yIntercept = x => (x - x1) * yDiff / xDiff + y1;
+ xDiff = x2 - x1,
+ yDiff = y2 - y1,
+ xIntercept = y => (y - y1) * xDiff / yDiff + x1,
+ yIntercept = x => (x - x1) * yDiff / xDiff + y1;
if (xDiff > 0 && yDiff > 0) {
let x = xIntercept(maxY);
@@ -50,11 +52,11 @@ function edgePoint(x1, y1, x2, y2, maxX, maxY) {
}
function evenr_to_axial(x, y) {
- return {q: x - (y + (y & 1)) / 2, r: y};
+ return { q: x - (y + (y & 1)) / 2, r: y };
}
function axial_to_evenr(q, r) {
- return {x: q + (r + (r & 1)) / 2, y: r};
+ return { x: q + (r + (r & 1)) / 2, y: r };
}
function axial_distance(q1, r1, q2, r2) {
@@ -63,7 +65,7 @@ function axial_distance(q1, r1, q2, r2) {
function offset_distance(x1, y1, x2, y2) {
let { q: q1, r: r1 } = evenr_to_axial(x1, y1),
- { q: q2, r: r2 } = evenr_to_axial(x2, y2);
+ { q: q2, r: r2 } = evenr_to_axial(x2, y2);
return axial_distance(q1, r1, q2, r2);
}
@@ -73,7 +75,7 @@ function cube_to_axial(q, r, s) {
}
function axial_to_cube(q, r) {
- return { q: q, r: r, s: -q - r};
+ return { q: q, r: r, s: -q - r };
}
function cube_round(q, r, s) {
@@ -82,8 +84,8 @@ function cube_round(q, r, s) {
rS = Math.round(s);
let q_diff = Math.abs(rQ - q),
- r_diff = Math.abs(rR - r),
- s_diff = Math.abs(rS - s);
+ r_diff = Math.abs(rR - r),
+ s_diff = Math.abs(rS - s);
if (q_diff > r_diff && q_diff > s_diff) {
rQ = -rR - rS;
@@ -93,15 +95,15 @@ function cube_round(q, r, s) {
rS = -rQ - rR;
}
- return {q: rQ, r: rR, s: rS};
+ return { q: rQ, r: rR, s: rS };
}
function axial_round(q, r) {
let cube = axial_to_cube(q, r),
- round = cube_round(cube.q, cube.r, cube.s),
- axial = cube_to_axial(round.q, round.r, round.s);
+ round = cube_round(cube.q, cube.r, cube.s),
+ axial = cube_to_axial(round.q, round.r, round.s);
- return {q: axial.q, r: axial.r};
+ return { q: axial.q, r: axial.r };
}
function lerp(a, b, t) {
@@ -114,14 +116,14 @@ function axial_lerp(q1, r1, q2, r2, t) {
function linedraw(x1, y1, x2, y2) {
let axial1 = evenr_to_axial(x1, y1),
- axial2 = evenr_to_axial(x2, y2),
- n = offset_distance(x1, y1, x2, y2),
- results = [];
+ axial2 = evenr_to_axial(x2, y2),
+ n = offset_distance(x1, y1, x2, y2),
+ results = [];
for (let i = 0; i <= n; i++) {
let lerp = axial_lerp(axial1.q, axial1.r, axial2.q, axial2.r, 1.0 / n * i),
- round = axial_round(lerp.q, lerp.r),
- { x, y } = axial_to_evenr(round.q, round.r);
+ round = axial_round(lerp.q, lerp.r),
+ { x, y } = axial_to_evenr(round.q, round.r);
results.push([x, y]);
}
@@ -129,39 +131,68 @@ function linedraw(x1, y1, x2, y2) {
return results;
}
+const PanZoom = new function () {
+ this.start = function (svg) {
+ svg.addEventListener('wheel', e => {
+ e.preventDefault();
+
+ svg.setAttributeNS(null, 'viewBox', zoom(svg, e));
+ }, { passive: false });
+
+ svg.addEventListener('pointerdown', e => {
+ e.preventDefault();
+
+ pan(svg, e);
+ }, { passive: false });
+ }
+};
+
window.addEventListener('load', () => {
const svgns = "http://www.w3.org/2000/svg",
- // svg = document.querySelector('svg'),
- svg = document.querySelector('object').contentDocument.querySelector('svg'),
- hex = svg.querySelector('#point'),
- ptGrp = svg.querySelector('#points'),
- cntrGrp = svg.querySelector('#counters'),
- settingsPanel = document.getElementById('panel'),
- recordSheetVisibility = document.querySelector('#content input[type="checkbox"].visible');
+ // svg = document.querySelector('svg'),
+ // hex = svg.querySelector('#point'),
+ svg = document.querySelector('object').contentDocument.querySelector('svg'),
+ hex = svg.querySelector('#hex'),
+ ptGrp = svg.querySelector('#points'),
+ cntrGrp = svg.querySelector('#counters'),
+ settingsPanel = document.getElementById('panel'),
+ recordSheetVisibility = document.querySelector('#content input[type="checkbox"].visible');
+
+ PanZoom.start(svg);
+
+ let cells = svg.querySelectorAll('g[data-x]');
+
+ cells.forEach(cell => {
+ cell.addEventListener('click', e => {
+ let { dataset: { x }, parentElement: { dataset: { y }}} = cell;
+
+ console.log(`Cell at index { x: ${x}, y: ${y} } clicked.`);
+ }
+ )});
const q = s => document.querySelector(s),
- qA = s => document.querySelectorAll(s);
+ qA = s => document.querySelectorAll(s);
const { x: VIEWBOX_X, y: VIEWBOX_Y, width: VIEWBOX_WIDTH, height: VIEWBOX_HEIGHT } =
svg.viewBox.baseVal;
const COLUMN_COUNT = 33,
- ROW_COUNT = 51,
- // const COLUMN_COUNT = 20,
- // ROW_COUNT = 20,
- HORZ_POINT_DISTANCE = 1.005,
- VERT_POINT_DISTANCE = Math.sqrt(3) * HORZ_POINT_DISTANCE / 2,
- ALTERNATING_OFFSET = HORZ_POINT_DISTANCE / 2,
- CIRCUMRADIUS = Math.max(...[...new Set(Object.values(hex.points).flatMap(({x, y}) => [x, y]))]),
- INRADIUS = CIRCUMRADIUS * Math.sqrt(3) / 2,
- [COLUMNS, ROWS] = [COLUMN_COUNT, ROW_COUNT].map(n => [...Array(n).keys()]),
- POINTS = ROWS.map(y => COLUMNS.map(x => [x, y]));
+ ROW_COUNT = 51,
+ // const COLUMN_COUNT = 20,
+ // ROW_COUNT = 20,
+ HORZ_POINT_DISTANCE = 1.005,
+ VERT_POINT_DISTANCE = Math.sqrt(3) * HORZ_POINT_DISTANCE / 2,
+ ALTERNATING_OFFSET = HORZ_POINT_DISTANCE / 2,
+ CIRCUMRADIUS = Math.max(...[...new Set(Object.values(hex.points).flatMap(({ x, y }) => [x, y]))]),
+ INRADIUS = CIRCUMRADIUS * Math.sqrt(3) / 2,
+ [COLUMNS, ROWS] = [COLUMN_COUNT, ROW_COUNT].map(n => [...Array(n).keys()]),
+ POINTS = ROWS.map(y => COLUMNS.map(x => [x, y]));
const FIRING_ARC_SIZE = {
- 'small': Math.atan(HORZ_POINT_DISTANCE / (6 * VERT_POINT_DISTANCE)),
- 'medium': Math.atan((HORZ_POINT_DISTANCE / 2) / VERT_POINT_DISTANCE),
- 'large': Math.atan((21 * HORZ_POINT_DISTANCE) / (6 * VERT_POINT_DISTANCE))
- };
+ 'small': Math.atan(HORZ_POINT_DISTANCE / (6 * VERT_POINT_DISTANCE)),
+ 'medium': Math.atan((HORZ_POINT_DISTANCE / 2) / VERT_POINT_DISTANCE),
+ 'large': Math.atan((21 * HORZ_POINT_DISTANCE) / (6 * VERT_POINT_DISTANCE))
+ };
function positionFiringArc(e) {
let activeFiringArc = svg.querySelector('polygon.firing-arc.active');
@@ -170,12 +201,12 @@ window.addEventListener('load', () => {
if (activeFiringArc) {
let activeFiringArcOutline = svg.querySelector(`#lines polygon[data-troop-number="${activeFiringArc.dataset.troopNumber}"][data-troop-allegiance="${activeFiringArc.dataset.troopAllegiance}"]`);
- board = svg.querySelector('#image-maps'),
- { width, height } = board.getBBox(),
- pt = new DOMPoint(e.clientX, e.clientY),
- { x: pointerX, y: pointerY } = pt.matrixTransform(board.getScreenCTM().inverse()),
- [maxXpx, maxYpx] = [width, height],
- {x: x1px, y: y1px} = activeFiringArc.points[0];
+ board = svg.querySelector('#image-maps'),
+ { width, height } = board.getBBox(),
+ pt = new DOMPoint(e.clientX, e.clientY),
+ { x: pointerX, y: pointerY } = pt.matrixTransform(board.getScreenCTM().inverse()),
+ [maxXpx, maxYpx] = [width, height],
+ { x: x1px, y: y1px } = activeFiringArc.points[0];
let [x2px, y2px] = [
pointerX / width * maxXpx,
@@ -187,7 +218,7 @@ window.addEventListener('load', () => {
let angle = calculateAngle(xDiff, yDiff);
let arcAngle = FIRING_ARC_SIZE[activeFiringArc.dataset.size];
- let distance = Math.sqrt((x2px - x1px)**2 + (y2px - y1px)**2);
+ let distance = Math.sqrt((x2px - x1px) ** 2 + (y2px - y1px) ** 2);
let yDelta = distance * Math.cos(angle) * Math.tan(arcAngle);
let xDelta = distance * Math.sin(angle) * Math.tan(arcAngle);
@@ -331,133 +362,133 @@ window.addEventListener('load', () => {
const grid = svg.querySelector('#grid');
- const Counter = new function() {
+ const Counter = new function () {
let container = ptGrp,
- selectedClass = 'selected',
-
- dataSelector = function(troopNumber, allegiance) {
- return `[data-troop-number="${troopNumber}"][data-troop-allegiance="${allegiance}"]`;
- },
-
- selector = function(troopNumber, allegiance) {
- return `use.counter${dataSelector(troopNumber, allegiance)}`;
- },
-
- position = function(x, y) {
- return `g[data-x="${x}"][data-y="${y}"]`;
- },
-
- counterPosition = function(x, y) {
- return `use.counter[data-x="${x}"][data-x="${y}"]`;
- },
-
- traceSelector = function(troopNumber, allegiance) {
- return `polyline.move-trace${dataSelector(troopNumber, allegiance)}`;
- },
-
- clickClone = function() {
- let { troopNumber, troopAllegiance, x, y } = this.dataset,
- [xAttr, yAttr] = this.parentElement.getAttribute('transform').match(/-?\d+\.?\d*/g);
-
- if (Counter.isSelected(troopNumber, troopAllegiance)) {
- let trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance)),
- points = trace.getAttribute('points').split(' ');
-
- if (`${xAttr},${yAttr}` == points.at(0)) {
- let counter = Counter.get(troopNumber, troopAllegiance);
- counter.setAttributeNS(null, 'x', 0);
- counter.setAttributeNS(null, 'y', 0);
- counter.dataset.x = x;
- counter.dataset.y = y;
- container.querySelector(`g[data-x="${x}"][data-y="${y}"]`).appendChild(counter);
-
- Counter.removeClones(this);
- trace.remove();
- } else {
- points = points.filter(p => p != `${xAttr},${yAttr}`).join(' ');
-
- trace.setAttributeNS(null, 'points', points);
- }
+ selectedClass = 'selected',
+
+ dataSelector = function (troopNumber, allegiance) {
+ return `[data-troop-number="${troopNumber}"][data-troop-allegiance="${allegiance}"]`;
+ },
+
+ selector = function (troopNumber, allegiance) {
+ return `use.counter${dataSelector(troopNumber, allegiance)}`;
+ },
+
+ position = function (x, y) {
+ return `g[data-x="${x}"][data-y="${y}"]`;
+ },
+
+ counterPosition = function (x, y) {
+ return `use.counter[data-x="${x}"][data-x="${y}"]`;
+ },
+
+ traceSelector = function (troopNumber, allegiance) {
+ return `polyline.move-trace${dataSelector(troopNumber, allegiance)}`;
+ },
+
+ clickClone = function () {
+ let { troopNumber, troopAllegiance, x, y } = this.dataset,
+ [xAttr, yAttr] = this.parentElement.getAttribute('transform').match(/-?\d+\.?\d*/g);
+
+ if (Counter.isSelected(troopNumber, troopAllegiance)) {
+ let trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance)),
+ points = trace.getAttribute('points').split(' ');
+
+ if (`${xAttr},${yAttr}` == points.at(0)) {
+ let counter = Counter.get(troopNumber, troopAllegiance);
+ counter.setAttributeNS(null, 'x', 0);
+ counter.setAttributeNS(null, 'y', 0);
+ counter.dataset.x = x;
+ counter.dataset.y = y;
+ container.querySelector(`g[data-x="${x}"][data-y="${y}"]`).appendChild(counter);
+
+ Counter.removeClones(this);
+ trace.remove();
+ } else {
+ points = points.filter(p => p != `${xAttr},${yAttr}`).join(' ');
- this.remove();
+ trace.setAttributeNS(null, 'points', points);
}
- },
- pointerOver = function() {
- let { troopNumber, troopAllegiance } = this.dataset;
- cp = svg.querySelector(`#clip-path-${troopAllegiance}-${troopNumber}`);
+ this.remove();
+ }
+ },
- if (cp) {
- cp.style.display = 'none';
- }
- },
+ pointerOver = function () {
+ let { troopNumber, troopAllegiance } = this.dataset;
+ cp = svg.querySelector(`#clip-path-${troopAllegiance}-${troopNumber}`);
- pointerOut = function() {
- let { troopNumber, troopAllegiance } = this.dataset;
- cp = svg.querySelector(`#clip-path-${troopAllegiance}-${troopNumber}`);
+ if (cp) {
+ cp.style.display = 'none';
+ }
+ },
- if (cp) {
- let isVisible =
- document
- .getElementById('toggle-firing-arc-vis')
- .querySelector(`input[data-allegiance="${troopAllegiance}"]`)
- .checked;
+ pointerOut = function () {
+ let { troopNumber, troopAllegiance } = this.dataset;
+ cp = svg.querySelector(`#clip-path-${troopAllegiance}-${troopNumber}`);
- cp.style.display = isVisible ? 'none' : '';
- }
- },
+ if (cp) {
+ let isVisible =
+ document
+ .getElementById('toggle-firing-arc-vis')
+ .querySelector(`input[data-allegiance="${troopAllegiance}"]`)
+ .checked;
- click = function() {
- if (this.classList.contains(selectedClass)) {
- let { troopNumber, troopAllegiance } = this.dataset,
- trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
+ cp.style.display = isVisible ? 'none' : '';
+ }
+ },
- if (trace) {
- let points = trace.getAttribute('points').split(' '),
- [xAttr, yAttr] = points.at(-2).split(','),
- clone = container.querySelector(`g[transform="translate(${xAttr} ${yAttr})"] ${dataSelector(troopNumber, troopAllegiance)}.clone`);
+ click = function () {
+ if (this.classList.contains(selectedClass)) {
+ let { troopNumber, troopAllegiance } = this.dataset,
+ trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
- points.pop();
+ if (trace) {
+ let points = trace.getAttribute('points').split(' '),
+ [xAttr, yAttr] = points.at(-2).split(','),
+ clone = container.querySelector(`g[transform="translate(${xAttr} ${yAttr})"] ${dataSelector(troopNumber, troopAllegiance)}.clone`);
- if (points.length >= 2) {
- trace.setAttributeNS(null, 'points', points.join(' '));
- } else {
- trace.remove();
- }
+ points.pop();
- this.setAttributeNS(null, 'x', clone.getAttribute('x'));
- this.setAttributeNS(null, 'y', clone.getAttribute('y'));
- this.dataset.x = clone.dataset.x;
- this.dataset.y = clone.dataset.y;
+ if (points.length >= 2) {
+ trace.setAttributeNS(null, 'points', points.join(' '));
+ } else {
+ trace.remove();
+ }
- container.querySelector(`g[data-x="${this.dataset.x}"][data-y="${this.dataset.y}"]`).appendChild(this);
+ this.setAttributeNS(null, 'x', clone.getAttribute('x'));
+ this.setAttributeNS(null, 'y', clone.getAttribute('y'));
+ this.dataset.x = clone.dataset.x;
+ this.dataset.y = clone.dataset.y;
- clone.remove();
- }
+ container.querySelector(`g[data-x="${this.dataset.x}"][data-y="${this.dataset.y}"]`).appendChild(this);
+
+ clone.remove();
}
- },
+ }
+ },
- dblClick = function() {
- if (this.classList.contains(selectedClass)) {
- let { troopNumber, troopAllegiance } = this.dataset,
- trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
+ dblClick = function () {
+ if (this.classList.contains(selectedClass)) {
+ let { troopNumber, troopAllegiance } = this.dataset,
+ trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
- if (!trace) {
- Counter.remove(this);
- svg.querySelectorAll(`#firing-arcs ${dataSelector(troopNumber, troopAllegiance)}`).forEach(el => el.remove());
- }
+ if (!trace) {
+ Counter.remove(this);
+ svg.querySelectorAll(`#firing-arcs ${dataSelector(troopNumber, troopAllegiance)}`).forEach(el => el.remove());
}
- };
+ }
+ };
- this.get = function(troopNumber, allegiance) {
+ this.get = function (troopNumber, allegiance) {
return container.querySelector(`${selector(troopNumber, allegiance)}:not(.clone)`);
};
- this.getAt = function(x, y) {
+ this.getAt = function (x, y) {
return container.querySelector(`${counterPosition(x, y)}:not(.clone)`);
};
- this.select = function({ dataset: { troopNumber, troopAllegiance }}) {
+ this.select = function ({ dataset: { troopNumber, troopAllegiance } }) {
this.unSelect();
let counter = container.querySelector(`${selector(troopNumber, troopAllegiance)}:not(.clone)`);
@@ -467,7 +498,7 @@ window.addEventListener('load', () => {
}
};
- this.unSelect = function() {
+ this.unSelect = function () {
let selected = container.querySelector(`.${selectedClass}`);
if (selected) {
@@ -482,35 +513,35 @@ window.addEventListener('load', () => {
}
};
- this.isSelected = function(troopNumber, allegiance) {
+ this.isSelected = function (troopNumber, allegiance) {
return container.querySelector(`${selector(troopNumber, allegiance)}.${selectedClass}`) !== null;
};
- this.place = function({ dataset: { troopNumber, troopAllegiance }}, point) {
+ this.place = function ({ dataset: { troopNumber, troopAllegiance } }, point) {
let counter, points,
- counterNodeList = container.querySelectorAll(selector(troopNumber, troopAllegiance));
+ counterNodeList = container.querySelectorAll(selector(troopNumber, troopAllegiance));
if (counterNodeList.length > 0) {
let counters = Array.from(counterNodeList),
- original = counters.find(el => !el.classList.contains('clone')),
- trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
+ original = counters.find(el => !el.classList.contains('clone')),
+ trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
// let ptContainers = counters.map(c => ptGrp.querySelector(position(c.dataset.x, c.dataset.y)));
let current = {
- x: point.dataset.x,
- y: point.dataset.y,
- // xAttr: point.getAttribute('x'),
- // yAttr: point.getAttribute('y'),
- transform: container.querySelector(position(point.dataset.x, point.dataset.y)).getAttribute('transform')
- },
- previous = {
- x: original.dataset.x,
- y: original.dataset.y,
- // xAttr: original.getAttribute('x'),
- // yAttr: original.getAttribute('y'),
- transform: container.querySelector(position(original.dataset.x, original.dataset.y)).getAttribute('transform')
- };
+ x: point.dataset.x,
+ y: point.dataset.y,
+ // xAttr: point.getAttribute('x'),
+ // yAttr: point.getAttribute('y'),
+ transform: container.querySelector(position(point.dataset.x, point.dataset.y)).getAttribute('transform')
+ },
+ previous = {
+ x: original.dataset.x,
+ y: original.dataset.y,
+ // xAttr: original.getAttribute('x'),
+ // yAttr: original.getAttribute('y'),
+ transform: container.querySelector(position(original.dataset.x, original.dataset.y)).getAttribute('transform')
+ };
[current.xAttr, current.yAttr] = current.transform.match(/-?\d+\.?\d*/g);
[previous.xAttr, previous.yAttr] = previous.transform.match(/-?\d+\.?\d*/g);
@@ -549,7 +580,7 @@ window.addEventListener('load', () => {
} else {
counter = document.createElementNS(svgns, 'use'),
- counter.setAttributeNS(null, 'href', `#${troopAllegiance}-${troopNumber}`);
+ counter.setAttributeNS(null, 'href', `#${troopAllegiance}-${troopNumber}`);
counter.classList.add('counter', 'selected');
counter.setAttributeNS(null, 'x', point.getAttribute('x'));
counter.setAttributeNS(null, 'y', point.getAttribute('y'));
@@ -570,19 +601,19 @@ window.addEventListener('load', () => {
// container.appendChild(counter);
};
- this.remove = function({ dataset: { troopNumber, troopAllegiance }}) {
+ this.remove = function ({ dataset: { troopNumber, troopAllegiance } }) {
container
.querySelectorAll(dataSelector(troopNumber, troopAllegiance))
.forEach(el => el.remove());
};
- this.removeClones = function({ dataset: { troopNumber, troopAllegiance }}) {
+ this.removeClones = function ({ dataset: { troopNumber, troopAllegiance } }) {
container
.querySelectorAll(`${selector(troopNumber, troopAllegiance)}.clone`)
.forEach(el => el.remove());
};
- this.endMove = function(el) {
+ this.endMove = function (el) {
let { troopNumber, troopAllegiance } = el.dataset;
let trace = grid.querySelector(traceSelector(troopNumber, troopAllegiance));
@@ -593,20 +624,20 @@ window.addEventListener('load', () => {
Counter.removeClones(el);
};
- this.hasProne = function(troopNumber, troopAllegiance) {
+ this.hasProne = function (troopNumber, troopAllegiance) {
let selector = `g#${troopAllegiance}-${troopNumber} use[href="#counter-prone"]`;
return !!svg.querySelector(selector);
};
};
- const RecordSheet = new function() {
- let clipUnclippedFiringArcs = function() {
+ const RecordSheet = new function () {
+ let clipUnclippedFiringArcs = function () {
let unclipped = svg.querySelectorAll('#firing-arcs polygon:not([clip-path])');
unclipped.forEach(el => {
let { troopNumber, troopAllegiance } = el.dataset,
- clipPathId = `clip-path-${troopAllegiance}-${troopNumber}`;
+ clipPathId = `clip-path-${troopAllegiance}-${troopNumber}`;
let isVisible =
document
@@ -622,7 +653,7 @@ window.addEventListener('load', () => {
});
};
- this.unSelect = function() {
+ this.unSelect = function () {
let selected = this.getSelected();
if (selected) {
@@ -634,13 +665,13 @@ window.addEventListener('load', () => {
Counter.unSelect();
};
- this.getSelected = function() {
+ this.getSelected = function () {
return document.querySelector('.soldier-record.selected');
};
- this.select = function(el) {
+ this.select = function (el) {
let { troopNumber, troopAllegiance } = el.dataset,
- proneStatus = Counter.hasProne(troopNumber, troopAllegiance);
+ proneStatus = Counter.hasProne(troopNumber, troopAllegiance);
RecordSheet.unSelect();
document.querySelector(`#record-sheet .soldier-record[data-troop-number="${troopNumber}"][data-troop-allegiance="${troopAllegiance}"]`).classList.add('selected');
@@ -650,8 +681,8 @@ window.addEventListener('load', () => {
};
};
- const SightLine = new function() {
- this.clear = function() {
+ const SightLine = new function () {
+ this.clear = function () {
let sl = grid.querySelector('line.sight-line');
let target = grid.querySelector(`use[href="#point"].sight-line-target`);
@@ -666,18 +697,18 @@ window.addEventListener('load', () => {
this.clearHexes();
};
- this.clearHexes = function() {
+ this.clearHexes = function () {
ptGrp.querySelectorAll('use[href="#point"].active').forEach(el => el.classList.remove('active'));
};
- this.draw = function(x1, y1, x2, y2) {
+ this.draw = function (x1, y1, x2, y2) {
let source = ptGrp.querySelector(`g[data-x="${x1}"][data-y="${y1}"]`),
- target = ptGrp.querySelector(`g[data-x="${x2}"][data-y="${y2}"]`),
+ target = ptGrp.querySelector(`g[data-x="${x2}"][data-y="${y2}"]`),
- [slX1, slY1] = source.getAttribute('transform').match(/-?\d+\.?\d*/g),
- [slX2, slY2] = target.getAttribute('transform').match(/-?\d+\.?\d*/g),
+ [slX1, slY1] = source.getAttribute('transform').match(/-?\d+\.?\d*/g),
+ [slX2, slY2] = target.getAttribute('transform').match(/-?\d+\.?\d*/g),
- sightLine = document.createElementNS(svgns, 'line');
+ sightLine = document.createElementNS(svgns, 'line');
sightLine.classList.add('sight-line');
sightLine.classList.add('active');
@@ -692,7 +723,7 @@ window.addEventListener('load', () => {
this.drawHexes(...coords);
};
- this.drawHexes = function(...coords) {
+ this.drawHexes = function (...coords) {
this.clearHexes()
info.querySelector('#hex-count').textContent = offset_distance(...coords);
@@ -706,10 +737,29 @@ window.addEventListener('load', () => {
};
};
+
// POINTS.forEach((row, index) => row.forEach(([x, y]) => {
- [].forEach(() => row.forEach(([x, y]) => {
- let group = svg.querySelector(`g[data-x="${x}"][data-y="${y}"]`);
- let point = group.querySelector(`use[href="#point"]`);
+ [].forEach((row, index) => row.forEach(([x, y]) => {
+ var cx = x * INRADIUS * 2 + (isEven(index) ? INRADIUS : 0),
+ cy = y * 3 / 2 * CIRCUMRADIUS,
+ point = document.createElementNS(svgns, 'use'),
+ group = document.createElementNS(svgns, 'g');
+
+ cx = parseFloat(cx.toFixed(1));
+ cy = parseFloat(cy.toFixed(1));
+
+ point.setAttributeNS(null, 'href', `#point`);
+ point.setAttributeNS(null, 'x', 0);
+ point.setAttributeNS(null, 'y', 0);
+
+ point.dataset.x = x;
+ point.dataset.y = y;
+
+ group.setAttributeNS(null, 'transform', `translate(${cx} ${cy})`);
+ group.dataset.x = x;
+ group.dataset.y = y;
+
+ group.appendChild(point);
group.addEventListener('pointerout', e => {
group.classList.remove('hover');
@@ -717,23 +767,23 @@ window.addEventListener('load', () => {
group.addEventListener('click', e => {
let cl = e.target.classList,
- sl = grid.querySelector('line.sight-line'),
- targetIsSomeOtherUnitCounter = cl.contains('counter') && !cl.contains('clone'),
- selected = RecordSheet.getSelected();
+ sl = grid.querySelector('line.sight-line'),
+ targetIsSomeOtherUnitCounter = cl.contains('counter') && !cl.contains('clone'),
+ selected = RecordSheet.getSelected();
// maybe we should start with, "are we clicking on a counter?"
if (sl) {
- let { troopNumber: sTn, troopAllegiance: sTa} = selected.dataset,
- { troopNumber: tTn, troopAllegiance: tTa} = e.target.dataset,
- sightLineInLockedPosition = !sl.classList.contains('active'),
- targetIsCounterOrCloneOfSelected = cl.contains('counter') && sTn == tTn && sTa == tTa;
+ let { troopNumber: sTn, troopAllegiance: sTa } = selected.dataset,
+ { troopNumber: tTn, troopAllegiance: tTa } = e.target.dataset,
+ sightLineInLockedPosition = !sl.classList.contains('active'),
+ targetIsCounterOrCloneOfSelected = cl.contains('counter') && sTn == tTn && sTa == tTa;
if (sightLineInLockedPosition && targetIsCounterOrCloneOfSelected) {
let counterParent = Counter.get(tTn, tTa).parentElement,
- [x, y] = counterParent.getAttribute('transform').match(/-?\d+\.?\d*/g),
- target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`),
- { x: x1, y: y1 } = counterParent.dataset,
- { x: x2, y: y2 } = target.dataset;
+ [x, y] = counterParent.getAttribute('transform').match(/-?\d+\.?\d*/g),
+ target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`),
+ { x: x1, y: y1 } = counterParent.dataset,
+ { x: x2, y: y2 } = target.dataset;
sl.setAttributeNS(null, 'x1', x);
sl.setAttributeNS(null, 'y1', y);
@@ -768,9 +818,9 @@ window.addEventListener('load', () => {
SightLine.clear();
} else {
let [x, y] = point.parentElement.getAttribute('transform').match(/-?\d+\.?\d*/g),
- target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`),
- { x: x1, y: y1 } = point.dataset,
- { x: x2, y: y2 } = target.dataset;
+ target = ptGrp.querySelector(`g[transform="translate(${sl.getAttribute('x2')} ${sl.getAttribute('y2')})"]`),
+ { x: x1, y: y1 } = point.dataset,
+ { x: x2, y: y2 } = target.dataset;
sl.setAttributeNS(null, 'x1', x);
sl.setAttributeNS(null, 'y1', y);
@@ -806,8 +856,8 @@ window.addEventListener('load', () => {
if (selected) {
let { troopNumber: tn, troopAllegiance: ta } = selected.dataset,
- counter = Counter.get(tn, ta),
- sl = svg.querySelector('line.sight-line');
+ counter = Counter.get(tn, ta),
+ sl = svg.querySelector('line.sight-line');
if (counter && (!sl || sl.classList.contains('active'))) {
if (counter.dataset.x !== e.target.dataset.x || counter.dataset.y !== e.target.dataset.y) {
@@ -833,7 +883,7 @@ window.addEventListener('load', () => {
});
// ptGrp.appendChild(document.createTextNode('\n '));
- // ptGrp.appendChild(group);
+ ptGrp.appendChild(group);
}));
document.querySelectorAll('.soldier-record').forEach(el =>
@@ -873,11 +923,11 @@ window.addEventListener('load', () => {
}));
document.querySelectorAll('.end-turn').forEach(el =>
- el.addEventListener('click', ({ target: { dataset: { allegiance }}}) => {
+ el.addEventListener('click', ({ target: { dataset: { allegiance } } }) => {
let dataSelector = `[data-troop-allegiance="${allegiance}"]`,
- records = Array.from(qA(`.soldier-record${dataSelector}`)),
- turnCounter = document.getElementById('turn-count'),
- { textContent: count, dataset: { update }} = turnCounter;
+ records = Array.from(qA(`.soldier-record${dataSelector}`)),
+ turnCounter = document.getElementById('turn-count'),
+ { textContent: count, dataset: { update } } = turnCounter;
el.setAttribute('disabled', '');
@@ -907,8 +957,8 @@ window.addEventListener('load', () => {
let selectedSoldier = document.querySelector('.soldier-record.selected');
if (selectedSoldier) {
- let {troopNumber, troopAllegiance} = selectedSoldier.dataset,
- counter = Counter.get(troopNumber, troopAllegiance);
+ let { troopNumber, troopAllegiance } = selectedSoldier.dataset,
+ counter = Counter.get(troopNumber, troopAllegiance);
let existingArcs = svg.querySelectorAll(
`#firing-arcs [data-troop-number="${troopNumber}"][data-troop-allegiance="${troopAllegiance}"]`
@@ -989,85 +1039,6 @@ window.addEventListener('load', () => {
}
}));
- svg.addEventListener('wheel', e => {
- e.preventDefault();
-
- const pt = new DOMPoint(e.clientX, e.clientY),
- svgP = pt.matrixTransform(svg.getScreenCTM().inverse());
-
- let { x, y, width, height } = svg.viewBox.baseVal,
-
- widthDelta = width * 0.25,
- heightDelta = height * 0.25,
-
- xChange = (svgP.x - x) / width * widthDelta,
- yChange = (svgP.y - y) / height * heightDelta,
-
- widthChange = (1 - ((svgP.x - x) / width)) * widthDelta,
- heightChange = (1 - ((svgP.y - y) / height)) * heightDelta,
-
- newX = parseInt(e.deltaY < 0 ? x + xChange : x - xChange),
- newWidth = parseInt(e.deltaY < 0 ? width - xChange - widthChange : width + xChange + widthChange),
-
- newY = parseInt(e.deltaY < 0 ? y + yChange : y - yChange),
- newHeight = parseInt(e.deltaY < 0 ? height - yChange - heightChange : height + yChange + heightChange);
-
- let vb = `${newX} ${newY} ${newWidth} ${newHeight}`
-
- // TODO attribute change event?
- localStorage.setItem('viewBox', vb);
- svg.setAttributeNS(null, 'viewBox', vb);
- }, { passive: false });
-
- svg.addEventListener('pointerdown', e => {
- e.preventDefault();
-
- const minPanDistanceThreshold = 5;
-
- let dist, ctm,
- pan = false,
- { x, y, width, height } = svg.viewBox.baseVal,
- startPt = new DOMPoint(e.clientX, e.clientY),
- movePt = new DOMPoint();
-
- function pointerMove(e) {
- movePt.x = e.clientX;
- movePt.y = e.clientY;
-
- if (!pan) {
- dist = Math.sqrt((movePt.x - startPt.x)**2 + (movePt.y - startPt.y)**2);
-
- if (dist >= minPanDistanceThreshold) {
- pan = true;
- svg.setPointerCapture(e.pointerId);
- startPt.x = e.clientX;
- startPt.y = e.clientY;
- }
- }
-
- if (pan) {
- ctm = svg.getScreenCTM().inverse();
-
- const [svgStartPt, svgMovePt] = [startPt, movePt].map(p => p.matrixTransform(ctm)),
- moveX = parseInt(svgStartPt.x - svgMovePt.x + x),
- moveY = parseInt(svgStartPt.y - svgMovePt.y + y);
-
- let vb = `${moveX} ${moveY} ${width} ${height}`;
-
- localStorage.setItem('viewBox', vb);
- svg.setAttributeNS(null, 'viewBox', vb);
- }
- }
-
- function pointerUp(e) {
- svg.removeEventListener('pointermove', pointerMove);
- svg.removeEventListener('pointerup', pointerUp);
- }
-
- svg.addEventListener('pointermove', pointerMove);
- svg.addEventListener('pointerup', pointerUp);
- }, { passive: false });
-
recordSheetVisibility.addEventListener('input', e => {
let divs = document.querySelectorAll('#content div');
@@ -1086,7 +1057,7 @@ window.addEventListener('load', () => {
clipPaths.forEach(cp => cp.style.display = el.checked ? 'none' : '');
}));
- document.getElementById('toggle-prone-counter').addEventListener('input', function(e) {
+ document.getElementById('toggle-prone-counter').addEventListener('input', function (e) {
let selected = RecordSheet.getSelected();
if (selected) {
@@ -1101,4 +1072,4 @@ window.addEventListener('load', () => {
}
}
});
-});
\ No newline at end of file
+});
--
cgit v1.2.3