intelligent-system-design-language 0.3.22 → 0.3.24

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.
Files changed (106) hide show
  1. package/.claude/agents/langium-language-designer.md +38 -38
  2. package/.claude/agents/typescript-vscode-expert.md +29 -29
  3. package/.claude/agents/ui-ux-designer.md +36 -36
  4. package/.claude/settings.local.json +33 -33
  5. package/.idea/inspectionProfiles/Project_Default.xml +6 -6
  6. package/.idea/isdl.iml +13 -13
  7. package/.idea/modules.xml +8 -8
  8. package/.idea/vcs.xml +6 -6
  9. package/.idea/watcherTasks.xml +3 -3
  10. package/.vscodeignore +18 -18
  11. package/LICENSE +673 -673
  12. package/README.md +86 -86
  13. package/bin/cli.js +4 -4
  14. package/bin/lsp.js +8 -8
  15. package/out/_backgrounds.scss +91 -91
  16. package/out/_handlebars.scss +497 -497
  17. package/out/_isdlStyles.scss +1444 -1444
  18. package/out/_vuetifyOverrides.scss +425 -425
  19. package/out/_vuetifyStyles.scss +31957 -31957
  20. package/out/cli/components/_backgrounds.scss +91 -91
  21. package/out/cli/components/_handlebars.scss +497 -497
  22. package/out/cli/components/_isdlStyles.scss +1444 -1444
  23. package/out/cli/components/_vuetifyOverrides.scss +425 -425
  24. package/out/cli/components/_vuetifyStyles.scss +31957 -31957
  25. package/out/cli/components/active-effect-sheet-generator.js +453 -453
  26. package/out/cli/components/chat-card-generator.js +654 -654
  27. package/out/cli/components/css-generator.js +4 -4
  28. package/out/cli/components/damage-roll-generator.js +160 -160
  29. package/out/cli/components/datamodel-generator.js +257 -257
  30. package/out/cli/components/derived-data-generator.js +923 -923
  31. package/out/cli/components/hotbar-drop-hook-generator.js +82 -82
  32. package/out/cli/components/init-hook-generator.js +495 -495
  33. package/out/cli/components/language-generator.js +1 -1
  34. package/out/cli/components/language-generator.js.map +1 -1
  35. package/out/cli/components/measured-template-preview.js +221 -221
  36. package/out/cli/components/method-generator.js +601 -562
  37. package/out/cli/components/method-generator.js.map +1 -1
  38. package/out/cli/components/ready-hook-generator.js +404 -404
  39. package/out/cli/components/token-generator.js +116 -116
  40. package/out/cli/components/vue/base-components/vue-attribute.js +138 -138
  41. package/out/cli/components/vue/base-components/vue-boolean.js +64 -64
  42. package/out/cli/components/vue/base-components/vue-calculator.js +93 -93
  43. package/out/cli/components/vue/base-components/vue-damage-application.js +356 -356
  44. package/out/cli/components/vue/base-components/vue-damage-bonuses.js +165 -165
  45. package/out/cli/components/vue/base-components/vue-damage-resistances.js +196 -196
  46. package/out/cli/components/vue/base-components/vue-damage-track.js +121 -121
  47. package/out/cli/components/vue/base-components/vue-date-time.js +42 -42
  48. package/out/cli/components/vue/base-components/vue-dice.js +98 -98
  49. package/out/cli/components/vue/base-components/vue-die.js +73 -73
  50. package/out/cli/components/vue/base-components/vue-document-choice.js +149 -149
  51. package/out/cli/components/vue/base-components/vue-document-choices.js +179 -179
  52. package/out/cli/components/vue/base-components/vue-document-link.js +60 -60
  53. package/out/cli/components/vue/base-components/vue-extended-choice.js +88 -88
  54. package/out/cli/components/vue/base-components/vue-inventory.js +519 -519
  55. package/out/cli/components/vue/base-components/vue-macro-choice.js +138 -138
  56. package/out/cli/components/vue/base-components/vue-measured-template.js +530 -530
  57. package/out/cli/components/vue/base-components/vue-money.js +483 -483
  58. package/out/cli/components/vue/base-components/vue-number.js +174 -174
  59. package/out/cli/components/vue/base-components/vue-paperdoll.js +43 -43
  60. package/out/cli/components/vue/base-components/vue-parent-property-reference.js +76 -76
  61. package/out/cli/components/vue/base-components/vue-prosemirror.js +18 -18
  62. package/out/cli/components/vue/base-components/vue-resource.js +136 -136
  63. package/out/cli/components/vue/base-components/vue-roll-visualizer.js +285 -285
  64. package/out/cli/components/vue/base-components/vue-self-property-reference.js +62 -62
  65. package/out/cli/components/vue/base-components/vue-string-choice.js +98 -98
  66. package/out/cli/components/vue/base-components/vue-string-choices.js +203 -203
  67. package/out/cli/components/vue/base-components/vue-string.js +60 -60
  68. package/out/cli/components/vue/base-components/vue-text-field.js +53 -53
  69. package/out/cli/components/vue/base-components/vue-tracker.js +431 -431
  70. package/out/cli/components/vue/vue-action-component-generator.js +64 -64
  71. package/out/cli/components/vue/vue-active-effect-sheet-generator.js +856 -856
  72. package/out/cli/components/vue/vue-datatable-sheet-class-generator.js +292 -292
  73. package/out/cli/components/vue/vue-datatable2-component-generator.js +824 -824
  74. package/out/cli/components/vue/vue-document-creation-app.js +121 -121
  75. package/out/cli/components/vue/vue-document-creation-sheet.js +94 -94
  76. package/out/cli/components/vue/vue-generator.js +40 -40
  77. package/out/cli/components/vue/vue-mixin.js +296 -296
  78. package/out/cli/components/vue/vue-pinned-datatable-component-generator.js +260 -260
  79. package/out/cli/components/vue/vue-prompt-generator.js +80 -80
  80. package/out/cli/components/vue/vue-prompt-sheet-class-generator.js +317 -317
  81. package/out/cli/components/vue/vue-sheet-application-generator.js +1171 -1171
  82. package/out/cli/components/vue/vue-sheet-class-generator.js +510 -510
  83. package/out/cli/generator.js +508 -438
  84. package/out/cli/generator.js.map +1 -1
  85. package/out/extension/github/githubManager.js +35 -35
  86. package/out/extension/github/githubQuickActions.js +120 -120
  87. package/out/extension/github/system-workflow.yml +47 -47
  88. package/out/extension/main.cjs +881 -311
  89. package/out/extension/main.cjs.map +3 -3
  90. package/out/extension/package.json +419 -419
  91. package/out/language/generated/ast.js +98 -2
  92. package/out/language/generated/ast.js.map +1 -1
  93. package/out/language/generated/grammar.js +14688 -14240
  94. package/out/language/generated/grammar.js.map +1 -1
  95. package/out/language/intelligent-system-design-language-validator.js +44 -2
  96. package/out/language/intelligent-system-design-language-validator.js.map +1 -1
  97. package/out/language/isdl-scope-provider.js +7 -1
  98. package/out/language/isdl-scope-provider.js.map +1 -1
  99. package/out/language/main.cjs +881 -311
  100. package/out/language/main.cjs.map +3 -3
  101. package/out/package.json +419 -419
  102. package/out/progressbar.min.js +6 -6
  103. package/out/styles.scss +828 -762
  104. package/out/test/validating/diagnostics.test.js +55 -0
  105. package/out/test/validating/diagnostics.test.js.map +1 -1
  106. package/package.json +419 -419
@@ -54,202 +54,202 @@ export default function generateDamageResistancesComponent(destination, entry) {
54
54
  return JSON.stringify(damageTypeMap, null, 8);
55
55
  }
56
56
  const damageTypesObject = extractDamageTypes();
57
- const fileNode = expandToNode `
58
- <script setup>
59
- import { ref, computed, inject, watchEffect } from "vue";
60
-
61
- const props = defineProps({
62
- label: String,
63
- systemPath: String,
64
- context: Object,
65
- visibility: String,
66
- editMode: Boolean,
67
- icon: String
68
- });
69
-
70
- const document = inject("rawDocument");
71
-
72
- // Static damage type configuration extracted from AST
73
- const damageTypeConfig = ${damageTypesObject};
74
-
75
- const isHidden = computed(() => {
76
- if (props.visibility === "hidden") {
77
- return true;
78
- }
79
- if (props.visibility === "gm" && !game.user.isGM) {
80
- return true;
81
- }
82
- return false;
83
- });
84
-
85
- // Get all damage resistances from the actor's system
86
- const damageResistances = computed(() => {
87
- const system = document.system;
88
- const resistanceInfo = {};
89
-
90
- // Scan all system properties for resistance damage fields
91
- for (const [key, value] of Object.entries(system)) {
92
- const flatResistMatch = key.match(/^(.+)damageresistanceflat$/);
93
- const percentResistMatch = key.match(/^(.+)damageresistancepercent$/);
94
-
95
- let damageType = null;
96
- let effectType = null;
97
-
98
- if (flatResistMatch) {
99
- damageType = flatResistMatch[1];
100
- effectType = 'flatResistance';
101
- } else if (percentResistMatch) {
102
- damageType = percentResistMatch[1];
103
- effectType = 'percentResistance';
104
- }
105
-
106
- if (damageType && effectType) {
107
- if (!resistanceInfo[damageType]) {
108
- const damageTypeObj = damageTypeConfig[damageType] || {};
109
-
110
- resistanceInfo[damageType] = {
111
- type: damageType,
112
- label: damageTypeObj.label || damageType,
113
- icon: damageTypeObj.icon || 'fa-solid fa-circle-info',
114
- color: damageTypeObj.color || '#666666',
115
- flatResistance: 0,
116
- percentResistance: 0
117
- };
118
- }
119
-
120
- if (effectType === 'flatResistance') {
121
- resistanceInfo[damageType].flatResistance = Number(value) || 0;
122
- } else if (effectType === 'percentResistance') {
123
- resistanceInfo[damageType].percentResistance = Number(value) || 0;
124
- }
125
- }
126
- }
127
-
128
- // Convert to array and sort by damage type name
129
- return Object.values(resistanceInfo).sort((a, b) => a.type.localeCompare(b.type));
130
- });
131
-
132
- // Helper function to capitalize damage type names
133
- const capitalize = (str) => {
134
- return str.charAt(0).toUpperCase() + str.slice(1);
135
- };
136
-
137
- // Helper function to format resistance values
138
- const formatValue = (value, suffix = '') => {
139
- const numValue = Number(value) || 0;
140
- return \`\${numValue}\${suffix}\`;
141
- };
142
- </script>
143
-
144
- <template>
145
- <div v-if="!isHidden" class="isdl-damage-resistances pt-2 double-wide">
146
- <v-card class="damage-resistances-card" variant="outlined" theme="light" color="white">
147
- <v-card-title class="damage-resistances-header bg-grey-darken-3 text-white">
148
- <v-icon v-if="icon" class="me-2">{{ icon }}</v-icon>
149
- <span>{{ game.i18n.localize(label) }}</span>
150
- </v-card-title>
151
-
152
- <v-card-text class="pa-0">
153
- <div v-if="damageResistances.length === 0" class="text-center text-disabled pa-2">
154
- No damage resistances found
155
- </div>
156
-
157
- <v-table v-else density="compact" class="damage-resistances-table">
158
- <thead>
159
- <tr>
160
- <th class="text-left text-white">Type</th>
161
- <th class="text-center text-white">Flat Resistance</th>
162
- <th class="text-center text-white">% Resistance</th>
163
- </tr>
164
- </thead>
165
- <tbody>
166
- <tr v-for="damage in damageResistances" :key="damage.type" class="damage-type-row">
167
- <td class="damage-type-name">
168
- <div class="damage-type-header">
169
- <v-icon :color="damage.color" size="small" class="me-2">{{ damage.icon }}</v-icon>
170
- <span class="text-subtitle-2">{{ damage.label || capitalize(damage.type) }}</span>
171
- </div>
172
- </td>
173
- <td class="text-center">
174
- <v-chip
175
- size="small"
176
- :color="Number(damage.flatResistance) > 0 ? 'primary' : 'default'"
177
- variant="flat"
178
- class="text-white font-weight-bold"
179
- >
180
- {{ formatValue(damage.flatResistance) }}
181
- </v-chip>
182
- </td>
183
- <td class="text-center">
184
- <v-chip
185
- size="small"
186
- :color="Number(damage.percentResistance) > 0 ? 'primary' : 'default'"
187
- variant="flat"
188
- class="text-white font-weight-bold"
189
- >
190
- {{ formatValue(damage.percentResistance, '%') }}
191
- </v-chip>
192
- </td>
193
- </tr>
194
- </tbody>
195
- </v-table>
196
- </v-card-text>
197
- </v-card>
198
- </div>
199
- </template>
200
-
201
- <style scoped>
202
- .damage-resistances-card {
203
- border-radius: 6px;
204
- background: #ffffff;
205
- }
206
-
207
- .damage-resistances-header {
208
- background: #424242;
209
- color: #ffffff;
210
- padding: 6px 12px;
211
- font-size: 0.85rem;
212
- font-weight: 600;
213
- border-bottom: 1px solid #333;
214
- }
215
-
216
- .damage-resistances-table {
217
- background: #ffffff;
218
- }
219
-
220
- .damage-type-row:hover {
221
- background-color: #f9f9f9;
222
- }
223
-
224
- .damage-type-name {
225
- font-weight: 500;
226
- min-width: 120px;
227
- }
228
-
229
- .damage-type-header {
230
- display: flex;
231
- align-items: center;
232
- gap: 4px;
233
- }
234
-
235
- .v-table th {
236
- font-weight: 600;
237
- font-size: 0.8rem;
238
- color: #555;
239
- background: #fafafa;
240
- border-bottom: 1px solid #e0e0e0;
241
- }
242
-
243
- .v-table td {
244
- padding: 4px 12px;
245
- border-bottom: 1px solid #f0f0f0;
246
- }
247
-
248
- .v-chip {
249
- min-width: 48px;
250
- justify-content: center;
251
- }
252
- </style>
57
+ const fileNode = expandToNode `
58
+ <script setup>
59
+ import { ref, computed, inject, watchEffect } from "vue";
60
+
61
+ const props = defineProps({
62
+ label: String,
63
+ systemPath: String,
64
+ context: Object,
65
+ visibility: String,
66
+ editMode: Boolean,
67
+ icon: String
68
+ });
69
+
70
+ const document = inject("rawDocument");
71
+
72
+ // Static damage type configuration extracted from AST
73
+ const damageTypeConfig = ${damageTypesObject};
74
+
75
+ const isHidden = computed(() => {
76
+ if (props.visibility === "hidden") {
77
+ return true;
78
+ }
79
+ if (props.visibility === "gm" && !game.user.isGM) {
80
+ return true;
81
+ }
82
+ return false;
83
+ });
84
+
85
+ // Get all damage resistances from the actor's system
86
+ const damageResistances = computed(() => {
87
+ const system = document.system;
88
+ const resistanceInfo = {};
89
+
90
+ // Scan all system properties for resistance damage fields
91
+ for (const [key, value] of Object.entries(system)) {
92
+ const flatResistMatch = key.match(/^(.+)damageresistanceflat$/);
93
+ const percentResistMatch = key.match(/^(.+)damageresistancepercent$/);
94
+
95
+ let damageType = null;
96
+ let effectType = null;
97
+
98
+ if (flatResistMatch) {
99
+ damageType = flatResistMatch[1];
100
+ effectType = 'flatResistance';
101
+ } else if (percentResistMatch) {
102
+ damageType = percentResistMatch[1];
103
+ effectType = 'percentResistance';
104
+ }
105
+
106
+ if (damageType && effectType) {
107
+ if (!resistanceInfo[damageType]) {
108
+ const damageTypeObj = damageTypeConfig[damageType] || {};
109
+
110
+ resistanceInfo[damageType] = {
111
+ type: damageType,
112
+ label: damageTypeObj.label || damageType,
113
+ icon: damageTypeObj.icon || 'fa-solid fa-circle-info',
114
+ color: damageTypeObj.color || '#666666',
115
+ flatResistance: 0,
116
+ percentResistance: 0
117
+ };
118
+ }
119
+
120
+ if (effectType === 'flatResistance') {
121
+ resistanceInfo[damageType].flatResistance = Number(value) || 0;
122
+ } else if (effectType === 'percentResistance') {
123
+ resistanceInfo[damageType].percentResistance = Number(value) || 0;
124
+ }
125
+ }
126
+ }
127
+
128
+ // Convert to array and sort by damage type name
129
+ return Object.values(resistanceInfo).sort((a, b) => a.type.localeCompare(b.type));
130
+ });
131
+
132
+ // Helper function to capitalize damage type names
133
+ const capitalize = (str) => {
134
+ return str.charAt(0).toUpperCase() + str.slice(1);
135
+ };
136
+
137
+ // Helper function to format resistance values
138
+ const formatValue = (value, suffix = '') => {
139
+ const numValue = Number(value) || 0;
140
+ return \`\${numValue}\${suffix}\`;
141
+ };
142
+ </script>
143
+
144
+ <template>
145
+ <div v-if="!isHidden" class="isdl-damage-resistances pt-2 double-wide">
146
+ <v-card class="damage-resistances-card" variant="outlined" theme="light" color="white">
147
+ <v-card-title class="damage-resistances-header bg-grey-darken-3 text-white">
148
+ <v-icon v-if="icon" class="me-2">{{ icon }}</v-icon>
149
+ <span>{{ game.i18n.localize(label) }}</span>
150
+ </v-card-title>
151
+
152
+ <v-card-text class="pa-0">
153
+ <div v-if="damageResistances.length === 0" class="text-center text-disabled pa-2">
154
+ No damage resistances found
155
+ </div>
156
+
157
+ <v-table v-else density="compact" class="damage-resistances-table">
158
+ <thead>
159
+ <tr>
160
+ <th class="text-left text-white">Type</th>
161
+ <th class="text-center text-white">Flat Resistance</th>
162
+ <th class="text-center text-white">% Resistance</th>
163
+ </tr>
164
+ </thead>
165
+ <tbody>
166
+ <tr v-for="damage in damageResistances" :key="damage.type" class="damage-type-row">
167
+ <td class="damage-type-name">
168
+ <div class="damage-type-header">
169
+ <v-icon :color="damage.color" size="small" class="me-2">{{ damage.icon }}</v-icon>
170
+ <span class="text-subtitle-2">{{ damage.label || capitalize(damage.type) }}</span>
171
+ </div>
172
+ </td>
173
+ <td class="text-center">
174
+ <v-chip
175
+ size="small"
176
+ :color="Number(damage.flatResistance) > 0 ? 'primary' : 'default'"
177
+ variant="flat"
178
+ class="text-white font-weight-bold"
179
+ >
180
+ {{ formatValue(damage.flatResistance) }}
181
+ </v-chip>
182
+ </td>
183
+ <td class="text-center">
184
+ <v-chip
185
+ size="small"
186
+ :color="Number(damage.percentResistance) > 0 ? 'primary' : 'default'"
187
+ variant="flat"
188
+ class="text-white font-weight-bold"
189
+ >
190
+ {{ formatValue(damage.percentResistance, '%') }}
191
+ </v-chip>
192
+ </td>
193
+ </tr>
194
+ </tbody>
195
+ </v-table>
196
+ </v-card-text>
197
+ </v-card>
198
+ </div>
199
+ </template>
200
+
201
+ <style scoped>
202
+ .damage-resistances-card {
203
+ border-radius: 6px;
204
+ background: #ffffff;
205
+ }
206
+
207
+ .damage-resistances-header {
208
+ background: #424242;
209
+ color: #ffffff;
210
+ padding: 6px 12px;
211
+ font-size: 0.85rem;
212
+ font-weight: 600;
213
+ border-bottom: 1px solid #333;
214
+ }
215
+
216
+ .damage-resistances-table {
217
+ background: #ffffff;
218
+ }
219
+
220
+ .damage-type-row:hover {
221
+ background-color: #f9f9f9;
222
+ }
223
+
224
+ .damage-type-name {
225
+ font-weight: 500;
226
+ min-width: 120px;
227
+ }
228
+
229
+ .damage-type-header {
230
+ display: flex;
231
+ align-items: center;
232
+ gap: 4px;
233
+ }
234
+
235
+ .v-table th {
236
+ font-weight: 600;
237
+ font-size: 0.8rem;
238
+ color: #555;
239
+ background: #fafafa;
240
+ border-bottom: 1px solid #e0e0e0;
241
+ }
242
+
243
+ .v-table td {
244
+ padding: 4px 12px;
245
+ border-bottom: 1px solid #f0f0f0;
246
+ }
247
+
248
+ .v-chip {
249
+ min-width: 48px;
250
+ justify-content: center;
251
+ }
252
+ </style>
253
253
  `.appendNewLine();
254
254
  fs.writeFileSync(generatedFilePath, toString(fileNode));
255
255
  }
@@ -7,127 +7,127 @@ export default function generateDamageTrackComponent(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 { computed, inject } from "vue";
13
-
14
- const props = defineProps({
15
- label: String,
16
- systemPath: String,
17
- context: Object,
18
- editMode: Boolean,
19
- primaryColor: String,
20
- secondaryColor: String,
21
- types: Array,
22
- max: Number,
23
- });
24
-
25
- const document = inject("rawDocument");
26
-
27
- // types ordered from least to most severe (first type is least severe)
28
- // empty is always the "unfilled" state
29
- const typeColors = ['#888888', '#4fc3f7', '#ef5350', '#7b1fa2', '#ff9800', '#43a047'];
30
-
31
- const getColor = (index) => {
32
- if (index === 0) return props.secondaryColor ?? '#555';
33
- return typeColors[index] ?? typeColors[typeColors.length - 1];
34
- };
35
-
36
- // Build ordered list of boxes: [most-severe ... least-severe ... empty]
37
- // We render: all aggravated boxes, then lethal, then bashing, then empty
38
- const boxes = computed(() => {
39
- const result = [];
40
- const types = props.types ?? [];
41
- // Fill from most severe (last type) to least severe (first type), then empty
42
- for (let t = types.length - 1; t >= 0; t--) {
43
- const count = getVal(types[t]);
44
- for (let i = 0; i < count; i++) {
45
- result.push({ type: types[t], typeIndex: t + 1 });
46
- }
47
- }
48
- const emptyCount = getVal('empty');
49
- for (let i = 0; i < emptyCount; i++) {
50
- result.push({ type: 'empty', typeIndex: 0 });
51
- }
52
- return result;
53
- });
54
-
55
- const getVal = (type) => {
56
- const v = foundry.utils.getProperty(props.context, props.systemPath + '.' + type);
57
- return Math.max(0, Math.floor(v ?? 0));
58
- };
59
-
60
- const setVal = (type, value) => {
61
- foundry.utils.setProperty(props.context, props.systemPath + '.' + type, value);
62
- };
63
-
64
- // Left-click: fill an empty box with least-severe type
65
- const addDamage = (box, index) => {
66
- if (!props.editMode) return;
67
- const types = props.types ?? [];
68
- if (types.length === 0) return;
69
- if (box.type === 'empty') {
70
- const leastSevere = types[0];
71
- setVal(leastSevere, getVal(leastSevere) + 1);
72
- setVal('empty', getVal('empty') - 1);
73
- } else {
74
- // Upgrade: cycle to next more severe type if available
75
- const typeIndex = types.indexOf(box.type);
76
- if (typeIndex < types.length - 1) {
77
- const nextType = types[typeIndex + 1];
78
- setVal(box.type, getVal(box.type) - 1);
79
- setVal(nextType, getVal(nextType) + 1);
80
- }
81
- }
82
- };
83
-
84
- // Right-click: heal most-severe filled box → empty
85
- const healDamage = (box, index) => {
86
- if (!props.editMode) return;
87
- if (box.type === 'empty') return;
88
- setVal(box.type, getVal(box.type) - 1);
89
- setVal('empty', getVal('empty') + 1);
90
- };
91
-
92
- const getLabel = computed(() => game.i18n.localize(props.label));
93
-
94
- const boxSymbol = (type) => {
95
- const types = props.types ?? [];
96
- const idx = types.indexOf(type);
97
- if (type === 'empty') return '';
98
- if (idx === types.length - 1) return 'X';
99
- if (idx === types.length - 2) return '/';
100
- return '\\\\';
101
- };
102
- </script>
103
-
104
- <template>
105
- <div class="isdl-damage-track">
106
- <div class="damage-track-label">{{ getLabel }}</div>
107
- <div class="damage-track-boxes">
108
- <div
109
- v-for="(box, i) in boxes"
110
- :key="i"
111
- class="damage-box"
112
- :class="{ 'damage-box--filled': box.type !== 'empty', 'damage-box--empty': box.type === 'empty' }"
113
- :style="{
114
- borderColor: getColor(box.typeIndex),
115
- backgroundColor: box.type !== 'empty' ? getColor(box.typeIndex) : 'transparent',
116
- }"
117
- :data-tooltip="box.type !== 'empty' ? box.type : 'empty'"
118
- @click.stop="addDamage(box, i)"
119
- @contextmenu.prevent.stop="healDamage(box, i)"
120
- >
121
- <span class="damage-symbol">{{ boxSymbol(box.type) }}</span>
122
- </div>
123
- </div>
124
- <div class="damage-track-legend" v-if="types && types.length">
125
- <span v-for="(t, i) in types" :key="t" class="damage-legend-item">
126
- <span :style="{ color: getColor(i + 1) }">{{ boxSymbol(t) }}</span> {{ t }}
127
- </span>
128
- </div>
129
- </div>
130
- </template>
10
+ const fileNode = expandToNode `
11
+ <script setup>
12
+ import { computed, inject } from "vue";
13
+
14
+ const props = defineProps({
15
+ label: String,
16
+ systemPath: String,
17
+ context: Object,
18
+ editMode: Boolean,
19
+ primaryColor: String,
20
+ secondaryColor: String,
21
+ types: Array,
22
+ max: Number,
23
+ });
24
+
25
+ const document = inject("rawDocument");
26
+
27
+ // types ordered from least to most severe (first type is least severe)
28
+ // empty is always the "unfilled" state
29
+ const typeColors = ['#888888', '#4fc3f7', '#ef5350', '#7b1fa2', '#ff9800', '#43a047'];
30
+
31
+ const getColor = (index) => {
32
+ if (index === 0) return props.secondaryColor ?? '#555';
33
+ return typeColors[index] ?? typeColors[typeColors.length - 1];
34
+ };
35
+
36
+ // Build ordered list of boxes: [most-severe ... least-severe ... empty]
37
+ // We render: all aggravated boxes, then lethal, then bashing, then empty
38
+ const boxes = computed(() => {
39
+ const result = [];
40
+ const types = props.types ?? [];
41
+ // Fill from most severe (last type) to least severe (first type), then empty
42
+ for (let t = types.length - 1; t >= 0; t--) {
43
+ const count = getVal(types[t]);
44
+ for (let i = 0; i < count; i++) {
45
+ result.push({ type: types[t], typeIndex: t + 1 });
46
+ }
47
+ }
48
+ const emptyCount = getVal('empty');
49
+ for (let i = 0; i < emptyCount; i++) {
50
+ result.push({ type: 'empty', typeIndex: 0 });
51
+ }
52
+ return result;
53
+ });
54
+
55
+ const getVal = (type) => {
56
+ const v = foundry.utils.getProperty(props.context, props.systemPath + '.' + type);
57
+ return Math.max(0, Math.floor(v ?? 0));
58
+ };
59
+
60
+ const setVal = (type, value) => {
61
+ foundry.utils.setProperty(props.context, props.systemPath + '.' + type, value);
62
+ };
63
+
64
+ // Left-click: fill an empty box with least-severe type
65
+ const addDamage = (box, index) => {
66
+ if (!props.editMode) return;
67
+ const types = props.types ?? [];
68
+ if (types.length === 0) return;
69
+ if (box.type === 'empty') {
70
+ const leastSevere = types[0];
71
+ setVal(leastSevere, getVal(leastSevere) + 1);
72
+ setVal('empty', getVal('empty') - 1);
73
+ } else {
74
+ // Upgrade: cycle to next more severe type if available
75
+ const typeIndex = types.indexOf(box.type);
76
+ if (typeIndex < types.length - 1) {
77
+ const nextType = types[typeIndex + 1];
78
+ setVal(box.type, getVal(box.type) - 1);
79
+ setVal(nextType, getVal(nextType) + 1);
80
+ }
81
+ }
82
+ };
83
+
84
+ // Right-click: heal most-severe filled box → empty
85
+ const healDamage = (box, index) => {
86
+ if (!props.editMode) return;
87
+ if (box.type === 'empty') return;
88
+ setVal(box.type, getVal(box.type) - 1);
89
+ setVal('empty', getVal('empty') + 1);
90
+ };
91
+
92
+ const getLabel = computed(() => game.i18n.localize(props.label));
93
+
94
+ const boxSymbol = (type) => {
95
+ const types = props.types ?? [];
96
+ const idx = types.indexOf(type);
97
+ if (type === 'empty') return '';
98
+ if (idx === types.length - 1) return 'X';
99
+ if (idx === types.length - 2) return '/';
100
+ return '\\\\';
101
+ };
102
+ </script>
103
+
104
+ <template>
105
+ <div class="isdl-damage-track">
106
+ <div class="damage-track-label">{{ getLabel }}</div>
107
+ <div class="damage-track-boxes">
108
+ <div
109
+ v-for="(box, i) in boxes"
110
+ :key="i"
111
+ class="damage-box"
112
+ :class="{ 'damage-box--filled': box.type !== 'empty', 'damage-box--empty': box.type === 'empty' }"
113
+ :style="{
114
+ borderColor: getColor(box.typeIndex),
115
+ backgroundColor: box.type !== 'empty' ? getColor(box.typeIndex) : 'transparent',
116
+ }"
117
+ :data-tooltip="box.type !== 'empty' ? box.type : 'empty'"
118
+ @click.stop="addDamage(box, i)"
119
+ @contextmenu.prevent.stop="healDamage(box, i)"
120
+ >
121
+ <span class="damage-symbol">{{ boxSymbol(box.type) }}</span>
122
+ </div>
123
+ </div>
124
+ <div class="damage-track-legend" v-if="types && types.length">
125
+ <span v-for="(t, i) in types" :key="t" class="damage-legend-item">
126
+ <span :style="{ color: getColor(i + 1) }">{{ boxSymbol(t) }}</span> {{ t }}
127
+ </span>
128
+ </div>
129
+ </div>
130
+ </template>
131
131
  `.appendNewLine();
132
132
  fs.writeFileSync(generatedFilePath, toString(fileNode));
133
133
  }