All files / src/lib/events eventPlatformerStateSet.js

0% Statements 0/14
0% Branches 0/6
0% Functions 0/2
0% Lines 0/14

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 59 60 61 62 63 64 65 66 67 68 69 70                                                                                                                                           
const l10n = require("../helpers/l10n").default;
 
const id = "EVENT_PLATFORMER_STATE_SET";
const groups = ["EVENT_GROUP_ENGINE_FIELDS"];
const subGroups = {
  EVENT_GROUP_ENGINE_FIELDS: "GAMETYPE_PLATFORMER",
};
 
const labelsMap = {
  fall: l10n("FIELD_FALL_STATE"),
  ground: l10n("FIELD_GROUND_STATE"),
  jump: l10n("FIELD_JUMP_STATE"),
  dash: l10n("FIELD_DASH_STATE"),
  ladder: l10n("FIELD_LADDER_STATE"),
  wall: l10n("FIELD_WALL_STATE"),
  knockback: l10n("FIELD_KNOCKBACK_STATE"),
  blank: l10n("FIELD_BLANK_STATE"),
  run: l10n("FIELD_RUN_STATE"),
  float: l10n("FIELD_FLOAT_STATE"),
};
 
const valuesMap = {
  fall: "PLATFORM_FALL_STATE",
  ground: "PLATFORM_GROUND_STATE",
  jump: "PLATFORM_JUMP_STATE",
  dash: "PLATFORM_DASH_STATE",
  ladder: "PLATFORM_LADDER_STATE",
  wall: "PLATFORM_WALL_STATE",
  knockback: "PLATFORM_KNOCKBACK_STATE",
  blank: "PLATFORM_BLANK_STATE",
  run: "PLATFORM_RUN_STATE",
  float: "PLATFORM_FLOAT_STATE",
};
 
const autoLabel = (_, input) => {
  return l10n("EVENT_PLATFORMER_STATE_SET_LABEL", {
    state: labelsMap[input.state] || l10n("FIELD_FALL_STATE"),
  });
};
 
const fields = [
  {
    key: "state",
    label: l10n("FIELD_STATE"),
    type: "select",
    defaultValue: "fall",
    options: Object.entries(labelsMap),
  },
];
 
const compile = (input, helpers) => {
  const { _addComment, _setConstMemInt8 } = helpers;
  _addComment("Set Platformer State");
  _setConstMemInt8(
    "plat_next_state",
    valuesMap[input.state] ?? "PLATFORM_FALL_STATE",
  );
};
 
module.exports = {
  id,
  description: l10n("EVENT_PLATFORMER_STATE_SET_DESC"),
  autoLabel,
  groups,
  subGroups,
  fields,
  compile,
  allowedBeforeInitFade: true,
};