ActionManager.js
32.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
(function() {
var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
var __module = nodeEnv ? module : {exports:{}};
var __filename = 'preview-scripts/assets/script/avg/ActionManager.js';
var __require = nodeEnv ? function (request) {
return cc.require(request);
} : function (request) {
return __quick_compile_project__.require(request, __filename);
};
function __define (exports, require, module) {
if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}"use strict";
cc._RF.push(module, '86449vqe09Fybjsr9QzRedG', 'ActionManager');
// script/avg/ActionManager.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionManager = void 0;
const ActionModel_1 = require("./model/ActionModel");
const EditorEvents_1 = require("./EditorEvents");
const GameRecord_1 = require("./game-data/GameRecord");
const simba_random_1 = require("simba-random");
const AudioManager_1 = require("../common/gameplay/managers/AudioManager");
const runningExecutors = new Set();
let _affectRecord = true;
class ActionExecutor {
constructor(action) {
this.sleep = (t) => {
return new Promise((resolve) => {
this._timerHandle = setTimeout(() => {
this._timerHandle = undefined;
resolve();
}, t * 1000);
});
};
this.execute = async () => {
runningExecutors.add(this);
if (this._action.trigger === ActionModel_1.TriggerType.Click) { // wait for click events
// await new Promise((resolve) => {
// this._disposable = ClickEvent.once(() => {
// resolve();
// })
// });
}
if (this._action.trigger === ActionModel_1.TriggerType.Event) {
if (!this._action.triggerEvent)
return;
return new Promise((resolve) => {
this._disposable = EditorEvents_1.EditorEvents.emitter.once(this._action.triggerEvent, async () => {
let result = await this.executeInternal();
resolve();
return result;
});
});
}
else {
return this.executeInternal();
}
};
this.executeInternal = async () => {
if (this._action.delay) {
await this.sleep(this._action.delay);
}
let finished = true;
if (this.nextExecutor && this.nextExecutor._action.trigger === ActionModel_1.TriggerType.PreviousStart) {
[finished] = await Promise.all([this.onExec(), this.nextExecutor.execute()]);
}
else {
finished = await this.onExec();
if (this.nextExecutor) {
await this.nextExecutor.execute();
}
}
if (finished) {
runningExecutors.delete(this);
}
};
this.stop = () => {
this.onStop();
if (this._disposable)
this._disposable.dispose();
if (this._timerHandle)
clearTimeout(this._timerHandle);
};
this._action = action;
}
}
class ModifyVariableExecutor extends ActionExecutor {
onExec() {
if (!_affectRecord)
return Promise.resolve(true);
try {
let action = this._action;
let varValue = GameRecord_1.GameRecord.getVariableValue(action.target);
let value = action.oprand.value;
if (action.oprand.type === ActionModel_1.OperandType.Const) {
if (typeof varValue === "number") {
value = Number.parseFloat(value);
}
}
else if (action.oprand.type === ActionModel_1.OperandType.Random) {
let arr = value.split("-");
let min = Number.parseFloat(arr[0]);
let max = Number.parseFloat(arr[1]);
value = simba_random_1.Random.range(min, max);
}
else if (action.oprand.type === ActionModel_1.OperandType.Variable) {
value = GameRecord_1.GameRecord.getVariableValue(value);
}
switch (action.operator) {
case ActionModel_1.VariableOperator.Assign:
break;
case ActionModel_1.VariableOperator.Plus:
varValue += value;
break;
case ActionModel_1.VariableOperator.Minus:
varValue -= value;
break;
case ActionModel_1.VariableOperator.Multiply:
varValue *= value;
break;
case ActionModel_1.VariableOperator.Divide:
varValue /= value;
break;
case ActionModel_1.VariableOperator.Modulo:
varValue %= value;
break;
}
GameRecord_1.GameRecord.setVariableValue(action.target, varValue);
}
catch (e) {
console.error(e);
}
return Promise.resolve(true);
}
onStop() {
}
}
class PlayAudioExecutor extends ActionExecutor {
async onExec() {
let action = this._action;
if (action.audioType === "effect") {
if (action.stopPreviousSound) {
AudioManager_1.AudioManager.stopAllEffect();
}
if (action.loopCount <= 0) {
this.audioId = await AudioManager_1.AudioManager.playEffect(action.filePath, 0);
return false;
}
else {
AudioManager_1.AudioManager.playEffect(action.filePath, action.loopCount);
}
}
else {
if (!action.filePath) {
AudioManager_1.AudioManager.stopMusic();
}
else {
AudioManager_1.AudioManager.playMusic(action.filePath);
}
if (_affectRecord) {
GameRecord_1.GameRecord.recordVariables.bgm = action.filePath;
}
}
return true;
}
onStop() {
if (this.audioId !== undefined) {
AudioManager_1.AudioManager.stopEffect(this.audioId);
}
}
}
class EmitEventExecutor extends ActionExecutor {
async onExec() {
if (this._action.emitEvent) {
await Promise.all(EditorEvents_1.EditorEvents.emitter.emit(this._action.emitEvent, this._action.param));
}
return Promise.resolve(true);
}
onStop() {
}
}
var ActionManager;
(function (ActionManager) {
function getExecutor(action) {
if (action.type === ActionModel_1.ActionType.ModifyVariable) {
return new ModifyVariableExecutor(action);
}
else if (action.type === ActionModel_1.ActionType.PlayAudio) {
return new PlayAudioExecutor(action);
}
else if (action.type === ActionModel_1.ActionType.EmitEvent) {
return new EmitEventExecutor(action);
}
return undefined;
}
let stopped = false;
let prevActions;
async function executeActions(actionData, filter, affectRecord = true) {
// if (prevActions === actionData) {
// throw new Error("Action already executed.");
// }
// prevActions = actionData;
_affectRecord = affectRecord;
if (!stopped) {
stop();
}
stopped = false;
let firstActionExecutor;
let triggerType = ActionModel_1.TriggerType.PreviousStart;
let executors = [];
let noWaitExecutors = [];
if (actionData.actions) {
let currExecutor;
for (let i = 0; i < actionData.actions.length; i++) {
if (i > 0 && actionData.actions[i].trigger === ActionModel_1.TriggerType.Event) {
if (firstActionExecutor) {
executors.push(firstActionExecutor);
firstActionExecutor = undefined;
}
}
let action = actionData.actions[i];
if (filter && !filter(action)) {
continue;
}
let executor = getExecutor(action);
if (executor) {
if (!firstActionExecutor) {
firstActionExecutor = executor;
triggerType = action.trigger;
currExecutor = executor;
}
else if (currExecutor) {
currExecutor.nextExecutor = executor;
currExecutor = executor;
}
}
}
if (firstActionExecutor) {
if (triggerType === ActionModel_1.TriggerType.PreviousStart || triggerType === ActionModel_1.TriggerType.PreviousEnd) {
executors.push(firstActionExecutor);
}
else {
noWaitExecutors.push(firstActionExecutor);
}
}
}
if (noWaitExecutors.length) {
noWaitExecutors.forEach((v) => v.execute());
}
let promises = executors.map(v => v.execute());
if (executors.length) {
await Promise.all(promises);
}
if (stopped)
return;
}
ActionManager.executeActions = executeActions;
function stop() {
if (stopped)
return;
stopped = true;
for (let executor of runningExecutors) {
executor.stop();
}
runningExecutors.clear();
//add line
// prevActions = undefined;
}
ActionManager.stop = stop;
})(ActionManager = exports.ActionManager || (exports.ActionManager = {}));
cc._RF.pop();
}
if (nodeEnv) {
__define(__module.exports, __require, __module);
}
else {
__quick_compile_project__.registerModuleFunc(__filename, function () {
__define(__module.exports, __require, __module);
});
}
})();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImFzc2V0cy9zY3JpcHQvYXZnL0FjdGlvbk1hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRUEscURBQXNLO0FBQ3RLLGlEQUE4QztBQUM5Qyx1REFBb0Q7QUFDcEQsK0NBQXNDO0FBQ3RDLDJFQUF3RTtBQUV4RSxNQUFNLGdCQUFnQixHQUFHLElBQUksR0FBRyxFQUFZLENBQUM7QUFFN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IHZhclZhbHVlICs9ICh2YWx1ZSBhcyBhbnkpO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFZhcmlhYmxlT3BlcmF0b3IuTWludXM6XG4gICAgICAgICAgICAgICAgICAgICh2YXJWYWx1ZSBhcyBudW1iZXIpIC09ICh2YWx1ZSBhcyBudW1iZXIpO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFZhcmlhYmxlT3BlcmF0b3IuTXVsdGlwbHk6XG4gICAgICAgICAgICAgICAgICAgICh2YXJWYWx1ZSBhcyBudW1iZXIpICo9ICh2YWx1ZSBhcyBudW1iZXIpO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFZhcmlhYmxlT3BlcmF0b3IuRGl2aWRlOlxuICAgICAgICAgICAgICAgICAgICAodmFyVmFsdWUgYXMgbnVtYmVyKSAvPSAodmFsdWUgYXMgbnVtYmVyKTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgY2FzZSBWYXJpYWJsZU9wZXJhdG9yLk1vZHVsbzpcbiAgICAgICAgICAgICAgICAgICAgKHZhclZhbHVlIGFzIG51bWJlcikgJT0gKHZhbHVlIGFzIG51bWJlcik7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgR2FtZVJlY29yZC5zZXRWYXJpYWJsZVZhbHVlKGFjdGlvbi50YXJnZXQsIHZhclZhbHVlKTtcbiAgICAgICAgfSBjYXRjaCAoZSkge1xuICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHRydWUpO1xuICAgIH1cblxuICAgIG9uU3RvcCgpOiB2b2lkIHtcbiAgICB9XG59XG5cbmNsYXNzIFBsYXlBdWRpb0V4ZWN1dG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FmaXJzdEFjdGlvbkV4ZWN1dG9yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBmaXJzdEFjdGlvbkV4ZWN1dG9yID0gZXhlY3V0b3I7XG4gICAgICAgICAgICAgICAgICAgICAgICB0cmlnZ2VyVHlwZSA9IGFjdGlvbi50cmlnZ2VyO1xuICAgICAgICAgICAgICAgICAgICAgICAgY3VyckV4ZWN1dG9yID0gZXhlY3V0b3I7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoY3VyckV4ZWN1dG9yKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICBjdXJyRXhlY3V0b3IubmV4dEV4ZWN1dG9yID0gZXhlY3V0b3I7XG4gICAgICAgICAgICAgICAgICAgICAgICBjdXJyRXhlY3V0b3IgPSBleGVjdXRvcjtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGZpcnN0QWN0aW9uRXhlY3V0b3IpIHtcbiAgICAgICAgICAgICAgICBpZiAodHJpZ2dlclR5cGUgPT09IFRyaWdnZXJUeXBlLlByZXZpb3VzU3RhcnQgfHwgdHJpZ2dlclR5cGUgPT09IFRyaWdnZXJUeXBlLlByZXZpb3VzRW5kKSB7XG4gICAgICAgICAgICAgICAgICAgIGV4ZWN1dG9ycy5wdXNoKGZpcnN0QWN0aW9uRXhlY3V0b3IpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG5vV2FpdEV4ZWN1dG9ycy5wdXNoKGZpcnN0QWN0aW9uRXhlY3V0b3IpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChub1dhaXRFeGVjdXRvcnMubGVuZ3RoKSB7XG4gICAgICAgICAgICBub1dhaXRFeGVjdXRvcnMuZm9yRWFjaCgodikgPT4gdi5leGVjdXRlKCkpO1xuICAgICAgIC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