Update Custom Event instances in Init scripts
When a Custom Event script was updated the instances of it in
Init Scripts (for actors and triggers) weren't updated accordingly.
Added a path in updateEntitiesCustomEventScript to also update
startScripts.
@@ -714,13 +714,7 @@ const updateEntitiesCustomEventScript = (state, type, id, entities, patch) => {
let newState = state;
const usedVariables = Object.keys(variables).map((i) => `$variable[${i}]$`);
const usedActors = Object.keys(actors).map((i) => `$actor[${i}]$`);
- Object.values(entities).forEach(entity => {
- if (!entity || !entity.script) {
- return;
- }
- const patchEntity = {
- ...entity,
- script: mapEvents(entity.script, event => {
+ const patchCustomEventScript = event => {
if (event.command !== EVENT_CALL_CUSTOM_EVENT) {
return event;
}
@@ -731,8 +725,7 @@ const updateEntitiesCustomEventScript = (state, type, id, entities, patch) => {
Object.keys(newArgs).forEach((k) => {
if (k.startsWith("$") &&
!usedVariables.find((v) => v === k) &&
- !usedActors.find((a) => a === k)
- ) {
+ !usedActors.find((a) => a === k)) {
delete newArgs[k];
}
});
@@ -743,7 +736,15 @@ const updateEntitiesCustomEventScript = (state, type, id, entities, patch) => {
script: [...script]
}
};
- })
+ };
+ Object.values(entities).forEach(entity => {
+ if (!entity || (!entity.script && !entity.startScript)) {
+ return;
+ }
+ const patchEntity = {
+ ...entity,
+ ...entity.script && { script: mapEvents(entity.script, patchCustomEventScript) },
+ ...entity.startScript && { startScript: mapEvents(entity.startScript, patchCustomEventScript) }
};
newState = editEntity(newState, type, entity.id, patchEntity);
});
