triggerix-editor-preset-war3 0.0.7 → 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 CHANGED
@@ -169,7 +169,7 @@ War3ConditionDef / ToolDef │
169
169
  - **查询**:`getAvailableEvents` / `getAvailableActions` / `getAvailableConditions`
170
170
  - **描述符**:`getEventDescriptor` / `getActionDescriptor(index)` / `getConditionDescriptor(index)` / `getToolDescriptor(name, slotValues?)` / `getSlotTools(slotDef)`
171
171
  - **状态操作**:
172
- - Event:`setEvent` / `clearEvent` / `setEventSlot`
172
+ - Event:`setEvent` / `clearEvent` / `setEventSlot`(单事件便捷);多事件:`addEvent` / `removeEvent` / `setEventSlotAt(index, …)`
173
173
  - Action:`addAction` / `removeAction` / `moveAction` / `setActionSlot`
174
174
  - Condition:`addCondition` / `removeCondition` / `setConditionSlot`
175
175
  - **值来源**:`getValueSources(valueType?)` 返回 `{ conditions, tools }`
@@ -191,14 +191,14 @@ War3ConditionDef / ToolDef │
191
191
 
192
192
  ```ts
193
193
  {
194
- id: string, // 默认 crypto.randomUUID(),可外部传入
195
- event: { type: string, payload?: Record<string, Value> },
196
- conditions?: { type: 'and', conditions: Action[] }, // 仅当 conditions 非空时存在
197
- actions: Action[] // [{ type, params? }]
194
+ id: string, // 默认 crypto.randomUUID(),可外部传入
195
+ events: { type: string, payload?: Record<string, Value> }[], // 多事件 OR 触发
196
+ conditions?: ConditionItem[], // 扁平数组,默认隐式 AND,可嵌套显式 group
197
+ actions: Action[] // [{ type, params? }]
198
198
  }
199
199
  ```
200
200
 
201
- > 注:编辑期 Condition 在内部以 `Action` 形式(`{ type, params }`)存储,序列化为 `and` 分组;Condition ↔ Action 的语义映射由运行时层完成。
201
+ > 注:编辑期 Condition 在内部以 `Action` 形式(`{ type, params }`)存储,作为扁平 `ConditionItem[]` 透传至运行时;Condition ↔ Action 的语义映射由运行时层完成。
202
202
 
203
203
  ## 模块结构
204
204
 
@@ -288,9 +288,9 @@ const emitEventTool = defineCompositeTool<
288
288
 
289
289
  ```ts
290
290
  interface War3EditorState {
291
- event: ItemState | null // 单一事件
291
+ events: ItemState[] // 多事件源(运行时按 OR 匹配);UI 单事件时通常为 0 或 1 项
292
292
  conditions: ItemState[] // 条件列表(AND 语义)
293
- actions: ItemState[] // 动作列表(顺序敏感)
293
+ actions: ItemState[] // 动作列表(顺序敏感)
294
294
  }
295
295
 
296
296
  interface ItemState {
package/dist/index.cjs CHANGED
@@ -57,7 +57,7 @@ class War3Registry extends editor.BaseRegistry {
57
57
  }
58
58
 
59
59
  const INITIAL_STATE = {
60
- event: null,
60
+ events: [],
61
61
  conditions: [],
62
62
  actions: []
63
63
  };
@@ -65,24 +65,60 @@ class War3EditorStateManager extends editor.ObservableState {
65
65
  constructor() {
66
66
  super({ ...INITIAL_STATE });
67
67
  }
68
- // --- Event ---
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
+ */
69
73
  setEvent(id) {
70
- this.setState((s) => ({ ...s, event: { id, slotValues: {} } }));
74
+ this.setState((s) => ({
75
+ ...s,
76
+ events: [{ id, slotValues: {} }]
77
+ }));
71
78
  }
79
+ /**
80
+ * Clear all events (single-event UI equivalent: no event configured).
81
+ */
72
82
  clearEvent() {
73
- this.setState((s) => ({ ...s, event: null }));
83
+ this.setState((s) => ({ ...s, events: [] }));
74
84
  }
85
+ /**
86
+ * Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
87
+ */
75
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) {
76
112
  this.setState((s) => {
77
- if (!s.event)
113
+ const target = s.events[index];
114
+ if (!target)
78
115
  return s;
79
- return {
80
- ...s,
81
- event: {
82
- ...s.event,
83
- slotValues: { ...s.event.slotValues, [key]: entry }
84
- }
116
+ const events = [...s.events];
117
+ events[index] = {
118
+ ...target,
119
+ slotValues: { ...target.slotValues, [key]: entry }
85
120
  };
121
+ return { ...s, events };
86
122
  });
87
123
  }
88
124
  // --- Actions ---
@@ -212,6 +248,13 @@ function resolveItemParams(slotValues, registry) {
212
248
  }
213
249
  return hasParams ? params : void 0;
214
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
+ }
215
258
  function serializeItems(items, registry) {
216
259
  return items.map((item) => {
217
260
  const params = resolveItemParams(item.slotValues, registry);
@@ -229,22 +272,15 @@ function generateTriggerId() {
229
272
  return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
230
273
  }
231
274
  function toTrigger(state, registry, triggerId) {
232
- const eventParams = state.event ? resolveItemParams(state.event.slotValues, registry) : void 0;
233
- const event = {
234
- type: state.event?.id ?? "",
235
- ...eventParams ? { payload: eventParams } : {}
236
- };
275
+ const events = state.events.map((item) => serializeEvent(item, registry));
237
276
  const actions = serializeItems(state.actions, registry);
238
277
  const trigger = {
239
278
  id: triggerId ?? generateTriggerId(),
240
- event,
279
+ events,
241
280
  actions
242
281
  };
243
282
  if (state.conditions.length > 0) {
244
- trigger.conditions = {
245
- type: "and",
246
- conditions: serializeItems(state.conditions, registry)
247
- };
283
+ trigger.conditions = serializeItems(state.conditions, registry);
248
284
  }
249
285
  return trigger;
250
286
  }
@@ -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
- if (!state.event)
312
+ const ev = state.events[index];
313
+ if (!ev)
277
314
  return null;
278
- return getEventDescriptor(registry, state.event.id, state.event.slotValues);
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),
package/dist/index.d.cts CHANGED
@@ -81,7 +81,12 @@ interface ItemState {
81
81
  slotValues: Record<string, SlotValueEntry>;
82
82
  }
83
83
  interface War3EditorState {
84
- event: ItemState | null;
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
  }
@@ -119,9 +124,31 @@ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War
119
124
  */
120
125
  declare class War3EditorStateManager extends ObservableState<War3EditorState> {
121
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
+ */
122
131
  setEvent(id: string): void;
132
+ /**
133
+ * Clear all events (single-event UI equivalent: no event configured).
134
+ */
123
135
  clearEvent(): void;
136
+ /**
137
+ * Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
138
+ */
124
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;
125
152
  addAction(id: string): void;
126
153
  removeAction(index: number): void;
127
154
  moveAction(from: number, to: number): void;
@@ -142,7 +169,7 @@ interface War3Editor extends Editor<War3EditorState> {
142
169
  getAvailableEvents: () => War3EventDef[];
143
170
  getAvailableActions: () => War3ActionDef[];
144
171
  getAvailableConditions: () => War3ConditionDef[];
145
- getEventDescriptor: () => ItemDescriptor | null;
172
+ getEventDescriptor: (index?: number) => ItemDescriptor | null;
146
173
  getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
147
174
  getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
148
175
  getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
@@ -150,6 +177,9 @@ interface War3Editor extends Editor<War3EditorState> {
150
177
  setEvent: (id: string) => void;
151
178
  clearEvent: () => void;
152
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;
153
183
  addAction: (id: string) => void;
154
184
  removeAction: (index: number) => void;
155
185
  moveAction: (from: number, to: number) => void;
@@ -229,9 +259,14 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
229
259
  *
230
260
  * Output shape (compatible with @triggerix/core):
231
261
  * {
232
- * id, event: { type, payload? }, conditions?: { type:'and', conditions:[...] },
262
+ * id, events: [{ type, payload? }, ...],
263
+ * conditions?: ConditionItem[] // flat array, implicit AND
233
264
  * actions: [{ type, params? }]
234
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.
235
270
  */
236
271
  declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
237
272
 
package/dist/index.d.mts CHANGED
@@ -81,7 +81,12 @@ interface ItemState {
81
81
  slotValues: Record<string, SlotValueEntry>;
82
82
  }
83
83
  interface War3EditorState {
84
- event: ItemState | null;
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
  }
@@ -119,9 +124,31 @@ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War
119
124
  */
120
125
  declare class War3EditorStateManager extends ObservableState<War3EditorState> {
121
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
+ */
122
131
  setEvent(id: string): void;
132
+ /**
133
+ * Clear all events (single-event UI equivalent: no event configured).
134
+ */
123
135
  clearEvent(): void;
136
+ /**
137
+ * Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
138
+ */
124
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;
125
152
  addAction(id: string): void;
126
153
  removeAction(index: number): void;
127
154
  moveAction(from: number, to: number): void;
@@ -142,7 +169,7 @@ interface War3Editor extends Editor<War3EditorState> {
142
169
  getAvailableEvents: () => War3EventDef[];
143
170
  getAvailableActions: () => War3ActionDef[];
144
171
  getAvailableConditions: () => War3ConditionDef[];
145
- getEventDescriptor: () => ItemDescriptor | null;
172
+ getEventDescriptor: (index?: number) => ItemDescriptor | null;
146
173
  getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
147
174
  getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
148
175
  getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
@@ -150,6 +177,9 @@ interface War3Editor extends Editor<War3EditorState> {
150
177
  setEvent: (id: string) => void;
151
178
  clearEvent: () => void;
152
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;
153
183
  addAction: (id: string) => void;
154
184
  removeAction: (index: number) => void;
155
185
  moveAction: (from: number, to: number) => void;
@@ -229,9 +259,14 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
229
259
  *
230
260
  * Output shape (compatible with @triggerix/core):
231
261
  * {
232
- * id, event: { type, payload? }, conditions?: { type:'and', conditions:[...] },
262
+ * id, events: [{ type, payload? }, ...],
263
+ * conditions?: ConditionItem[] // flat array, implicit AND
233
264
  * actions: [{ type, params? }]
234
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.
235
270
  */
236
271
  declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
237
272
 
package/dist/index.d.ts CHANGED
@@ -81,7 +81,12 @@ interface ItemState {
81
81
  slotValues: Record<string, SlotValueEntry>;
82
82
  }
83
83
  interface War3EditorState {
84
- event: ItemState | null;
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
  }
@@ -119,9 +124,31 @@ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War
119
124
  */
120
125
  declare class War3EditorStateManager extends ObservableState<War3EditorState> {
121
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
+ */
122
131
  setEvent(id: string): void;
132
+ /**
133
+ * Clear all events (single-event UI equivalent: no event configured).
134
+ */
123
135
  clearEvent(): void;
136
+ /**
137
+ * Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
138
+ */
124
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;
125
152
  addAction(id: string): void;
126
153
  removeAction(index: number): void;
127
154
  moveAction(from: number, to: number): void;
@@ -142,7 +169,7 @@ interface War3Editor extends Editor<War3EditorState> {
142
169
  getAvailableEvents: () => War3EventDef[];
143
170
  getAvailableActions: () => War3ActionDef[];
144
171
  getAvailableConditions: () => War3ConditionDef[];
145
- getEventDescriptor: () => ItemDescriptor | null;
172
+ getEventDescriptor: (index?: number) => ItemDescriptor | null;
146
173
  getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
147
174
  getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
148
175
  getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
@@ -150,6 +177,9 @@ interface War3Editor extends Editor<War3EditorState> {
150
177
  setEvent: (id: string) => void;
151
178
  clearEvent: () => void;
152
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;
153
183
  addAction: (id: string) => void;
154
184
  removeAction: (index: number) => void;
155
185
  moveAction: (from: number, to: number) => void;
@@ -229,9 +259,14 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
229
259
  *
230
260
  * Output shape (compatible with @triggerix/core):
231
261
  * {
232
- * id, event: { type, payload? }, conditions?: { type:'and', conditions:[...] },
262
+ * id, events: [{ type, payload? }, ...],
263
+ * conditions?: ConditionItem[] // flat array, implicit AND
233
264
  * actions: [{ type, params? }]
234
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.
235
270
  */
236
271
  declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
237
272
 
package/dist/index.mjs CHANGED
@@ -55,7 +55,7 @@ class War3Registry extends BaseRegistry {
55
55
  }
56
56
 
57
57
  const INITIAL_STATE = {
58
- event: null,
58
+ events: [],
59
59
  conditions: [],
60
60
  actions: []
61
61
  };
@@ -63,24 +63,60 @@ class War3EditorStateManager extends ObservableState {
63
63
  constructor() {
64
64
  super({ ...INITIAL_STATE });
65
65
  }
66
- // --- Event ---
66
+ // --- Events ---
67
+ /**
68
+ * Single-event UI helper: reset the events array to one freshly-initialized event.
69
+ * Preserves conditions and actions; only the events slot is replaced.
70
+ */
67
71
  setEvent(id) {
68
- this.setState((s) => ({ ...s, event: { id, slotValues: {} } }));
72
+ this.setState((s) => ({
73
+ ...s,
74
+ events: [{ id, slotValues: {} }]
75
+ }));
69
76
  }
77
+ /**
78
+ * Clear all events (single-event UI equivalent: no event configured).
79
+ */
70
80
  clearEvent() {
71
- this.setState((s) => ({ ...s, event: null }));
81
+ this.setState((s) => ({ ...s, events: [] }));
72
82
  }
83
+ /**
84
+ * Single-event UI helper: set a slot on events[0]. No-op when no event is configured.
85
+ */
73
86
  setEventSlot(key, entry) {
87
+ this.setEventSlotAt(0, key, entry);
88
+ }
89
+ /**
90
+ * Multi-event: append a freshly-initialized event. Returns the new event's index.
91
+ */
92
+ addEvent(id) {
93
+ const index = this.getState().events.length;
94
+ this.setState((s) => ({ ...s, events: [...s.events, { id, slotValues: {} }] }));
95
+ return index;
96
+ }
97
+ /**
98
+ * Multi-event: remove an event by index. Out-of-range index is a no-op.
99
+ */
100
+ removeEvent(index) {
101
+ this.setState((s) => ({
102
+ ...s,
103
+ events: s.events.filter((_, i) => i !== index)
104
+ }));
105
+ }
106
+ /**
107
+ * Multi-event: set a slot on the event at the given index. Out-of-range index is a no-op.
108
+ */
109
+ setEventSlotAt(index, key, entry) {
74
110
  this.setState((s) => {
75
- if (!s.event)
111
+ const target = s.events[index];
112
+ if (!target)
76
113
  return s;
77
- return {
78
- ...s,
79
- event: {
80
- ...s.event,
81
- slotValues: { ...s.event.slotValues, [key]: entry }
82
- }
114
+ const events = [...s.events];
115
+ events[index] = {
116
+ ...target,
117
+ slotValues: { ...target.slotValues, [key]: entry }
83
118
  };
119
+ return { ...s, events };
84
120
  });
85
121
  }
86
122
  // --- Actions ---
@@ -210,6 +246,13 @@ function resolveItemParams(slotValues, registry) {
210
246
  }
211
247
  return hasParams ? params : void 0;
212
248
  }
249
+ function serializeEvent(item, registry) {
250
+ const eventParams = resolveItemParams(item.slotValues, registry);
251
+ return {
252
+ type: item.id,
253
+ ...eventParams ? { payload: eventParams } : {}
254
+ };
255
+ }
213
256
  function serializeItems(items, registry) {
214
257
  return items.map((item) => {
215
258
  const params = resolveItemParams(item.slotValues, registry);
@@ -227,22 +270,15 @@ function generateTriggerId() {
227
270
  return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
228
271
  }
229
272
  function toTrigger(state, registry, triggerId) {
230
- const eventParams = state.event ? resolveItemParams(state.event.slotValues, registry) : void 0;
231
- const event = {
232
- type: state.event?.id ?? "",
233
- ...eventParams ? { payload: eventParams } : {}
234
- };
273
+ const events = state.events.map((item) => serializeEvent(item, registry));
235
274
  const actions = serializeItems(state.actions, registry);
236
275
  const trigger = {
237
276
  id: triggerId ?? generateTriggerId(),
238
- event,
277
+ events,
239
278
  actions
240
279
  };
241
280
  if (state.conditions.length > 0) {
242
- trigger.conditions = {
243
- type: "and",
244
- conditions: serializeItems(state.conditions, registry)
245
- };
281
+ trigger.conditions = serializeItems(state.conditions, registry);
246
282
  }
247
283
  return trigger;
248
284
  }
@@ -269,11 +305,12 @@ function createWar3Editor() {
269
305
  getAvailableActions: () => registry.getActions(),
270
306
  getAvailableConditions: () => registry.getConditions(),
271
307
  // --- 描述符 ---
272
- getEventDescriptor: () => {
308
+ getEventDescriptor: (index = 0) => {
273
309
  const state = stateManager.getState();
274
- if (!state.event)
310
+ const ev = state.events[index];
311
+ if (!ev)
275
312
  return null;
276
- return getEventDescriptor(registry, state.event.id, state.event.slotValues);
313
+ return getEventDescriptor(registry, ev.id, ev.slotValues);
277
314
  },
278
315
  getActionDescriptor: (index) => {
279
316
  const state = stateManager.getState();
@@ -295,6 +332,9 @@ function createWar3Editor() {
295
332
  setEvent: (id) => stateManager.setEvent(id),
296
333
  clearEvent: () => stateManager.clearEvent(),
297
334
  setEventSlot: (key, entry) => stateManager.setEventSlot(key, entry),
335
+ addEvent: (id) => stateManager.addEvent(id),
336
+ removeEvent: (index) => stateManager.removeEvent(index),
337
+ setEventSlotAt: (index, key, entry) => stateManager.setEventSlotAt(index, key, entry),
298
338
  addAction: (id) => stateManager.addAction(id),
299
339
  removeAction: (index) => stateManager.removeAction(index),
300
340
  moveAction: (from, to) => stateManager.moveAction(from, to),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "triggerix-editor-preset-war3",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "War3-style template editor preset for Triggerix",
6
6
  "homepage": "https://github.com/triggerix-collective/triggerix-editor-preset-war3#readme",
7
7
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@triggerix/core": "^0.0.8",
29
- "@triggerix/editor": "^0.0.8"
28
+ "@triggerix/core": "^0.0.10",
29
+ "@triggerix/editor": "^0.0.10"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@antfu/eslint-config": "^9.0.0",