intelligent-system-design-language 0.3.21 → 0.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/langium-language-designer.md +38 -38
- package/.claude/agents/typescript-vscode-expert.md +29 -29
- package/.claude/agents/ui-ux-designer.md +36 -36
- package/.claude/settings.local.json +33 -33
- package/.idea/inspectionProfiles/Project_Default.xml +6 -6
- package/.idea/isdl.iml +13 -13
- package/.idea/modules.xml +8 -8
- package/.idea/vcs.xml +6 -6
- package/.idea/watcherTasks.xml +3 -3
- package/.vscodeignore +18 -18
- package/LICENSE +673 -673
- package/README.md +86 -86
- package/bin/cli.js +4 -4
- package/bin/lsp.js +8 -8
- package/out/_backgrounds.scss +91 -91
- package/out/_handlebars.scss +497 -497
- package/out/_isdlStyles.scss +1444 -1381
- package/out/_vuetifyOverrides.scss +425 -425
- package/out/_vuetifyStyles.scss +31957 -31957
- package/out/cli/components/_backgrounds.scss +91 -91
- package/out/cli/components/_handlebars.scss +497 -497
- package/out/cli/components/_isdlStyles.scss +1444 -1381
- package/out/cli/components/_vuetifyOverrides.scss +425 -425
- package/out/cli/components/_vuetifyStyles.scss +31957 -31957
- package/out/cli/components/active-effect-sheet-generator.js +453 -453
- package/out/cli/components/chat-card-generator.js +654 -651
- package/out/cli/components/chat-card-generator.js.map +1 -1
- package/out/cli/components/css-generator.js +4 -4
- package/out/cli/components/damage-roll-generator.js +160 -160
- package/out/cli/components/datamodel-generator.js +264 -257
- package/out/cli/components/datamodel-generator.js.map +1 -1
- package/out/cli/components/derived-data-generator.js +923 -923
- package/out/cli/components/hotbar-drop-hook-generator.js +82 -82
- package/out/cli/components/init-hook-generator.js +495 -495
- package/out/cli/components/language-generator.js +1 -1
- package/out/cli/components/language-generator.js.map +1 -1
- package/out/cli/components/measured-template-preview.js +221 -221
- package/out/cli/components/method-generator.js +979 -887
- package/out/cli/components/method-generator.js.map +1 -1
- package/out/cli/components/ready-hook-generator.js +404 -404
- package/out/cli/components/token-generator.js +116 -116
- package/out/cli/components/vue/base-components/vue-attribute.js +138 -138
- package/out/cli/components/vue/base-components/vue-boolean.js +64 -64
- package/out/cli/components/vue/base-components/vue-calculator.js +93 -93
- package/out/cli/components/vue/base-components/vue-damage-application.js +356 -356
- package/out/cli/components/vue/base-components/vue-damage-bonuses.js +165 -165
- package/out/cli/components/vue/base-components/vue-damage-resistances.js +196 -196
- package/out/cli/components/vue/base-components/vue-damage-track.js +121 -121
- package/out/cli/components/vue/base-components/vue-date-time.js +42 -42
- package/out/cli/components/vue/base-components/vue-dice.js +98 -98
- package/out/cli/components/vue/base-components/vue-die.js +73 -73
- package/out/cli/components/vue/base-components/vue-document-choice.js +149 -149
- package/out/cli/components/vue/base-components/vue-document-choices.js +179 -179
- package/out/cli/components/vue/base-components/vue-document-link.js +60 -60
- package/out/cli/components/vue/base-components/vue-extended-choice.js +88 -88
- package/out/cli/components/vue/base-components/vue-inventory.js +519 -519
- package/out/cli/components/vue/base-components/vue-macro-choice.js +138 -138
- package/out/cli/components/vue/base-components/vue-measured-template.js +530 -530
- package/out/cli/components/vue/base-components/vue-money.js +483 -483
- package/out/cli/components/vue/base-components/vue-number.js +174 -174
- package/out/cli/components/vue/base-components/vue-paperdoll.js +43 -43
- package/out/cli/components/vue/base-components/vue-parent-property-reference.js +76 -76
- package/out/cli/components/vue/base-components/vue-prosemirror.js +18 -18
- package/out/cli/components/vue/base-components/vue-resource.js +136 -136
- package/out/cli/components/vue/base-components/vue-roll-visualizer.js +286 -109
- package/out/cli/components/vue/base-components/vue-roll-visualizer.js.map +1 -1
- package/out/cli/components/vue/base-components/vue-self-property-reference.js +62 -62
- package/out/cli/components/vue/base-components/vue-string-choice.js +98 -98
- package/out/cli/components/vue/base-components/vue-string-choices.js +203 -203
- package/out/cli/components/vue/base-components/vue-string.js +60 -60
- package/out/cli/components/vue/base-components/vue-text-field.js +53 -53
- package/out/cli/components/vue/base-components/vue-tracker.js +431 -431
- package/out/cli/components/vue/vue-action-component-generator.js +64 -64
- package/out/cli/components/vue/vue-active-effect-sheet-generator.js +856 -856
- package/out/cli/components/vue/vue-datatable-sheet-class-generator.js +292 -292
- package/out/cli/components/vue/vue-datatable2-component-generator.js +824 -824
- package/out/cli/components/vue/vue-document-creation-app.js +121 -121
- package/out/cli/components/vue/vue-document-creation-sheet.js +94 -94
- package/out/cli/components/vue/vue-generator.js +40 -40
- package/out/cli/components/vue/vue-mixin.js +296 -296
- package/out/cli/components/vue/vue-pinned-datatable-component-generator.js +260 -260
- package/out/cli/components/vue/vue-prompt-generator.js +91 -76
- package/out/cli/components/vue/vue-prompt-generator.js.map +1 -1
- package/out/cli/components/vue/vue-prompt-sheet-class-generator.js +317 -317
- package/out/cli/components/vue/vue-sheet-application-generator.js +1177 -1167
- package/out/cli/components/vue/vue-sheet-application-generator.js.map +1 -1
- package/out/cli/components/vue/vue-sheet-class-generator.js +510 -510
- package/out/cli/generator.js +438 -433
- package/out/cli/generator.js.map +1 -1
- package/out/extension/github/githubAuthProvider.js +71 -29
- package/out/extension/github/githubAuthProvider.js.map +1 -1
- package/out/extension/github/githubGistManager.js +4 -3
- package/out/extension/github/githubGistManager.js.map +1 -1
- package/out/extension/github/githubManager.js +40 -38
- package/out/extension/github/githubManager.js.map +1 -1
- package/out/extension/github/githubQuickActions.js +120 -120
- package/out/extension/github/system-workflow.yml +47 -47
- package/out/extension/main.cjs +909 -532
- package/out/extension/main.cjs.map +3 -3
- package/out/extension/package.json +419 -419
- package/out/language/generated/ast.js +51 -2
- package/out/language/generated/ast.js.map +1 -1
- package/out/language/generated/grammar.js +14240 -13991
- package/out/language/generated/grammar.js.map +1 -1
- package/out/language/intelligent-system-design-language-validator.js +32 -2
- package/out/language/intelligent-system-design-language-validator.js.map +1 -1
- package/out/language/isdl-scope-provider.js +14 -1
- package/out/language/isdl-scope-provider.js.map +1 -1
- package/out/language/main.cjs +913 -569
- package/out/language/main.cjs.map +3 -3
- package/out/package.json +419 -419
- package/out/progressbar.min.js +6 -6
- package/out/styles.scss +762 -747
- package/out/test/validating/diagnostics.test.js +40 -0
- package/out/test/validating/diagnostics.test.js.map +1 -1
- package/package.json +419 -419
|
@@ -7,536 +7,536 @@ export default function generateMeasuredTemplateComponent(destination) {
|
|
|
7
7
|
if (!fs.existsSync(generatedFileDir)) {
|
|
8
8
|
fs.mkdirSync(generatedFileDir, { recursive: true });
|
|
9
9
|
}
|
|
10
|
-
const fileNode = expandToNode `
|
|
11
|
-
<script setup>
|
|
12
|
-
import { ref, computed, inject, watchEffect, onMounted, onUnmounted, nextTick, watch } from "vue";
|
|
13
|
-
|
|
14
|
-
const props = defineProps({
|
|
15
|
-
label: String,
|
|
16
|
-
systemPath: String,
|
|
17
|
-
context: Object,
|
|
18
|
-
visibility: String,
|
|
19
|
-
editMode: Boolean,
|
|
20
|
-
primaryColor: String,
|
|
21
|
-
secondaryColor: String,
|
|
22
|
-
tertiaryColor: String,
|
|
23
|
-
icon: String,
|
|
24
|
-
disabled: Boolean
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const document = inject("rawDocument");
|
|
28
|
-
|
|
29
|
-
// Vuetify's up/down stepper buttons update the model without firing a
|
|
30
|
-
// native change event, so Foundry's submitOnChange form handler never
|
|
31
|
-
// persists them. When the value changes while focus is NOT on a text
|
|
32
|
-
// input (i.e. a stepper click, not typing), persist directly. Typing
|
|
33
|
-
// still persists via the input's native change on blur/enter.
|
|
34
|
-
// ('document' is the injected Foundry document; DOM access uses window.)
|
|
35
|
-
const persistOnStep = (path, newValue) => {
|
|
36
|
-
if (document && window.document.activeElement?.tagName !== 'INPUT') {
|
|
37
|
-
document.update({ [path]: newValue });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const expanded = ref(false);
|
|
42
|
-
const canvasRef = ref(null);
|
|
43
|
-
let pixiApp = null;
|
|
44
|
-
let templateGraphics = null;
|
|
45
|
-
|
|
46
|
-
const expandIcon = computed(() => {
|
|
47
|
-
return expanded.value ? "fa-solid fa-caret-up" : "fa-solid fa-caret-down";
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const type = computed({
|
|
51
|
-
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".type") || "circle",
|
|
52
|
-
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".type", newValue)
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const direction = computed({
|
|
56
|
-
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".direction") || 0,
|
|
57
|
-
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".direction", newValue)
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const angle = computed({
|
|
61
|
-
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".angle") || 60,
|
|
62
|
-
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".angle", newValue)
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const distance = computed({
|
|
66
|
-
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".distance") || 30,
|
|
67
|
-
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".distance", newValue)
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const width = computed({
|
|
71
|
-
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".width") || 5,
|
|
72
|
-
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".width", newValue)
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const summary = computed(() => {
|
|
76
|
-
let sum = \`\${direction.value}° \${type.value} (\${distance.value} squares)\`;
|
|
77
|
-
if (type.value === 'cone') sum += \` \${angle.value}° angle\`;
|
|
78
|
-
if (type.value === 'ray') sum += \` \${width.value} squares wide\`;
|
|
79
|
-
return sum;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const getLabel = computed(() => {
|
|
83
|
-
const localized = game.i18n.localize(props.label);
|
|
84
|
-
if (props.icon) {
|
|
85
|
-
return \`<i class="fa-solid \${props.icon}"></i> \${localized}\`;
|
|
86
|
-
}
|
|
87
|
-
return localized;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// PIXI Drawing Functions
|
|
92
|
-
const initializePixi = async () => {
|
|
93
|
-
if (!canvasRef.value || pixiApp) return;
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const { width, height } = getCanvasSize();
|
|
97
|
-
|
|
98
|
-
pixiApp = new PIXI.Application({
|
|
99
|
-
view: canvasRef.value,
|
|
100
|
-
width,
|
|
101
|
-
height,
|
|
102
|
-
backgroundColor: 0xf8f9fa,
|
|
103
|
-
antialias: true,
|
|
104
|
-
resolution: window.devicePixelRatio || 1,
|
|
105
|
-
autoDensity: true
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Draw grid background
|
|
109
|
-
drawGrid();
|
|
110
|
-
|
|
111
|
-
// Create template graphics container
|
|
112
|
-
templateGraphics = new PIXI.Graphics();
|
|
113
|
-
pixiApp.stage.addChild(templateGraphics);
|
|
114
|
-
|
|
115
|
-
// Initial draw
|
|
116
|
-
drawTemplate();
|
|
117
|
-
} catch (error) {
|
|
118
|
-
console.warn("PIXI initialization failed:", error);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const getCanvasSize = () => {
|
|
123
|
-
const bufferSquares = 2;
|
|
124
|
-
const canvasSize = 150; // Always 150px x 150px
|
|
125
|
-
|
|
126
|
-
// Calculate required grid squares to display
|
|
127
|
-
let maxDimension = distance.value;
|
|
128
|
-
|
|
129
|
-
if (type.value === 'cone') {
|
|
130
|
-
// For cones, consider the width at the end
|
|
131
|
-
const endWidth = Math.tan((angle.value / 2) * Math.PI / 180) * distance.value * 2;
|
|
132
|
-
maxDimension = Math.max(distance.value, endWidth);
|
|
133
|
-
} else if (type.value === 'ray') {
|
|
134
|
-
maxDimension = Math.max(distance.value, width.value);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Total grid squares needed (template + buffer on all sides)
|
|
138
|
-
const totalGridSquares = (maxDimension * 2) + (bufferSquares * 2);
|
|
139
|
-
const gridSize = canvasSize / totalGridSquares;
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
width: canvasSize,
|
|
143
|
-
height: canvasSize,
|
|
144
|
-
gridSize: gridSize,
|
|
145
|
-
totalGridSquares: totalGridSquares
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const resizeCanvas = () => {
|
|
150
|
-
if (!pixiApp) return;
|
|
151
|
-
|
|
152
|
-
const { width, height } = getCanvasSize();
|
|
153
|
-
pixiApp.renderer.resize(width, height);
|
|
154
|
-
|
|
155
|
-
// Clear and redraw everything
|
|
156
|
-
pixiApp.stage.removeChildren();
|
|
157
|
-
drawGrid();
|
|
158
|
-
templateGraphics = new PIXI.Graphics();
|
|
159
|
-
pixiApp.stage.addChild(templateGraphics);
|
|
160
|
-
drawTemplate();
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const drawGrid = () => {
|
|
164
|
-
if (!pixiApp) return;
|
|
165
|
-
|
|
166
|
-
const gridGraphics = new PIXI.Graphics();
|
|
167
|
-
const { gridSize } = getCanvasSize();
|
|
168
|
-
const width = pixiApp.screen.width;
|
|
169
|
-
const height = pixiApp.screen.height;
|
|
170
|
-
|
|
171
|
-
// Always offset grid by half a square so canvas center aligns with grid square center
|
|
172
|
-
const offset = gridSize / 2;
|
|
173
|
-
|
|
174
|
-
console.log("Drawing grid with offset:", offset, "gridSize:", gridSize, "distance:", distance.value);
|
|
175
|
-
|
|
176
|
-
gridGraphics.lineStyle(1, 0xe0e0e0, 0.8);
|
|
177
|
-
|
|
178
|
-
// Vertical lines
|
|
179
|
-
for (let x = offset; x <= width; x += gridSize) {
|
|
180
|
-
gridGraphics.moveTo(x, 0);
|
|
181
|
-
gridGraphics.lineTo(x, height);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Horizontal lines
|
|
185
|
-
for (let y = offset; y <= height; y += gridSize) {
|
|
186
|
-
gridGraphics.moveTo(0, y);
|
|
187
|
-
gridGraphics.lineTo(width, y);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
pixiApp.stage.addChild(gridGraphics);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const drawTemplate = () => {
|
|
194
|
-
if (!templateGraphics || !pixiApp) return;
|
|
195
|
-
|
|
196
|
-
templateGraphics.clear();
|
|
197
|
-
|
|
198
|
-
const { gridSize } = getCanvasSize();
|
|
199
|
-
const directionRad = toRadians(direction.value);
|
|
200
|
-
|
|
201
|
-
// Always center in grid square (canvas center)
|
|
202
|
-
const centerX = pixiApp.screen.width / 2;
|
|
203
|
-
const centerY = pixiApp.screen.height / 2;
|
|
204
|
-
|
|
205
|
-
// Convert grid units to pixels for Foundry shape functions
|
|
206
|
-
const distancePixels = distance.value * gridSize;
|
|
207
|
-
const widthPixels = width.value * gridSize;
|
|
208
|
-
|
|
209
|
-
// Set template style
|
|
210
|
-
templateGraphics.lineStyle(3, 0xff6b6b, 1);
|
|
211
|
-
templateGraphics.beginFill(0xff6b6b, 0.25);
|
|
212
|
-
|
|
213
|
-
switch (type.value) {
|
|
214
|
-
case 'circle':
|
|
215
|
-
templateGraphics.drawCircle(centerX, centerY, distancePixels);
|
|
216
|
-
break;
|
|
217
|
-
case 'rectangle':
|
|
218
|
-
templateGraphics.drawRect(
|
|
219
|
-
centerX - distancePixels/2,
|
|
220
|
-
centerY - distancePixels/2,
|
|
221
|
-
distancePixels,
|
|
222
|
-
distancePixels
|
|
223
|
-
);
|
|
224
|
-
break;
|
|
225
|
-
case 'cone':
|
|
226
|
-
const coneShape = getConeShape(directionRad, angle.value, distancePixels);
|
|
227
|
-
const conePoints = [];
|
|
228
|
-
for (let i = 0; i < coneShape.points.length; i += 2) {
|
|
229
|
-
conePoints.push(centerX + coneShape.points[i]);
|
|
230
|
-
conePoints.push(centerY + coneShape.points[i + 1]);
|
|
231
|
-
}
|
|
232
|
-
templateGraphics.drawPolygon(conePoints);
|
|
233
|
-
break;
|
|
234
|
-
case 'ray':
|
|
235
|
-
const rayShape = getRayShape(directionRad, distancePixels, widthPixels);
|
|
236
|
-
const rayPoints = [];
|
|
237
|
-
for (let i = 0; i < rayShape.points.length; i += 2) {
|
|
238
|
-
rayPoints.push(centerX + rayShape.points[i]);
|
|
239
|
-
rayPoints.push(centerY + rayShape.points[i + 1]);
|
|
240
|
-
}
|
|
241
|
-
templateGraphics.drawPolygon(rayPoints);
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
templateGraphics.endFill();
|
|
246
|
-
|
|
247
|
-
// Draw origin point
|
|
248
|
-
templateGraphics.lineStyle(0);
|
|
249
|
-
templateGraphics.beginFill(0x333333, 1);
|
|
250
|
-
templateGraphics.drawCircle(centerX, centerY, Math.max(2, gridSize * 0.15));
|
|
251
|
-
templateGraphics.endFill();
|
|
252
|
-
|
|
253
|
-
// Draw direction indicator
|
|
254
|
-
templateGraphics.lineStyle(2, 0x333333, 1);
|
|
255
|
-
templateGraphics.moveTo(centerX, centerY);
|
|
256
|
-
templateGraphics.lineTo(
|
|
257
|
-
centerX + Math.cos(directionRad) * (gridSize * 0.8),
|
|
258
|
-
centerY + Math.sin(directionRad) * (gridSize * 0.8)
|
|
259
|
-
);
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// Helper function to simulate Ray.fromAngle
|
|
263
|
-
const createRay = (x, y, angle, distance) => {
|
|
264
|
-
return {
|
|
265
|
-
A: { x, y },
|
|
266
|
-
B: {
|
|
267
|
-
x: x + Math.cos(angle) * distance,
|
|
268
|
-
y: y + Math.sin(angle) * distance
|
|
269
|
-
},
|
|
270
|
-
dx: Math.cos(angle) * distance,
|
|
271
|
-
dy: Math.sin(angle) * distance
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// Helper function to convert degrees to radians
|
|
276
|
-
const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Get a Conical area of effect given a direction, angle, and distance
|
|
280
|
-
* @param {number} direction
|
|
281
|
-
* @param {number} angle
|
|
282
|
-
* @param {number} distance
|
|
283
|
-
* @returns {PIXI.Polygon}
|
|
284
|
-
*/
|
|
285
|
-
const getConeShape = (direction, angle, distance) => {
|
|
286
|
-
angle = angle || 90;
|
|
287
|
-
const coneType = game.settings.get("core", "coneTemplateType"); // Default to round cones
|
|
288
|
-
|
|
289
|
-
// For round cones - approximate the shape with a ray every 3 degrees
|
|
290
|
-
let angles;
|
|
291
|
-
if (coneType === "round") {
|
|
292
|
-
const da = Math.min(angle, 3);
|
|
293
|
-
const numRays = Math.floor(angle / da);
|
|
294
|
-
angles = Array.from({length: numRays + 1}, (_, i) => (angle / -2) + (i * da));
|
|
295
|
-
if (angles[angles.length - 1] !== angle / 2) {
|
|
296
|
-
angles.push(angle / 2);
|
|
297
|
-
}
|
|
298
|
-
} else {
|
|
299
|
-
// For flat cones, direct point-to-point
|
|
300
|
-
angles = [(angle / -2), (angle / 2)];
|
|
301
|
-
distance /= Math.cos(toRadians(angle / 2));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Get the cone shape as a polygon
|
|
305
|
-
const rays = angles.map(a => createRay(0, 0, direction + toRadians(a), distance + 1));
|
|
306
|
-
const points = rays.reduce((arr, r) => {
|
|
307
|
-
return arr.concat([r.B.x, r.B.y]);
|
|
308
|
-
}, [0, 0]).concat([0, 0]);
|
|
309
|
-
return new PIXI.Polygon(points);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Get a rotated Rectangular area of effect given a width, height, and direction
|
|
314
|
-
* @param {number} direction
|
|
315
|
-
* @param {number} distance
|
|
316
|
-
* @param {number} width
|
|
317
|
-
* @returns {PIXI.Polygon}
|
|
318
|
-
*/
|
|
319
|
-
const getRayShape = (direction, distance, width) => {
|
|
320
|
-
const up = createRay(0, 0, direction - Math.PI/2, (width / 2) + 1);
|
|
321
|
-
const down = createRay(0, 0, direction + Math.PI/2, (width / 2) + 1);
|
|
322
|
-
const l1 = createRay(up.B.x, up.B.y, direction, distance + 1);
|
|
323
|
-
const l2 = createRay(down.B.x, down.B.y, direction, distance + 1);
|
|
324
|
-
|
|
325
|
-
// Create Polygon shape
|
|
326
|
-
const points = [down.B.x, down.B.y, up.B.x, up.B.y, l1.B.x, l1.B.y, l2.B.x, l2.B.y];
|
|
327
|
-
return new PIXI.Polygon(points);
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const destroyPixi = () => {
|
|
331
|
-
if (pixiApp) {
|
|
332
|
-
pixiApp.destroy(true, true);
|
|
333
|
-
pixiApp = null;
|
|
334
|
-
templateGraphics = null;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
// Watch for changes and redraw/resize
|
|
339
|
-
watchEffect(() => {
|
|
340
|
-
if (expanded.value && pixiApp) {
|
|
341
|
-
// Use nextTick to ensure all reactive values are updated
|
|
342
|
-
nextTick(() => {
|
|
343
|
-
resizeCanvas();
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
// Separate watcher for individual property changes
|
|
349
|
-
watchEffect(() => {
|
|
350
|
-
// Watch these specific values to trigger updates
|
|
351
|
-
const currentType = type.value;
|
|
352
|
-
const currentDirection = direction.value;
|
|
353
|
-
const currentDistance = distance.value;
|
|
354
|
-
const currentAngle = angle.value;
|
|
355
|
-
const currentWidth = width.value;
|
|
356
|
-
|
|
357
|
-
if (expanded.value && pixiApp && templateGraphics) {
|
|
358
|
-
nextTick(() => {
|
|
359
|
-
drawTemplate();
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
watch(distance, () => {
|
|
365
|
-
if (expanded.value && pixiApp) {
|
|
366
|
-
nextTick(() => {
|
|
367
|
-
resizeCanvas();
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
// Watch for expansion changes
|
|
373
|
-
watchEffect(async () => {
|
|
374
|
-
if (expanded.value) {
|
|
375
|
-
await nextTick();
|
|
376
|
-
await nextTick(); // Double nextTick to ensure DOM and reactive values are ready
|
|
377
|
-
initializePixi();
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
onMounted(() => {
|
|
382
|
-
if (expanded.value) {
|
|
383
|
-
initializePixi();
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
onUnmounted(() => {
|
|
388
|
-
destroyPixi();
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
const onPlace = () => {
|
|
392
|
-
console.log("Placing template at current cursor position");
|
|
393
|
-
game.system.measuredTemplatePreviewClass.place({
|
|
394
|
-
type: type.value,
|
|
395
|
-
distance: distance.value,
|
|
396
|
-
direction: direction.value,
|
|
397
|
-
angle: angle.value,
|
|
398
|
-
width: width.value
|
|
399
|
-
}, document.sheet);
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
</script>
|
|
403
|
-
|
|
404
|
-
<template>
|
|
405
|
-
<v-input class="isdl-tracker isdl-measured-template">
|
|
406
|
-
<template #default>
|
|
407
|
-
<v-field
|
|
408
|
-
class="v-field--active"
|
|
409
|
-
density="compact"
|
|
410
|
-
variant="outlined"
|
|
411
|
-
>
|
|
412
|
-
<template #label>
|
|
413
|
-
<span v-html="getLabel" />
|
|
414
|
-
</template>
|
|
415
|
-
<template #append-inner>
|
|
416
|
-
<v-icon
|
|
417
|
-
icon="fa-solid fa-border-outer"
|
|
418
|
-
class="map-icon"
|
|
419
|
-
@click.stop="onPlace"
|
|
420
|
-
data-tooltip="Place"
|
|
421
|
-
:color="primaryColor" />
|
|
422
|
-
<v-icon
|
|
423
|
-
:icon="expandIcon"
|
|
424
|
-
@click.stop="expanded = !expanded"
|
|
425
|
-
class="v-select__menu-icon"
|
|
426
|
-
/>
|
|
427
|
-
</template>
|
|
428
|
-
<div class="tracker-content flexcol">
|
|
429
|
-
<div class="d-flex tracker-inner-content">
|
|
430
|
-
<span v-html="summary" />
|
|
431
|
-
</div>
|
|
432
|
-
<v-expand-transition>
|
|
433
|
-
<div v-show="expanded" class="template-expanded-content" style="margin-top: 1rem;">
|
|
434
|
-
<div class="template-controls">
|
|
435
|
-
<div class="d-flex flex-row">
|
|
436
|
-
<v-select
|
|
437
|
-
:model-value="type"
|
|
438
|
-
@update:model-value="(v) => { type = v; if (document) document.update({ [systemPath + '.type']: v }); }"
|
|
439
|
-
:name="systemPath + '.type'"
|
|
440
|
-
:items="[
|
|
441
|
-
{ title: 'Circle', value: 'circle' },
|
|
442
|
-
{ title: 'Cone', value: 'cone' },
|
|
443
|
-
{ title: 'Rectangle', value: 'rectangle' },
|
|
444
|
-
{ title: 'Ray', value: 'ray' }
|
|
445
|
-
]"
|
|
446
|
-
label="Type"
|
|
447
|
-
density="compact"
|
|
448
|
-
variant="outlined"
|
|
449
|
-
class="control-field slim-number"
|
|
450
|
-
:hide-details="true"
|
|
451
|
-
:tile="true"
|
|
452
|
-
:disabled="disabled"
|
|
453
|
-
/>
|
|
454
|
-
<v-number-input
|
|
455
|
-
:model-value="direction"
|
|
456
|
-
@update:model-value="(v) => { direction = v; persistOnStep(systemPath + '.direction', v); }"
|
|
457
|
-
:name="systemPath + '.direction'"
|
|
458
|
-
label="Direction (°)"
|
|
459
|
-
controlVariant="stacked"
|
|
460
|
-
density="compact"
|
|
461
|
-
variant="outlined"
|
|
462
|
-
class="control-field slim-number"
|
|
463
|
-
:hide-details="true"
|
|
464
|
-
:tile="true"
|
|
465
|
-
:min="0"
|
|
466
|
-
:max="360"
|
|
467
|
-
:step="0.5"
|
|
468
|
-
:precision="1"
|
|
469
|
-
:disabled="disabled"
|
|
470
|
-
/>
|
|
471
|
-
</div>
|
|
472
|
-
<div class="d-flex flex-row" style="margin-top: 1rem;">
|
|
473
|
-
<v-number-input
|
|
474
|
-
:model-value="distance"
|
|
475
|
-
@update:model-value="(v) => { distance = v; persistOnStep(systemPath + '.distance', v); }"
|
|
476
|
-
:name="systemPath + '.distance'"
|
|
477
|
-
label="Distance (grid units)"
|
|
478
|
-
controlVariant="stacked"
|
|
479
|
-
density="compact"
|
|
480
|
-
variant="outlined"
|
|
481
|
-
class="control-field"
|
|
482
|
-
:hide-details="true"
|
|
483
|
-
:tile="true"
|
|
484
|
-
:min="0"
|
|
485
|
-
:precision="1"
|
|
486
|
-
:step="0.5"
|
|
487
|
-
:disabled="disabled"
|
|
488
|
-
/>
|
|
489
|
-
<v-number-input
|
|
490
|
-
v-if="type === 'cone'"
|
|
491
|
-
:model-value="angle"
|
|
492
|
-
@update:model-value="(v) => { angle = v; persistOnStep(systemPath + '.angle', v); }"
|
|
493
|
-
:name="systemPath + '.angle'"
|
|
494
|
-
label="Angle (°)"
|
|
495
|
-
controlVariant="stacked"
|
|
496
|
-
density="compact"
|
|
497
|
-
variant="outlined"
|
|
498
|
-
class="control-field slim-number"
|
|
499
|
-
:hide-details="true"
|
|
500
|
-
:tile="true"
|
|
501
|
-
:min="0"
|
|
502
|
-
:max="360"
|
|
503
|
-
:step="0.5"
|
|
504
|
-
:precision="1"
|
|
505
|
-
:disabled="disabled"
|
|
506
|
-
/>
|
|
507
|
-
<v-number-input
|
|
508
|
-
v-if="type === 'ray'"
|
|
509
|
-
:model-value="width"
|
|
510
|
-
@update:model-value="(v) => { width = v; persistOnStep(systemPath + '.width', v); }"
|
|
511
|
-
:name="systemPath + '.width'"
|
|
512
|
-
label="Width (grid units)"
|
|
513
|
-
controlVariant="stacked"
|
|
514
|
-
density="compact"
|
|
515
|
-
variant="outlined"
|
|
516
|
-
class="control-field slim-number"
|
|
517
|
-
:hide-details="true"
|
|
518
|
-
:tile="true"
|
|
519
|
-
:min="0"
|
|
520
|
-
:step="0.5"
|
|
521
|
-
:precision="1"
|
|
522
|
-
:disabled="disabled"
|
|
523
|
-
/>
|
|
524
|
-
</div>
|
|
525
|
-
</div>
|
|
526
|
-
<div class="template-preview" style="display: flex; margin-top: 0.5rem;">
|
|
527
|
-
<canvas
|
|
528
|
-
ref="canvasRef"
|
|
529
|
-
class="template-canvas"
|
|
530
|
-
style="margin-left: auto; margin-right: auto;"
|
|
531
|
-
></canvas>
|
|
532
|
-
</div>
|
|
533
|
-
</div>
|
|
534
|
-
</v-expand-transition>
|
|
535
|
-
</div>
|
|
536
|
-
</v-field>
|
|
537
|
-
</template>
|
|
538
|
-
</v-input>
|
|
539
|
-
</template>
|
|
10
|
+
const fileNode = expandToNode `
|
|
11
|
+
<script setup>
|
|
12
|
+
import { ref, computed, inject, watchEffect, onMounted, onUnmounted, nextTick, watch } from "vue";
|
|
13
|
+
|
|
14
|
+
const props = defineProps({
|
|
15
|
+
label: String,
|
|
16
|
+
systemPath: String,
|
|
17
|
+
context: Object,
|
|
18
|
+
visibility: String,
|
|
19
|
+
editMode: Boolean,
|
|
20
|
+
primaryColor: String,
|
|
21
|
+
secondaryColor: String,
|
|
22
|
+
tertiaryColor: String,
|
|
23
|
+
icon: String,
|
|
24
|
+
disabled: Boolean
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const document = inject("rawDocument");
|
|
28
|
+
|
|
29
|
+
// Vuetify's up/down stepper buttons update the model without firing a
|
|
30
|
+
// native change event, so Foundry's submitOnChange form handler never
|
|
31
|
+
// persists them. When the value changes while focus is NOT on a text
|
|
32
|
+
// input (i.e. a stepper click, not typing), persist directly. Typing
|
|
33
|
+
// still persists via the input's native change on blur/enter.
|
|
34
|
+
// ('document' is the injected Foundry document; DOM access uses window.)
|
|
35
|
+
const persistOnStep = (path, newValue) => {
|
|
36
|
+
if (document && window.document.activeElement?.tagName !== 'INPUT') {
|
|
37
|
+
document.update({ [path]: newValue });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const expanded = ref(false);
|
|
42
|
+
const canvasRef = ref(null);
|
|
43
|
+
let pixiApp = null;
|
|
44
|
+
let templateGraphics = null;
|
|
45
|
+
|
|
46
|
+
const expandIcon = computed(() => {
|
|
47
|
+
return expanded.value ? "fa-solid fa-caret-up" : "fa-solid fa-caret-down";
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const type = computed({
|
|
51
|
+
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".type") || "circle",
|
|
52
|
+
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".type", newValue)
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const direction = computed({
|
|
56
|
+
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".direction") || 0,
|
|
57
|
+
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".direction", newValue)
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const angle = computed({
|
|
61
|
+
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".angle") || 60,
|
|
62
|
+
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".angle", newValue)
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const distance = computed({
|
|
66
|
+
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".distance") || 30,
|
|
67
|
+
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".distance", newValue)
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const width = computed({
|
|
71
|
+
get: () => foundry.utils.getProperty(props.context, props.systemPath + ".width") || 5,
|
|
72
|
+
set: (newValue) => foundry.utils.setProperty(props.context, props.systemPath + ".width", newValue)
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const summary = computed(() => {
|
|
76
|
+
let sum = \`\${direction.value}° \${type.value} (\${distance.value} squares)\`;
|
|
77
|
+
if (type.value === 'cone') sum += \` \${angle.value}° angle\`;
|
|
78
|
+
if (type.value === 'ray') sum += \` \${width.value} squares wide\`;
|
|
79
|
+
return sum;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const getLabel = computed(() => {
|
|
83
|
+
const localized = game.i18n.localize(props.label);
|
|
84
|
+
if (props.icon) {
|
|
85
|
+
return \`<i class="fa-solid \${props.icon}"></i> \${localized}\`;
|
|
86
|
+
}
|
|
87
|
+
return localized;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
// PIXI Drawing Functions
|
|
92
|
+
const initializePixi = async () => {
|
|
93
|
+
if (!canvasRef.value || pixiApp) return;
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const { width, height } = getCanvasSize();
|
|
97
|
+
|
|
98
|
+
pixiApp = new PIXI.Application({
|
|
99
|
+
view: canvasRef.value,
|
|
100
|
+
width,
|
|
101
|
+
height,
|
|
102
|
+
backgroundColor: 0xf8f9fa,
|
|
103
|
+
antialias: true,
|
|
104
|
+
resolution: window.devicePixelRatio || 1,
|
|
105
|
+
autoDensity: true
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Draw grid background
|
|
109
|
+
drawGrid();
|
|
110
|
+
|
|
111
|
+
// Create template graphics container
|
|
112
|
+
templateGraphics = new PIXI.Graphics();
|
|
113
|
+
pixiApp.stage.addChild(templateGraphics);
|
|
114
|
+
|
|
115
|
+
// Initial draw
|
|
116
|
+
drawTemplate();
|
|
117
|
+
} catch (error) {
|
|
118
|
+
console.warn("PIXI initialization failed:", error);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const getCanvasSize = () => {
|
|
123
|
+
const bufferSquares = 2;
|
|
124
|
+
const canvasSize = 150; // Always 150px x 150px
|
|
125
|
+
|
|
126
|
+
// Calculate required grid squares to display
|
|
127
|
+
let maxDimension = distance.value;
|
|
128
|
+
|
|
129
|
+
if (type.value === 'cone') {
|
|
130
|
+
// For cones, consider the width at the end
|
|
131
|
+
const endWidth = Math.tan((angle.value / 2) * Math.PI / 180) * distance.value * 2;
|
|
132
|
+
maxDimension = Math.max(distance.value, endWidth);
|
|
133
|
+
} else if (type.value === 'ray') {
|
|
134
|
+
maxDimension = Math.max(distance.value, width.value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Total grid squares needed (template + buffer on all sides)
|
|
138
|
+
const totalGridSquares = (maxDimension * 2) + (bufferSquares * 2);
|
|
139
|
+
const gridSize = canvasSize / totalGridSquares;
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
width: canvasSize,
|
|
143
|
+
height: canvasSize,
|
|
144
|
+
gridSize: gridSize,
|
|
145
|
+
totalGridSquares: totalGridSquares
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const resizeCanvas = () => {
|
|
150
|
+
if (!pixiApp) return;
|
|
151
|
+
|
|
152
|
+
const { width, height } = getCanvasSize();
|
|
153
|
+
pixiApp.renderer.resize(width, height);
|
|
154
|
+
|
|
155
|
+
// Clear and redraw everything
|
|
156
|
+
pixiApp.stage.removeChildren();
|
|
157
|
+
drawGrid();
|
|
158
|
+
templateGraphics = new PIXI.Graphics();
|
|
159
|
+
pixiApp.stage.addChild(templateGraphics);
|
|
160
|
+
drawTemplate();
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const drawGrid = () => {
|
|
164
|
+
if (!pixiApp) return;
|
|
165
|
+
|
|
166
|
+
const gridGraphics = new PIXI.Graphics();
|
|
167
|
+
const { gridSize } = getCanvasSize();
|
|
168
|
+
const width = pixiApp.screen.width;
|
|
169
|
+
const height = pixiApp.screen.height;
|
|
170
|
+
|
|
171
|
+
// Always offset grid by half a square so canvas center aligns with grid square center
|
|
172
|
+
const offset = gridSize / 2;
|
|
173
|
+
|
|
174
|
+
console.log("Drawing grid with offset:", offset, "gridSize:", gridSize, "distance:", distance.value);
|
|
175
|
+
|
|
176
|
+
gridGraphics.lineStyle(1, 0xe0e0e0, 0.8);
|
|
177
|
+
|
|
178
|
+
// Vertical lines
|
|
179
|
+
for (let x = offset; x <= width; x += gridSize) {
|
|
180
|
+
gridGraphics.moveTo(x, 0);
|
|
181
|
+
gridGraphics.lineTo(x, height);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Horizontal lines
|
|
185
|
+
for (let y = offset; y <= height; y += gridSize) {
|
|
186
|
+
gridGraphics.moveTo(0, y);
|
|
187
|
+
gridGraphics.lineTo(width, y);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
pixiApp.stage.addChild(gridGraphics);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const drawTemplate = () => {
|
|
194
|
+
if (!templateGraphics || !pixiApp) return;
|
|
195
|
+
|
|
196
|
+
templateGraphics.clear();
|
|
197
|
+
|
|
198
|
+
const { gridSize } = getCanvasSize();
|
|
199
|
+
const directionRad = toRadians(direction.value);
|
|
200
|
+
|
|
201
|
+
// Always center in grid square (canvas center)
|
|
202
|
+
const centerX = pixiApp.screen.width / 2;
|
|
203
|
+
const centerY = pixiApp.screen.height / 2;
|
|
204
|
+
|
|
205
|
+
// Convert grid units to pixels for Foundry shape functions
|
|
206
|
+
const distancePixels = distance.value * gridSize;
|
|
207
|
+
const widthPixels = width.value * gridSize;
|
|
208
|
+
|
|
209
|
+
// Set template style
|
|
210
|
+
templateGraphics.lineStyle(3, 0xff6b6b, 1);
|
|
211
|
+
templateGraphics.beginFill(0xff6b6b, 0.25);
|
|
212
|
+
|
|
213
|
+
switch (type.value) {
|
|
214
|
+
case 'circle':
|
|
215
|
+
templateGraphics.drawCircle(centerX, centerY, distancePixels);
|
|
216
|
+
break;
|
|
217
|
+
case 'rectangle':
|
|
218
|
+
templateGraphics.drawRect(
|
|
219
|
+
centerX - distancePixels/2,
|
|
220
|
+
centerY - distancePixels/2,
|
|
221
|
+
distancePixels,
|
|
222
|
+
distancePixels
|
|
223
|
+
);
|
|
224
|
+
break;
|
|
225
|
+
case 'cone':
|
|
226
|
+
const coneShape = getConeShape(directionRad, angle.value, distancePixels);
|
|
227
|
+
const conePoints = [];
|
|
228
|
+
for (let i = 0; i < coneShape.points.length; i += 2) {
|
|
229
|
+
conePoints.push(centerX + coneShape.points[i]);
|
|
230
|
+
conePoints.push(centerY + coneShape.points[i + 1]);
|
|
231
|
+
}
|
|
232
|
+
templateGraphics.drawPolygon(conePoints);
|
|
233
|
+
break;
|
|
234
|
+
case 'ray':
|
|
235
|
+
const rayShape = getRayShape(directionRad, distancePixels, widthPixels);
|
|
236
|
+
const rayPoints = [];
|
|
237
|
+
for (let i = 0; i < rayShape.points.length; i += 2) {
|
|
238
|
+
rayPoints.push(centerX + rayShape.points[i]);
|
|
239
|
+
rayPoints.push(centerY + rayShape.points[i + 1]);
|
|
240
|
+
}
|
|
241
|
+
templateGraphics.drawPolygon(rayPoints);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
templateGraphics.endFill();
|
|
246
|
+
|
|
247
|
+
// Draw origin point
|
|
248
|
+
templateGraphics.lineStyle(0);
|
|
249
|
+
templateGraphics.beginFill(0x333333, 1);
|
|
250
|
+
templateGraphics.drawCircle(centerX, centerY, Math.max(2, gridSize * 0.15));
|
|
251
|
+
templateGraphics.endFill();
|
|
252
|
+
|
|
253
|
+
// Draw direction indicator
|
|
254
|
+
templateGraphics.lineStyle(2, 0x333333, 1);
|
|
255
|
+
templateGraphics.moveTo(centerX, centerY);
|
|
256
|
+
templateGraphics.lineTo(
|
|
257
|
+
centerX + Math.cos(directionRad) * (gridSize * 0.8),
|
|
258
|
+
centerY + Math.sin(directionRad) * (gridSize * 0.8)
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Helper function to simulate Ray.fromAngle
|
|
263
|
+
const createRay = (x, y, angle, distance) => {
|
|
264
|
+
return {
|
|
265
|
+
A: { x, y },
|
|
266
|
+
B: {
|
|
267
|
+
x: x + Math.cos(angle) * distance,
|
|
268
|
+
y: y + Math.sin(angle) * distance
|
|
269
|
+
},
|
|
270
|
+
dx: Math.cos(angle) * distance,
|
|
271
|
+
dy: Math.sin(angle) * distance
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// Helper function to convert degrees to radians
|
|
276
|
+
const toRadians = (degrees) => degrees * (Math.PI / 180);
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Get a Conical area of effect given a direction, angle, and distance
|
|
280
|
+
* @param {number} direction
|
|
281
|
+
* @param {number} angle
|
|
282
|
+
* @param {number} distance
|
|
283
|
+
* @returns {PIXI.Polygon}
|
|
284
|
+
*/
|
|
285
|
+
const getConeShape = (direction, angle, distance) => {
|
|
286
|
+
angle = angle || 90;
|
|
287
|
+
const coneType = game.settings.get("core", "coneTemplateType"); // Default to round cones
|
|
288
|
+
|
|
289
|
+
// For round cones - approximate the shape with a ray every 3 degrees
|
|
290
|
+
let angles;
|
|
291
|
+
if (coneType === "round") {
|
|
292
|
+
const da = Math.min(angle, 3);
|
|
293
|
+
const numRays = Math.floor(angle / da);
|
|
294
|
+
angles = Array.from({length: numRays + 1}, (_, i) => (angle / -2) + (i * da));
|
|
295
|
+
if (angles[angles.length - 1] !== angle / 2) {
|
|
296
|
+
angles.push(angle / 2);
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
// For flat cones, direct point-to-point
|
|
300
|
+
angles = [(angle / -2), (angle / 2)];
|
|
301
|
+
distance /= Math.cos(toRadians(angle / 2));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Get the cone shape as a polygon
|
|
305
|
+
const rays = angles.map(a => createRay(0, 0, direction + toRadians(a), distance + 1));
|
|
306
|
+
const points = rays.reduce((arr, r) => {
|
|
307
|
+
return arr.concat([r.B.x, r.B.y]);
|
|
308
|
+
}, [0, 0]).concat([0, 0]);
|
|
309
|
+
return new PIXI.Polygon(points);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Get a rotated Rectangular area of effect given a width, height, and direction
|
|
314
|
+
* @param {number} direction
|
|
315
|
+
* @param {number} distance
|
|
316
|
+
* @param {number} width
|
|
317
|
+
* @returns {PIXI.Polygon}
|
|
318
|
+
*/
|
|
319
|
+
const getRayShape = (direction, distance, width) => {
|
|
320
|
+
const up = createRay(0, 0, direction - Math.PI/2, (width / 2) + 1);
|
|
321
|
+
const down = createRay(0, 0, direction + Math.PI/2, (width / 2) + 1);
|
|
322
|
+
const l1 = createRay(up.B.x, up.B.y, direction, distance + 1);
|
|
323
|
+
const l2 = createRay(down.B.x, down.B.y, direction, distance + 1);
|
|
324
|
+
|
|
325
|
+
// Create Polygon shape
|
|
326
|
+
const points = [down.B.x, down.B.y, up.B.x, up.B.y, l1.B.x, l1.B.y, l2.B.x, l2.B.y];
|
|
327
|
+
return new PIXI.Polygon(points);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const destroyPixi = () => {
|
|
331
|
+
if (pixiApp) {
|
|
332
|
+
pixiApp.destroy(true, true);
|
|
333
|
+
pixiApp = null;
|
|
334
|
+
templateGraphics = null;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// Watch for changes and redraw/resize
|
|
339
|
+
watchEffect(() => {
|
|
340
|
+
if (expanded.value && pixiApp) {
|
|
341
|
+
// Use nextTick to ensure all reactive values are updated
|
|
342
|
+
nextTick(() => {
|
|
343
|
+
resizeCanvas();
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Separate watcher for individual property changes
|
|
349
|
+
watchEffect(() => {
|
|
350
|
+
// Watch these specific values to trigger updates
|
|
351
|
+
const currentType = type.value;
|
|
352
|
+
const currentDirection = direction.value;
|
|
353
|
+
const currentDistance = distance.value;
|
|
354
|
+
const currentAngle = angle.value;
|
|
355
|
+
const currentWidth = width.value;
|
|
356
|
+
|
|
357
|
+
if (expanded.value && pixiApp && templateGraphics) {
|
|
358
|
+
nextTick(() => {
|
|
359
|
+
drawTemplate();
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
watch(distance, () => {
|
|
365
|
+
if (expanded.value && pixiApp) {
|
|
366
|
+
nextTick(() => {
|
|
367
|
+
resizeCanvas();
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// Watch for expansion changes
|
|
373
|
+
watchEffect(async () => {
|
|
374
|
+
if (expanded.value) {
|
|
375
|
+
await nextTick();
|
|
376
|
+
await nextTick(); // Double nextTick to ensure DOM and reactive values are ready
|
|
377
|
+
initializePixi();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
onMounted(() => {
|
|
382
|
+
if (expanded.value) {
|
|
383
|
+
initializePixi();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
onUnmounted(() => {
|
|
388
|
+
destroyPixi();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const onPlace = () => {
|
|
392
|
+
console.log("Placing template at current cursor position");
|
|
393
|
+
game.system.measuredTemplatePreviewClass.place({
|
|
394
|
+
type: type.value,
|
|
395
|
+
distance: distance.value,
|
|
396
|
+
direction: direction.value,
|
|
397
|
+
angle: angle.value,
|
|
398
|
+
width: width.value
|
|
399
|
+
}, document.sheet);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
</script>
|
|
403
|
+
|
|
404
|
+
<template>
|
|
405
|
+
<v-input class="isdl-tracker isdl-measured-template">
|
|
406
|
+
<template #default>
|
|
407
|
+
<v-field
|
|
408
|
+
class="v-field--active"
|
|
409
|
+
density="compact"
|
|
410
|
+
variant="outlined"
|
|
411
|
+
>
|
|
412
|
+
<template #label>
|
|
413
|
+
<span v-html="getLabel" />
|
|
414
|
+
</template>
|
|
415
|
+
<template #append-inner>
|
|
416
|
+
<v-icon
|
|
417
|
+
icon="fa-solid fa-border-outer"
|
|
418
|
+
class="map-icon"
|
|
419
|
+
@click.stop="onPlace"
|
|
420
|
+
data-tooltip="Place"
|
|
421
|
+
:color="primaryColor" />
|
|
422
|
+
<v-icon
|
|
423
|
+
:icon="expandIcon"
|
|
424
|
+
@click.stop="expanded = !expanded"
|
|
425
|
+
class="v-select__menu-icon"
|
|
426
|
+
/>
|
|
427
|
+
</template>
|
|
428
|
+
<div class="tracker-content flexcol">
|
|
429
|
+
<div class="d-flex tracker-inner-content">
|
|
430
|
+
<span v-html="summary" />
|
|
431
|
+
</div>
|
|
432
|
+
<v-expand-transition>
|
|
433
|
+
<div v-show="expanded" class="template-expanded-content" style="margin-top: 1rem;">
|
|
434
|
+
<div class="template-controls">
|
|
435
|
+
<div class="d-flex flex-row">
|
|
436
|
+
<v-select
|
|
437
|
+
:model-value="type"
|
|
438
|
+
@update:model-value="(v) => { type = v; if (document) document.update({ [systemPath + '.type']: v }); }"
|
|
439
|
+
:name="systemPath + '.type'"
|
|
440
|
+
:items="[
|
|
441
|
+
{ title: 'Circle', value: 'circle' },
|
|
442
|
+
{ title: 'Cone', value: 'cone' },
|
|
443
|
+
{ title: 'Rectangle', value: 'rectangle' },
|
|
444
|
+
{ title: 'Ray', value: 'ray' }
|
|
445
|
+
]"
|
|
446
|
+
label="Type"
|
|
447
|
+
density="compact"
|
|
448
|
+
variant="outlined"
|
|
449
|
+
class="control-field slim-number"
|
|
450
|
+
:hide-details="true"
|
|
451
|
+
:tile="true"
|
|
452
|
+
:disabled="disabled"
|
|
453
|
+
/>
|
|
454
|
+
<v-number-input
|
|
455
|
+
:model-value="direction"
|
|
456
|
+
@update:model-value="(v) => { direction = v; persistOnStep(systemPath + '.direction', v); }"
|
|
457
|
+
:name="systemPath + '.direction'"
|
|
458
|
+
label="Direction (°)"
|
|
459
|
+
controlVariant="stacked"
|
|
460
|
+
density="compact"
|
|
461
|
+
variant="outlined"
|
|
462
|
+
class="control-field slim-number"
|
|
463
|
+
:hide-details="true"
|
|
464
|
+
:tile="true"
|
|
465
|
+
:min="0"
|
|
466
|
+
:max="360"
|
|
467
|
+
:step="0.5"
|
|
468
|
+
:precision="1"
|
|
469
|
+
:disabled="disabled"
|
|
470
|
+
/>
|
|
471
|
+
</div>
|
|
472
|
+
<div class="d-flex flex-row" style="margin-top: 1rem;">
|
|
473
|
+
<v-number-input
|
|
474
|
+
:model-value="distance"
|
|
475
|
+
@update:model-value="(v) => { distance = v; persistOnStep(systemPath + '.distance', v); }"
|
|
476
|
+
:name="systemPath + '.distance'"
|
|
477
|
+
label="Distance (grid units)"
|
|
478
|
+
controlVariant="stacked"
|
|
479
|
+
density="compact"
|
|
480
|
+
variant="outlined"
|
|
481
|
+
class="control-field"
|
|
482
|
+
:hide-details="true"
|
|
483
|
+
:tile="true"
|
|
484
|
+
:min="0"
|
|
485
|
+
:precision="1"
|
|
486
|
+
:step="0.5"
|
|
487
|
+
:disabled="disabled"
|
|
488
|
+
/>
|
|
489
|
+
<v-number-input
|
|
490
|
+
v-if="type === 'cone'"
|
|
491
|
+
:model-value="angle"
|
|
492
|
+
@update:model-value="(v) => { angle = v; persistOnStep(systemPath + '.angle', v); }"
|
|
493
|
+
:name="systemPath + '.angle'"
|
|
494
|
+
label="Angle (°)"
|
|
495
|
+
controlVariant="stacked"
|
|
496
|
+
density="compact"
|
|
497
|
+
variant="outlined"
|
|
498
|
+
class="control-field slim-number"
|
|
499
|
+
:hide-details="true"
|
|
500
|
+
:tile="true"
|
|
501
|
+
:min="0"
|
|
502
|
+
:max="360"
|
|
503
|
+
:step="0.5"
|
|
504
|
+
:precision="1"
|
|
505
|
+
:disabled="disabled"
|
|
506
|
+
/>
|
|
507
|
+
<v-number-input
|
|
508
|
+
v-if="type === 'ray'"
|
|
509
|
+
:model-value="width"
|
|
510
|
+
@update:model-value="(v) => { width = v; persistOnStep(systemPath + '.width', v); }"
|
|
511
|
+
:name="systemPath + '.width'"
|
|
512
|
+
label="Width (grid units)"
|
|
513
|
+
controlVariant="stacked"
|
|
514
|
+
density="compact"
|
|
515
|
+
variant="outlined"
|
|
516
|
+
class="control-field slim-number"
|
|
517
|
+
:hide-details="true"
|
|
518
|
+
:tile="true"
|
|
519
|
+
:min="0"
|
|
520
|
+
:step="0.5"
|
|
521
|
+
:precision="1"
|
|
522
|
+
:disabled="disabled"
|
|
523
|
+
/>
|
|
524
|
+
</div>
|
|
525
|
+
</div>
|
|
526
|
+
<div class="template-preview" style="display: flex; margin-top: 0.5rem;">
|
|
527
|
+
<canvas
|
|
528
|
+
ref="canvasRef"
|
|
529
|
+
class="template-canvas"
|
|
530
|
+
style="margin-left: auto; margin-right: auto;"
|
|
531
|
+
></canvas>
|
|
532
|
+
</div>
|
|
533
|
+
</div>
|
|
534
|
+
</v-expand-transition>
|
|
535
|
+
</div>
|
|
536
|
+
</v-field>
|
|
537
|
+
</template>
|
|
538
|
+
</v-input>
|
|
539
|
+
</template>
|
|
540
540
|
`;
|
|
541
541
|
fs.writeFileSync(generatedFilePath, toString(fileNode));
|
|
542
542
|
}
|