Skip to content

Commit ee52d93

Browse files
committed
Add force snap toggle
1 parent 47a3ca1 commit ee52d93

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

module.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Advanced Drawing Tools",
44
"description": "Improved drawing tools with different line, fill, and text styles.",
55
"author": "dev7355608",
6-
"version": "1.0.2",
6+
"version": "1.1.0",
77
"minimumCoreVersion": "9.255",
88
"compatibleCoreVersion": "9",
99
"esmodules": [
@@ -16,7 +16,7 @@
1616
],
1717
"url": "https://github.com/dev7355608/advanced-drawing-tools",
1818
"manifest": "https://raw.githubusercontent.com/dev7355608/advanced-drawing-tools/main/module.json",
19-
"download": "https://github.com/dev7355608/advanced-drawing-tools/archive/v1.0.2.zip",
19+
"download": "https://github.com/dev7355608/advanced-drawing-tools/archive/v1.1.0.zip",
2020
"bugs": "https://github.com/dev7355608/advanced-drawing-tools/issues",
2121
"readme": "https://raw.githubusercontent.com/dev7355608/advanced-drawing-tools/main/README.md"
2222
}

scripts/controls.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { MODULE_ID } from "./const.js";
2+
3+
Hooks.on("getSceneControlButtons", controls => {
4+
const drawingsControl = controls.find(c => c.name === "drawings");
5+
6+
drawingsControl?.tools.splice(drawingsControl.tools.findIndex(t => t.name === "clear"), 0, {
7+
name: `${MODULE_ID}.snap`,
8+
title: "CONTROLS.WallSnap",
9+
icon: "fas fa-plus",
10+
toggle: true,
11+
active: canvas.drawings?._forceSnap || false,
12+
onClick: toggled => canvas.drawings._forceSnap = toggled
13+
});
14+
});

scripts/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DashLineShader } from "./dash-line-shader.js";
33
import { calculateValue, cleanData } from "./utils.js";
44

55
import "./config.js";
6+
import "./controls.js";
67
import "./hud.js";
78

89
Hooks.once("init", () => {
@@ -537,6 +538,18 @@ Hooks.once("init", () => {
537538
}
538539
}, "OVERRIDE");
539540

541+
libWrapper.register(MODULE_ID, "DrawingsLayer.prototype.gridPrecision", function () {
542+
// Force snapping to grid vertices
543+
if (this._forceSnap) return canvas.grid.type <= CONST.GRID_TYPES.SQUARE ? 2 : 5;
544+
545+
// Normal snapping precision
546+
let size = canvas.dimensions.size;
547+
if (size >= 128) return 16;
548+
else if (size >= 64) return 8;
549+
else if (size >= 32) return 4;
550+
return 1;
551+
}, "OVERRIDE");
552+
540553
libWrapper.register(MODULE_ID, "DrawingsLayer.prototype._getNewDrawingData", function (wrapped, ...args) {
541554
const data = wrapped(...args);
542555

0 commit comments

Comments
 (0)