All files / src/lib/helpers eventSystem.ts

95% Statements 19/20
83.33% Branches 5/6
88.89% Functions 8/9
94.12% Lines 16/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  13x   13x 108x 22x 22x       4x     22x       13x 11x             10x                                     13x 15x 11x       13x 67x         13x  
/* eslint-disable @typescript-eslint/no-explicit-any */
import mapValues from "lodash/mapValues";
 
const filterEvents = (data: any = [], fn: any) => {
  return data.reduce((memo: any, o: any) => {
    if (fn(o)) {
      memo.push({
        ...o,
        children:
          o.children &&
          mapValues(o.children, (childEvents) => filterEvents(childEvents, fn)),
      });
    }
    return memo;
  }, []);
};
 
const filterSceneEvents = (scene: any, callback: any) => {
  return {
    ...scene,
    script: filterEvents(scene.script, callback),
    playerHit1Script: filterEvents(scene.playerHit1Script, callback),
    playerHit2Script: filterEvents(scene.playerHit2Script, callback),
    playerHit3Script: filterEvents(scene.playerHit3Script, callback),
    actors: scene.actors.map((actor: any) => {
      return {
        ...actor,
        script: filterEvents(actor.script, callback),
        startScript: filterEvents(actor.startScript, callback),
        updateScript: filterEvents(actor.updateScript, callback),
        hit1Script: filterEvents(actor.hit1Script, callback),
        hit2Script: filterEvents(actor.hit2Script, callback),
        hit3Script: filterEvents(actor.hit3Script, callback),
      };
    }),
    triggers: scene.triggers.map((trigger: any) => {
      return {
        ...trigger,
        script: filterEvents(trigger.script, callback),
      };
    }),
  };
};
 
const filterScenesEvents = (scenes: any, callback: any) => {
  return scenes.map((scene: any) => {
    return filterSceneEvents(scene, callback);
  });
};
 
const eventHasArg = (event: any, argName: any) => {
  return (
    event.args && Object.prototype.hasOwnProperty.call(event.args, argName)
  );
};
 
export { filterEvents, filterScenesEvents, filterSceneEvents, eventHasArg };