@eva/plugin-trigger 2.1.0-beta.5 → 2.1.0-beta.6
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.
|
@@ -108,7 +108,7 @@ exports.Trigger = class Trigger extends eva_js.Component {
|
|
|
108
108
|
console.log('[trigger]', action.message, payload);
|
|
109
109
|
break;
|
|
110
110
|
case 'callMethod':
|
|
111
|
-
this.callMethod(action.entity, action.component, action.method, (_d = action.args) !== null && _d !== void 0 ? _d : []);
|
|
111
|
+
this.callMethod(action.entity, action.component, action.method, (_d = action.args) !== null && _d !== void 0 ? _d : [], action.ref);
|
|
112
112
|
break;
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -117,7 +117,17 @@ exports.Trigger = class Trigger extends eva_js.Component {
|
|
|
117
117
|
console.warn('[plugin-trigger] action failed', action, err);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
/**
|
|
121
|
+
* 按 (entity, componentName[, ref]) 查找并调用方法。
|
|
122
|
+
*
|
|
123
|
+
* ADR-0024B:加 `ref` 字段后修复 alert-chase.json 等模板"同 entity 多
|
|
124
|
+
* BehaviorScript / Trigger 静默 dedup"的 hidden broken state。匹配规则:
|
|
125
|
+
* - 无 ref:按 `(entity, componentName)` 取首个命中(legacy 行为)
|
|
126
|
+
* - 有 ref:按 `(entity, componentName, ref)` 三元组定位,匹配 instance.ref /
|
|
127
|
+
* instance.name / constructor.ref 字段(优先 instance.ref,与
|
|
128
|
+
* ADR-0021 BehaviorScript first-class 一致)
|
|
129
|
+
*/
|
|
130
|
+
callMethod(entity, compName, method, args, ref) {
|
|
121
131
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
122
132
|
const game = (_b = (_a = this.gameObject) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.game;
|
|
123
133
|
if (!game)
|
|
@@ -129,7 +139,7 @@ exports.Trigger = class Trigger extends eva_js.Component {
|
|
|
129
139
|
continue;
|
|
130
140
|
if (go.name === entity) {
|
|
131
141
|
const comps = (_e = go.components) !== null && _e !== void 0 ? _e : [];
|
|
132
|
-
const c =
|
|
142
|
+
const c = this.findComponentByRef(comps, compName, ref);
|
|
133
143
|
if (c && typeof c[method] === 'function') {
|
|
134
144
|
c[method](...args);
|
|
135
145
|
}
|
|
@@ -141,6 +151,32 @@ exports.Trigger = class Trigger extends eva_js.Component {
|
|
|
141
151
|
}
|
|
142
152
|
}
|
|
143
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* 从 comps 列表里取出符合 (componentName, ref) 的 Component 实例。
|
|
156
|
+
*
|
|
157
|
+
* `ref` 可选 - 未传时取首个 componentName 匹配的实例(legacy);传入时按
|
|
158
|
+
* 三元组定位,匹配优先级 instance.ref → instance.name → constructor.ref。
|
|
159
|
+
*/
|
|
160
|
+
findComponentByRef(comps, componentName, ref) {
|
|
161
|
+
if (!ref) {
|
|
162
|
+
return comps.find((c) => { var _a; return ((_a = c === null || c === void 0 ? void 0 : c.constructor) === null || _a === void 0 ? void 0 : _a.componentName) === componentName; });
|
|
163
|
+
}
|
|
164
|
+
return comps.find((c) => {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
if (((_a = c === null || c === void 0 ? void 0 : c.constructor) === null || _a === void 0 ? void 0 : _a.componentName) !== componentName)
|
|
167
|
+
return false;
|
|
168
|
+
// 优先 instance.ref(ADR-0021 BehaviorScript first-class)
|
|
169
|
+
if (typeof c.ref === 'string' && c.ref === ref)
|
|
170
|
+
return true;
|
|
171
|
+
// fallback:instance.name(自定义 Component 习惯字段)
|
|
172
|
+
if (typeof c.name === 'string' && c.name === ref)
|
|
173
|
+
return true;
|
|
174
|
+
// fallback:constructor.ref(静态标签)
|
|
175
|
+
if (((_b = c === null || c === void 0 ? void 0 : c.constructor) === null || _b === void 0 ? void 0 : _b.ref) === ref)
|
|
176
|
+
return true;
|
|
177
|
+
return false;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
144
180
|
evalGuard(guard, payload) {
|
|
145
181
|
try {
|
|
146
182
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),o=require("@eva/plugin-signal-bus");"function"==typeof SuppressedError&&SuppressedError,exports.Trigger=class extends e.Component{constructor(){super(...arguments),this.rules=[],this.subs=[],this.ctx={}}init(e){var o,t;e&&(this.rules=null!==(o=e.rules)&&void 0!==o?o:[],this.ctx=null!==(t=e.context)&&void 0!==t?t:{})}awake(){const e=o.getSignalBus();for(const o of this.rules){const t=e.on(o.on,e=>{if(!o.guard||this.evalGuard(o.guard,e))for(const t of o.do)this.exec(t,e)});this.subs.push(t)}}exec(e,t){var r,n,s,i;try{switch(e.type){case"emit":o.getSignalBus().emit(e.signal,null!==(r=e.payload)&&void 0!==r?r:t);break;case"setStore":"undefined"!=typeof mx&&(null===(n=null===mx||void 0===mx?void 0:mx.store)||void 0===n?void 0:n.update)&&mx.store.update(e.key,()=>e.value);break;case"incStore":"undefined"!=typeof mx&&(null===(s=null===mx||void 0===mx?void 0:mx.store)||void 0===s?void 0:s.update)&&mx.store.update(e.key,o=>{var t;return(null!=o?o:0)+(null!==(t=e.delta)&&void 0!==t?t:1)});break;case"log":console.log("[trigger]",e.message,t);break;case"callMethod":this.callMethod(e.entity,e.component,e.method,null!==(i=e.args)&&void 0!==i?i:[],e.ref)}}catch(o){console.warn("[plugin-trigger] action failed",e,o)}}callMethod(e,o,t,r,n){var s,i,l,u,c,a,d;const v=null===(i=null===(s=this.gameObject)||void 0===s?void 0:s.scene)||void 0===i?void 0:i.game;if(!v)return;const g=[...null!==(u=null===(l=v.scene)||void 0===l?void 0:l.gameObjects)&&void 0!==u?u:[]];for(;g.length;){const s=g.pop();if(s){if(s.name===e){const e=null!==(c=s.components)&&void 0!==c?c:[],i=this.findComponentByRef(e,o,n);return void(i&&"function"==typeof i[t]&&i[t](...r))}if(null===(d=null===(a=s.transform)||void 0===a?void 0:a.children)||void 0===d?void 0:d.length)for(const e of s.transform.children)g.push(e.gameObject)}}}findComponentByRef(e,o,t){return t?e.find(e=>{var r,n;return(null===(r=null==e?void 0:e.constructor)||void 0===r?void 0:r.componentName)===o&&("string"==typeof e.ref&&e.ref===t||("string"==typeof e.name&&e.name===t||(null===(n=null==e?void 0:e.constructor)||void 0===n?void 0:n.ref)===t))}):e.find(e=>{var t;return(null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t.componentName)===o})}evalGuard(e,o){try{const t=new Function("payload","ctx",`return (${e});`);return Boolean(t(o,this.ctx))}catch(o){return console.warn(`[plugin-trigger] bad guard "${e}":`,o),!1}}onDestroy(){for(const e of this.subs)e.dispose();this.subs=[]}},exports.Trigger.componentName="Trigger",exports.Trigger=function(e,o,t,r){var n,s=arguments.length,i=s<3?o:null===r?r=Object.getOwnPropertyDescriptor(o,t):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,o,t,r);else for(var l=e.length-1;l>=0;l--)(n=e[l])&&(i=(s<3?n(i):s>3?n(o,t,i):n(o,t))||i);return s>3&&i&&Object.defineProperty(o,t,i),i}([e.decorators.componentObserver({})],exports.Trigger);class t extends e.System{constructor(){super(...arguments),this.name="Trigger"}}t.systemName="Trigger",exports.TriggerSystem=t;
|
package/dist/plugin-trigger.d.ts
CHANGED
|
@@ -37,7 +37,24 @@ export declare class Trigger extends Component<TriggerParams> {
|
|
|
37
37
|
init(params?: TriggerParams): void;
|
|
38
38
|
awake(): void;
|
|
39
39
|
private exec;
|
|
40
|
+
/**
|
|
41
|
+
* 按 (entity, componentName[, ref]) 查找并调用方法。
|
|
42
|
+
*
|
|
43
|
+
* ADR-0024B:加 `ref` 字段后修复 alert-chase.json 等模板"同 entity 多
|
|
44
|
+
* BehaviorScript / Trigger 静默 dedup"的 hidden broken state。匹配规则:
|
|
45
|
+
* - 无 ref:按 `(entity, componentName)` 取首个命中(legacy 行为)
|
|
46
|
+
* - 有 ref:按 `(entity, componentName, ref)` 三元组定位,匹配 instance.ref /
|
|
47
|
+
* instance.name / constructor.ref 字段(优先 instance.ref,与
|
|
48
|
+
* ADR-0021 BehaviorScript first-class 一致)
|
|
49
|
+
*/
|
|
40
50
|
private callMethod;
|
|
51
|
+
/**
|
|
52
|
+
* 从 comps 列表里取出符合 (componentName, ref) 的 Component 实例。
|
|
53
|
+
*
|
|
54
|
+
* `ref` 可选 - 未传时取首个 componentName 匹配的实例(legacy);传入时按
|
|
55
|
+
* 三元组定位,匹配优先级 instance.ref → instance.name → constructor.ref。
|
|
56
|
+
*/
|
|
57
|
+
private findComponentByRef;
|
|
41
58
|
private evalGuard;
|
|
42
59
|
onDestroy(): void;
|
|
43
60
|
}
|
|
@@ -64,6 +81,18 @@ export declare type TriggerAction = {
|
|
|
64
81
|
component: string;
|
|
65
82
|
method: string;
|
|
66
83
|
args?: any[];
|
|
84
|
+
/**
|
|
85
|
+
* 同 entity 上同 componentName 多实例时的实例区分符(ADR-0024B / ADR-0015)。
|
|
86
|
+
*
|
|
87
|
+
* 默认按 `(entity, componentName)` 二元组定位 — 同名多实例时取首个命中。
|
|
88
|
+
* 设 `ref` 后按 `(entity, componentName, ref)` 三元组定位,匹配
|
|
89
|
+
* `BehaviorScript` 的 ADR-0021 `ref` 字段或自定义 Component 的 `name` /
|
|
90
|
+
* `static ref` 字段。
|
|
91
|
+
*
|
|
92
|
+
* 修复 alert-chase.json 模板"同 entity 多 BehaviorScript 静默 dedup"的
|
|
93
|
+
* hidden broken state。
|
|
94
|
+
*/
|
|
95
|
+
ref?: string;
|
|
67
96
|
};
|
|
68
97
|
|
|
69
98
|
export declare interface TriggerParams {
|
|
@@ -104,7 +104,7 @@ let Trigger = class Trigger extends Component {
|
|
|
104
104
|
console.log('[trigger]', action.message, payload);
|
|
105
105
|
break;
|
|
106
106
|
case 'callMethod':
|
|
107
|
-
this.callMethod(action.entity, action.component, action.method, (_d = action.args) !== null && _d !== void 0 ? _d : []);
|
|
107
|
+
this.callMethod(action.entity, action.component, action.method, (_d = action.args) !== null && _d !== void 0 ? _d : [], action.ref);
|
|
108
108
|
break;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -113,7 +113,17 @@ let Trigger = class Trigger extends Component {
|
|
|
113
113
|
console.warn('[plugin-trigger] action failed', action, err);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
/**
|
|
117
|
+
* 按 (entity, componentName[, ref]) 查找并调用方法。
|
|
118
|
+
*
|
|
119
|
+
* ADR-0024B:加 `ref` 字段后修复 alert-chase.json 等模板"同 entity 多
|
|
120
|
+
* BehaviorScript / Trigger 静默 dedup"的 hidden broken state。匹配规则:
|
|
121
|
+
* - 无 ref:按 `(entity, componentName)` 取首个命中(legacy 行为)
|
|
122
|
+
* - 有 ref:按 `(entity, componentName, ref)` 三元组定位,匹配 instance.ref /
|
|
123
|
+
* instance.name / constructor.ref 字段(优先 instance.ref,与
|
|
124
|
+
* ADR-0021 BehaviorScript first-class 一致)
|
|
125
|
+
*/
|
|
126
|
+
callMethod(entity, compName, method, args, ref) {
|
|
117
127
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
118
128
|
const game = (_b = (_a = this.gameObject) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.game;
|
|
119
129
|
if (!game)
|
|
@@ -125,7 +135,7 @@ let Trigger = class Trigger extends Component {
|
|
|
125
135
|
continue;
|
|
126
136
|
if (go.name === entity) {
|
|
127
137
|
const comps = (_e = go.components) !== null && _e !== void 0 ? _e : [];
|
|
128
|
-
const c =
|
|
138
|
+
const c = this.findComponentByRef(comps, compName, ref);
|
|
129
139
|
if (c && typeof c[method] === 'function') {
|
|
130
140
|
c[method](...args);
|
|
131
141
|
}
|
|
@@ -137,6 +147,32 @@ let Trigger = class Trigger extends Component {
|
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* 从 comps 列表里取出符合 (componentName, ref) 的 Component 实例。
|
|
152
|
+
*
|
|
153
|
+
* `ref` 可选 - 未传时取首个 componentName 匹配的实例(legacy);传入时按
|
|
154
|
+
* 三元组定位,匹配优先级 instance.ref → instance.name → constructor.ref。
|
|
155
|
+
*/
|
|
156
|
+
findComponentByRef(comps, componentName, ref) {
|
|
157
|
+
if (!ref) {
|
|
158
|
+
return comps.find((c) => { var _a; return ((_a = c === null || c === void 0 ? void 0 : c.constructor) === null || _a === void 0 ? void 0 : _a.componentName) === componentName; });
|
|
159
|
+
}
|
|
160
|
+
return comps.find((c) => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
if (((_a = c === null || c === void 0 ? void 0 : c.constructor) === null || _a === void 0 ? void 0 : _a.componentName) !== componentName)
|
|
163
|
+
return false;
|
|
164
|
+
// 优先 instance.ref(ADR-0021 BehaviorScript first-class)
|
|
165
|
+
if (typeof c.ref === 'string' && c.ref === ref)
|
|
166
|
+
return true;
|
|
167
|
+
// fallback:instance.name(自定义 Component 习惯字段)
|
|
168
|
+
if (typeof c.name === 'string' && c.name === ref)
|
|
169
|
+
return true;
|
|
170
|
+
// fallback:constructor.ref(静态标签)
|
|
171
|
+
if (((_b = c === null || c === void 0 ? void 0 : c.constructor) === null || _b === void 0 ? void 0 : _b.ref) === ref)
|
|
172
|
+
return true;
|
|
173
|
+
return false;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
140
176
|
evalGuard(guard, payload) {
|
|
141
177
|
try {
|
|
142
178
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-trigger",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.6",
|
|
4
4
|
"description": "Trigger — 信号 → DSL 动作的执行器,DSL 配置 \"on signal\" + \"do actions\",emit/setStore/transitionState/playSound 等。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-trigger.esm.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@eva/eva.js": "2.1.0-beta.
|
|
21
|
-
"@eva/plugin-signal-bus": "2.1.0-beta.
|
|
20
|
+
"@eva/eva.js": "2.1.0-beta.6",
|
|
21
|
+
"@eva/plugin-signal-bus": "2.1.0-beta.6"
|
|
22
22
|
}
|
|
23
23
|
}
|