triggerix-editor-preset-war3 0.0.6 → 0.0.8
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/README.md +351 -0
- package/dist/index.cjs +171 -131
- package/dist/index.d.cts +80 -45
- package/dist/index.d.mts +80 -45
- package/dist/index.d.ts +80 -45
- package/dist/index.mjs +171 -131
- package/package.json +10 -7
package/dist/index.cjs
CHANGED
|
@@ -34,47 +34,6 @@ function parseTemplate(template, slots, slotValues) {
|
|
|
34
34
|
return segments;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function buildDescriptor(def, slotValues) {
|
|
38
|
-
return {
|
|
39
|
-
id: def.id,
|
|
40
|
-
segments: parseTemplate(def.template, def.slots, slotValues)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getEventDescriptor(registry, id, slotValues) {
|
|
44
|
-
const def = registry.getEvent(id);
|
|
45
|
-
return def ? buildDescriptor(def, slotValues) : null;
|
|
46
|
-
}
|
|
47
|
-
function getActionDescriptor(registry, id, slotValues) {
|
|
48
|
-
const def = registry.getAction(id);
|
|
49
|
-
return def ? buildDescriptor(def, slotValues) : null;
|
|
50
|
-
}
|
|
51
|
-
function getConditionDescriptor(registry, id, slotValues) {
|
|
52
|
-
const def = registry.getCondition(id);
|
|
53
|
-
return def ? buildDescriptor(def, slotValues) : null;
|
|
54
|
-
}
|
|
55
|
-
function getToolDescriptor(registry, toolName, slotValues) {
|
|
56
|
-
const def = registry.getTool(toolName);
|
|
57
|
-
if (!def)
|
|
58
|
-
return null;
|
|
59
|
-
if (def.kind === "leaf") {
|
|
60
|
-
return {
|
|
61
|
-
kind: "leaf",
|
|
62
|
-
name: toolName,
|
|
63
|
-
label: def.label,
|
|
64
|
-
input: def.input
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
kind: "composite",
|
|
69
|
-
name: toolName,
|
|
70
|
-
label: def.label,
|
|
71
|
-
segments: parseTemplate(def.template, def.slots, slotValues)
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function getSlotToolDescriptors(registry, slotDef) {
|
|
75
|
-
return slotDef.tools.map((name) => getToolDescriptor(registry, name)).filter((d) => d !== null);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
37
|
class War3Registry extends editor.BaseRegistry {
|
|
79
38
|
tools = /* @__PURE__ */ new Map();
|
|
80
39
|
registerTool(name, def) {
|
|
@@ -97,74 +56,8 @@ class War3Registry extends editor.BaseRegistry {
|
|
|
97
56
|
}
|
|
98
57
|
}
|
|
99
58
|
|
|
100
|
-
function resolveSlotValue(entry, registry) {
|
|
101
|
-
if (!entry.tool)
|
|
102
|
-
return void 0;
|
|
103
|
-
const toolDef = registry.getTool(entry.tool);
|
|
104
|
-
if (!toolDef)
|
|
105
|
-
return void 0;
|
|
106
|
-
if (toolDef.kind === "leaf") {
|
|
107
|
-
return toolDef.resolve(entry.value);
|
|
108
|
-
}
|
|
109
|
-
const resolvedSubSlots = {};
|
|
110
|
-
if (entry.subSlots) {
|
|
111
|
-
for (const [key, subEntry] of Object.entries(entry.subSlots)) {
|
|
112
|
-
resolvedSubSlots[key] = resolveSlotValue(subEntry, registry);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return toolDef.resolve(resolvedSubSlots);
|
|
116
|
-
}
|
|
117
|
-
function resolveItemParams(slotValues, registry) {
|
|
118
|
-
const params = {};
|
|
119
|
-
let hasParams = false;
|
|
120
|
-
for (const [key, entry] of Object.entries(slotValues)) {
|
|
121
|
-
const resolved = resolveSlotValue(entry, registry);
|
|
122
|
-
if (resolved !== void 0) {
|
|
123
|
-
params[key] = resolved;
|
|
124
|
-
hasParams = true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return hasParams ? params : void 0;
|
|
128
|
-
}
|
|
129
|
-
function serializeItems(items, registry) {
|
|
130
|
-
return items.map((item) => {
|
|
131
|
-
const params = resolveItemParams(item.slotValues, registry);
|
|
132
|
-
const action = { type: item.id };
|
|
133
|
-
if (params) {
|
|
134
|
-
action.params = params;
|
|
135
|
-
}
|
|
136
|
-
return action;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function generateTriggerId() {
|
|
140
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
141
|
-
return globalThis.crypto.randomUUID();
|
|
142
|
-
}
|
|
143
|
-
return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
144
|
-
}
|
|
145
|
-
function toTrigger(state, registry, triggerId) {
|
|
146
|
-
const eventParams = state.event ? resolveItemParams(state.event.slotValues, registry) : void 0;
|
|
147
|
-
const event = {
|
|
148
|
-
type: state.event?.id ?? "",
|
|
149
|
-
...eventParams ? { payload: eventParams } : {}
|
|
150
|
-
};
|
|
151
|
-
const actions = serializeItems(state.actions, registry);
|
|
152
|
-
const trigger = {
|
|
153
|
-
id: triggerId ?? generateTriggerId(),
|
|
154
|
-
event,
|
|
155
|
-
actions
|
|
156
|
-
};
|
|
157
|
-
if (state.conditions.length > 0) {
|
|
158
|
-
trigger.conditions = {
|
|
159
|
-
type: "and",
|
|
160
|
-
conditions: serializeItems(state.conditions, registry)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
return trigger;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
59
|
const INITIAL_STATE = {
|
|
167
|
-
|
|
60
|
+
events: [],
|
|
168
61
|
conditions: [],
|
|
169
62
|
actions: []
|
|
170
63
|
};
|
|
@@ -172,24 +65,60 @@ class War3EditorStateManager extends editor.ObservableState {
|
|
|
172
65
|
constructor() {
|
|
173
66
|
super({ ...INITIAL_STATE });
|
|
174
67
|
}
|
|
175
|
-
// ---
|
|
68
|
+
// --- Events ---
|
|
69
|
+
/**
|
|
70
|
+
* Single-event UI helper: reset the events array to one freshly-initialized event.
|
|
71
|
+
* Preserves conditions and actions; only the events slot is replaced.
|
|
72
|
+
*/
|
|
176
73
|
setEvent(id) {
|
|
177
|
-
this.setState((s) => ({
|
|
74
|
+
this.setState((s) => ({
|
|
75
|
+
...s,
|
|
76
|
+
events: [{ id, slotValues: {} }]
|
|
77
|
+
}));
|
|
178
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Clear all events (single-event UI equivalent: no event configured).
|
|
81
|
+
*/
|
|
179
82
|
clearEvent() {
|
|
180
|
-
this.setState((s) => ({ ...s,
|
|
83
|
+
this.setState((s) => ({ ...s, events: [] }));
|
|
181
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
|
|
87
|
+
*/
|
|
182
88
|
setEventSlot(key, entry) {
|
|
89
|
+
this.setEventSlotAt(0, key, entry);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Multi-event: append a freshly-initialized event. Returns the new event's index.
|
|
93
|
+
*/
|
|
94
|
+
addEvent(id) {
|
|
95
|
+
const index = this.getState().events.length;
|
|
96
|
+
this.setState((s) => ({ ...s, events: [...s.events, { id, slotValues: {} }] }));
|
|
97
|
+
return index;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Multi-event: remove an event by index. Out-of-range index is a no-op.
|
|
101
|
+
*/
|
|
102
|
+
removeEvent(index) {
|
|
103
|
+
this.setState((s) => ({
|
|
104
|
+
...s,
|
|
105
|
+
events: s.events.filter((_, i) => i !== index)
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Multi-event: set a slot on the event at the given index. Out-of-range index is a no-op.
|
|
110
|
+
*/
|
|
111
|
+
setEventSlotAt(index, key, entry) {
|
|
183
112
|
this.setState((s) => {
|
|
184
|
-
|
|
113
|
+
const target = s.events[index];
|
|
114
|
+
if (!target)
|
|
185
115
|
return s;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
slotValues: { ...s.event.slotValues, [key]: entry }
|
|
191
|
-
}
|
|
116
|
+
const events = [...s.events];
|
|
117
|
+
events[index] = {
|
|
118
|
+
...target,
|
|
119
|
+
slotValues: { ...target.slotValues, [key]: entry }
|
|
192
120
|
};
|
|
121
|
+
return { ...s, events };
|
|
193
122
|
});
|
|
194
123
|
}
|
|
195
124
|
// --- Actions ---
|
|
@@ -249,6 +178,113 @@ class War3EditorStateManager extends editor.ObservableState {
|
|
|
249
178
|
}
|
|
250
179
|
}
|
|
251
180
|
|
|
181
|
+
function buildDescriptor(def, slotValues) {
|
|
182
|
+
return {
|
|
183
|
+
id: def.id,
|
|
184
|
+
segments: parseTemplate(def.template, def.slots, slotValues)
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function getEventDescriptor(registry, id, slotValues) {
|
|
188
|
+
const def = registry.getEvent(id);
|
|
189
|
+
return def ? buildDescriptor(def, slotValues) : null;
|
|
190
|
+
}
|
|
191
|
+
function getActionDescriptor(registry, id, slotValues) {
|
|
192
|
+
const def = registry.getAction(id);
|
|
193
|
+
return def ? buildDescriptor(def, slotValues) : null;
|
|
194
|
+
}
|
|
195
|
+
function getConditionDescriptor(registry, id, slotValues) {
|
|
196
|
+
const def = registry.getCondition(id);
|
|
197
|
+
return def ? buildDescriptor(def, slotValues) : null;
|
|
198
|
+
}
|
|
199
|
+
function getToolDescriptor(registry, toolName, slotValues) {
|
|
200
|
+
const def = registry.getTool(toolName);
|
|
201
|
+
if (!def)
|
|
202
|
+
return null;
|
|
203
|
+
if (def.kind === "leaf") {
|
|
204
|
+
return {
|
|
205
|
+
kind: "leaf",
|
|
206
|
+
name: toolName,
|
|
207
|
+
label: def.label,
|
|
208
|
+
input: def.input
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
kind: "composite",
|
|
213
|
+
name: toolName,
|
|
214
|
+
label: def.label,
|
|
215
|
+
segments: parseTemplate(def.template, def.slots, slotValues)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function getSlotToolDescriptors(registry, slotDef) {
|
|
219
|
+
return slotDef.tools.map((name) => getToolDescriptor(registry, name)).filter((d) => d !== null);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function resolveSlotValue(entry, registry) {
|
|
223
|
+
if (!entry.tool)
|
|
224
|
+
return void 0;
|
|
225
|
+
const toolDef = registry.getTool(entry.tool);
|
|
226
|
+
if (!toolDef)
|
|
227
|
+
return void 0;
|
|
228
|
+
if (toolDef.kind === "leaf") {
|
|
229
|
+
return toolDef.resolve(entry.value);
|
|
230
|
+
}
|
|
231
|
+
const resolvedSubSlots = {};
|
|
232
|
+
if (entry.subSlots) {
|
|
233
|
+
for (const [key, subEntry] of Object.entries(entry.subSlots)) {
|
|
234
|
+
resolvedSubSlots[key] = resolveSlotValue(subEntry, registry);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return toolDef.resolve(resolvedSubSlots);
|
|
238
|
+
}
|
|
239
|
+
function resolveItemParams(slotValues, registry) {
|
|
240
|
+
const params = {};
|
|
241
|
+
let hasParams = false;
|
|
242
|
+
for (const [key, entry] of Object.entries(slotValues)) {
|
|
243
|
+
const resolved = resolveSlotValue(entry, registry);
|
|
244
|
+
if (resolved !== void 0) {
|
|
245
|
+
params[key] = resolved;
|
|
246
|
+
hasParams = true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return hasParams ? params : void 0;
|
|
250
|
+
}
|
|
251
|
+
function serializeEvent(item, registry) {
|
|
252
|
+
const eventParams = resolveItemParams(item.slotValues, registry);
|
|
253
|
+
return {
|
|
254
|
+
type: item.id,
|
|
255
|
+
...eventParams ? { payload: eventParams } : {}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function serializeItems(items, registry) {
|
|
259
|
+
return items.map((item) => {
|
|
260
|
+
const params = resolveItemParams(item.slotValues, registry);
|
|
261
|
+
const action = { type: item.id };
|
|
262
|
+
if (params) {
|
|
263
|
+
action.params = params;
|
|
264
|
+
}
|
|
265
|
+
return action;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function generateTriggerId() {
|
|
269
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
270
|
+
return globalThis.crypto.randomUUID();
|
|
271
|
+
}
|
|
272
|
+
return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
273
|
+
}
|
|
274
|
+
function toTrigger(state, registry, triggerId) {
|
|
275
|
+
const events = state.events.map((item) => serializeEvent(item, registry));
|
|
276
|
+
const actions = serializeItems(state.actions, registry);
|
|
277
|
+
const trigger = {
|
|
278
|
+
id: triggerId ?? generateTriggerId(),
|
|
279
|
+
events,
|
|
280
|
+
actions
|
|
281
|
+
};
|
|
282
|
+
if (state.conditions.length > 0) {
|
|
283
|
+
trigger.conditions = serializeItems(state.conditions, registry);
|
|
284
|
+
}
|
|
285
|
+
return trigger;
|
|
286
|
+
}
|
|
287
|
+
|
|
252
288
|
function createWar3Editor() {
|
|
253
289
|
const registry = new War3Registry();
|
|
254
290
|
const stateManager = new War3EditorStateManager();
|
|
@@ -271,11 +307,12 @@ function createWar3Editor() {
|
|
|
271
307
|
getAvailableActions: () => registry.getActions(),
|
|
272
308
|
getAvailableConditions: () => registry.getConditions(),
|
|
273
309
|
// --- 描述符 ---
|
|
274
|
-
getEventDescriptor: () => {
|
|
310
|
+
getEventDescriptor: (index = 0) => {
|
|
275
311
|
const state = stateManager.getState();
|
|
276
|
-
|
|
312
|
+
const ev = state.events[index];
|
|
313
|
+
if (!ev)
|
|
277
314
|
return null;
|
|
278
|
-
return getEventDescriptor(registry,
|
|
315
|
+
return getEventDescriptor(registry, ev.id, ev.slotValues);
|
|
279
316
|
},
|
|
280
317
|
getActionDescriptor: (index) => {
|
|
281
318
|
const state = stateManager.getState();
|
|
@@ -297,6 +334,9 @@ function createWar3Editor() {
|
|
|
297
334
|
setEvent: (id) => stateManager.setEvent(id),
|
|
298
335
|
clearEvent: () => stateManager.clearEvent(),
|
|
299
336
|
setEventSlot: (key, entry) => stateManager.setEventSlot(key, entry),
|
|
337
|
+
addEvent: (id) => stateManager.addEvent(id),
|
|
338
|
+
removeEvent: (index) => stateManager.removeEvent(index),
|
|
339
|
+
setEventSlotAt: (index, key, entry) => stateManager.setEventSlotAt(index, key, entry),
|
|
300
340
|
addAction: (id) => stateManager.addAction(id),
|
|
301
341
|
removeAction: (index) => stateManager.removeAction(index),
|
|
302
342
|
moveAction: (from, to) => stateManager.moveAction(from, to),
|
|
@@ -316,6 +356,16 @@ function createWar3Editor() {
|
|
|
316
356
|
return editor;
|
|
317
357
|
}
|
|
318
358
|
|
|
359
|
+
function defineLeafTool(def) {
|
|
360
|
+
return { ...def, kind: "leaf" };
|
|
361
|
+
}
|
|
362
|
+
function defineCompositeTool(def) {
|
|
363
|
+
return { ...def, kind: "composite" };
|
|
364
|
+
}
|
|
365
|
+
function defineCondition(def) {
|
|
366
|
+
return def;
|
|
367
|
+
}
|
|
368
|
+
|
|
319
369
|
function valueEquals(a, b) {
|
|
320
370
|
if (a === b)
|
|
321
371
|
return true;
|
|
@@ -368,16 +418,6 @@ function resolveSlotDisplayText(entry, registry, fallbackLabel) {
|
|
|
368
418
|
}).join("");
|
|
369
419
|
}
|
|
370
420
|
|
|
371
|
-
function defineLeafTool(def) {
|
|
372
|
-
return { ...def, kind: "leaf" };
|
|
373
|
-
}
|
|
374
|
-
function defineCompositeTool(def) {
|
|
375
|
-
return { ...def, kind: "composite" };
|
|
376
|
-
}
|
|
377
|
-
function defineCondition(def) {
|
|
378
|
-
return def;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
421
|
function defineWar3Preset(options) {
|
|
382
422
|
return {
|
|
383
423
|
name: options.name,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseItemDef, BaseRegistry, Editor, Preset
|
|
1
|
+
import { BaseItemDef, BaseRegistry, ObservableState, Editor, Preset } from '@triggerix/editor';
|
|
2
2
|
export { BaseItemDef, Preset } from '@triggerix/editor';
|
|
3
3
|
import { Value, Trigger } from '@triggerix/core';
|
|
4
4
|
|
|
@@ -81,7 +81,12 @@ interface ItemState {
|
|
|
81
81
|
slotValues: Record<string, SlotValueEntry>;
|
|
82
82
|
}
|
|
83
83
|
interface War3EditorState {
|
|
84
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Event sources that activate the trigger (OR semantics across the array).
|
|
86
|
+
* Empty array = no event configured.
|
|
87
|
+
* Single-event UI usually keeps this at length 0 or 1.
|
|
88
|
+
*/
|
|
89
|
+
events: ItemState[];
|
|
85
90
|
conditions: ItemState[];
|
|
86
91
|
actions: ItemState[];
|
|
87
92
|
}
|
|
@@ -93,6 +98,12 @@ interface War3PresetOptions {
|
|
|
93
98
|
tools?: Record<string, ToolDef>;
|
|
94
99
|
}
|
|
95
100
|
|
|
101
|
+
/**
|
|
102
|
+
* 解析模板字符串为 Segment 数组
|
|
103
|
+
* 模板格式: "普通文本${slotKey}更多文本"
|
|
104
|
+
*/
|
|
105
|
+
declare function parseTemplate(template: string, slots?: Record<string, SlotDef>, slotValues?: Record<string, SlotValueEntry>): Segment[];
|
|
106
|
+
|
|
96
107
|
/**
|
|
97
108
|
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
98
109
|
*/
|
|
@@ -107,6 +118,48 @@ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War
|
|
|
107
118
|
};
|
|
108
119
|
}
|
|
109
120
|
|
|
121
|
+
/**
|
|
122
|
+
* War3 编辑器状态管理
|
|
123
|
+
* 继承 ObservableState,提供模板模式特有的状态操作
|
|
124
|
+
*/
|
|
125
|
+
declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
126
|
+
constructor();
|
|
127
|
+
/**
|
|
128
|
+
* Single-event UI helper: reset the events array to one freshly-initialized event.
|
|
129
|
+
* Preserves conditions and actions; only the events slot is replaced.
|
|
130
|
+
*/
|
|
131
|
+
setEvent(id: string): void;
|
|
132
|
+
/**
|
|
133
|
+
* Clear all events (single-event UI equivalent: no event configured).
|
|
134
|
+
*/
|
|
135
|
+
clearEvent(): void;
|
|
136
|
+
/**
|
|
137
|
+
* Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
|
|
138
|
+
*/
|
|
139
|
+
setEventSlot(key: string, entry: SlotValueEntry): void;
|
|
140
|
+
/**
|
|
141
|
+
* Multi-event: append a freshly-initialized event. Returns the new event's index.
|
|
142
|
+
*/
|
|
143
|
+
addEvent(id: string): number;
|
|
144
|
+
/**
|
|
145
|
+
* Multi-event: remove an event by index. Out-of-range index is a no-op.
|
|
146
|
+
*/
|
|
147
|
+
removeEvent(index: number): void;
|
|
148
|
+
/**
|
|
149
|
+
* Multi-event: set a slot on the event at the given index. Out-of-range index is a no-op.
|
|
150
|
+
*/
|
|
151
|
+
setEventSlotAt(index: number, key: string, entry: SlotValueEntry): void;
|
|
152
|
+
addAction(id: string): void;
|
|
153
|
+
removeAction(index: number): void;
|
|
154
|
+
moveAction(from: number, to: number): void;
|
|
155
|
+
setActionSlot(actionIndex: number, key: string, entry: SlotValueEntry): void;
|
|
156
|
+
addCondition(id: string): void;
|
|
157
|
+
removeCondition(index: number): void;
|
|
158
|
+
setConditionSlot(conditionIndex: number, key: string, entry: SlotValueEntry): void;
|
|
159
|
+
reset(): void;
|
|
160
|
+
private setItemSlot;
|
|
161
|
+
}
|
|
162
|
+
|
|
110
163
|
interface War3Editor extends Editor<War3EditorState> {
|
|
111
164
|
registerEvent: (def: War3EventDef) => void;
|
|
112
165
|
registerAction: (def: War3ActionDef) => void;
|
|
@@ -116,7 +169,7 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
116
169
|
getAvailableEvents: () => War3EventDef[];
|
|
117
170
|
getAvailableActions: () => War3ActionDef[];
|
|
118
171
|
getAvailableConditions: () => War3ConditionDef[];
|
|
119
|
-
getEventDescriptor: () => ItemDescriptor | null;
|
|
172
|
+
getEventDescriptor: (index?: number) => ItemDescriptor | null;
|
|
120
173
|
getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
|
|
121
174
|
getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
|
|
122
175
|
getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
|
|
@@ -124,6 +177,9 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
124
177
|
setEvent: (id: string) => void;
|
|
125
178
|
clearEvent: () => void;
|
|
126
179
|
setEventSlot: (key: string, entry: SlotValueEntry) => void;
|
|
180
|
+
addEvent: (id: string) => number;
|
|
181
|
+
removeEvent: (index: number) => void;
|
|
182
|
+
setEventSlotAt: (index: number, key: string, entry: SlotValueEntry) => void;
|
|
127
183
|
addAction: (id: string) => void;
|
|
128
184
|
removeAction: (index: number) => void;
|
|
129
185
|
moveAction: (from: number, to: number) => void;
|
|
@@ -140,24 +196,6 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
140
196
|
}
|
|
141
197
|
declare function createWar3Editor(): War3Editor;
|
|
142
198
|
|
|
143
|
-
declare function getEventDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
144
|
-
declare function getActionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
145
|
-
declare function getConditionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
146
|
-
declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
|
|
147
|
-
declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 递归解析 SlotValueEntry 为人类可读的展示文本
|
|
151
|
-
*
|
|
152
|
-
* - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
|
|
153
|
-
* - 如果 tool 为 leaf:
|
|
154
|
-
* - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
|
|
155
|
-
* - 其它类型:返回 value 的字符串形式
|
|
156
|
-
* - 若 value 为空:返回 fallbackLabel
|
|
157
|
-
* - 如果 tool 为 composite:使用 tool 的 template 递归展开
|
|
158
|
-
*/
|
|
159
|
-
declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
|
|
160
|
-
|
|
161
199
|
/**
|
|
162
200
|
* Type-safe LeafTool definition.
|
|
163
201
|
* Input type comes from the resolve callback annotation; output is inferred.
|
|
@@ -192,11 +230,23 @@ declare function defineCondition<TSlotValues extends Record<string, unknown> = R
|
|
|
192
230
|
resolve?: (slotValues: TSlotValues) => unknown;
|
|
193
231
|
}): War3ConditionDef;
|
|
194
232
|
|
|
233
|
+
declare function getEventDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
234
|
+
declare function getActionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
235
|
+
declare function getConditionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
236
|
+
declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
|
|
237
|
+
declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
|
|
238
|
+
|
|
195
239
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
240
|
+
* 递归解析 SlotValueEntry 为人类可读的展示文本
|
|
241
|
+
*
|
|
242
|
+
* - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
|
|
243
|
+
* - 如果 tool 为 leaf:
|
|
244
|
+
* - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
|
|
245
|
+
* - 其它类型:返回 value 的字符串形式
|
|
246
|
+
* - 若 value 为空:返回 fallbackLabel
|
|
247
|
+
* - 如果 tool 为 composite:使用 tool 的 template 递归展开
|
|
198
248
|
*/
|
|
199
|
-
declare function
|
|
249
|
+
declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
|
|
200
250
|
|
|
201
251
|
declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor>;
|
|
202
252
|
|
|
@@ -209,31 +259,16 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
|
|
|
209
259
|
*
|
|
210
260
|
* Output shape (compatible with @triggerix/core):
|
|
211
261
|
* {
|
|
212
|
-
* id,
|
|
262
|
+
* id, events: [{ type, payload? }, ...],
|
|
263
|
+
* conditions?: ConditionItem[] // flat array, implicit AND
|
|
213
264
|
* actions: [{ type, params? }]
|
|
214
265
|
* }
|
|
266
|
+
*
|
|
267
|
+
* - Multiple events use OR semantics at runtime.
|
|
268
|
+
* - Conditions are emitted as a flat `ConditionItem[]` (no ConditionGroup wrapper);
|
|
269
|
+
* the runtime treats the array as an implicit AND with explicit nested groups allowed.
|
|
215
270
|
*/
|
|
216
271
|
declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
|
|
217
272
|
|
|
218
|
-
/**
|
|
219
|
-
* War3 编辑器状态管理
|
|
220
|
-
* 继承 ObservableState,提供模板模式特有的状态操作
|
|
221
|
-
*/
|
|
222
|
-
declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
223
|
-
constructor();
|
|
224
|
-
setEvent(id: string): void;
|
|
225
|
-
clearEvent(): void;
|
|
226
|
-
setEventSlot(key: string, entry: SlotValueEntry): void;
|
|
227
|
-
addAction(id: string): void;
|
|
228
|
-
removeAction(index: number): void;
|
|
229
|
-
moveAction(from: number, to: number): void;
|
|
230
|
-
setActionSlot(actionIndex: number, key: string, entry: SlotValueEntry): void;
|
|
231
|
-
addCondition(id: string): void;
|
|
232
|
-
removeCondition(index: number): void;
|
|
233
|
-
setConditionSlot(conditionIndex: number, key: string, entry: SlotValueEntry): void;
|
|
234
|
-
reset(): void;
|
|
235
|
-
private setItemSlot;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
273
|
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toTrigger };
|
|
239
274
|
export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };
|