All files / src/lib/events eventVariableAddFlags.js

60% Statements 30/50
11.76% Branches 2/17
40% Functions 2/5
82.35% Lines 28/34

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 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 1031x   1x 1x 1x       1x                                                                   1x                               16x                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x                  
const l10n = require("../helpers/l10n").default;
 
const id = "EVENT_ADD_FLAGS";
const groups = ["EVENT_GROUP_VARIABLES"];
const subGroups = {
  EVENT_GROUP_VARIABLES: "EVENT_GROUP_FLAGS",
};
 
const autoLabel = (fetchArg, input) => {
  const flags = [
    input.flag1,
    input.flag2,
    input.flag3,
    input.flag4,
    input.flag5,
    input.flag6,
    input.flag7,
    input.flag8,
    input.flag9,
    input.flag10,
    input.flag11,
    input.flag12,
    input.flag13,
    input.flag14,
    input.flag15,
    input.flag16,
  ]
    .map((value, i) => {
      Iif (value) {
        return String(i + 1);
      }
      return "";
    })
    .filter((i) => i)
    .join(",");
 
  return l10n("EVENT_ADD_FLAGS_LABEL", {
    variable: fetchArg("variable"),
    flags,
  });
};
 
const fields = [].concat(
  [
    {
      key: "variable",
      label: l10n("FIELD_VARIABLE"),
      description: l10n("FIELD_VARIABLE_DESC"),
      type: "variable",
      defaultValue: "LAST_VARIABLE",
    },
    {
      type: "break",
    },
  ],
  Array(16)
    .fill()
    .map((_, i) => {
      return {
        key: `flag${i + 1}`,
        label: l10n("FIELD_FLAG_N", { n: i + 1 }),
        description: l10n("FIELD_FLAG_SET_N_DESC", { n: i + 1 }),
        hideFromDocs: i > 3,
        type: "flag",
        width: "50%",
        flexBasis: "40%",
        defaultValue: false,
      };
    })
);
 
const compile = (input, helpers) => {
  const { variableAddFlags } = helpers;
  let flag = 0;
  if (input.flag1) flag |= 0x0001;
  Iif (input.flag2) flag |= 0x0002;
  Iif (input.flag3) flag |= 0x0004;
  Iif (input.flag4) flag |= 0x0008;
  Iif (input.flag5) flag |= 0x0010;
  Iif (input.flag6) flag |= 0x0020;
  Iif (input.flag7) flag |= 0x0040;
  if (input.flag8) flag |= 0x0080;
  Iif (input.flag9) flag |= 0x0100;
  Iif (input.flag10) flag |= 0x0200;
  Iif (input.flag11) flag |= 0x0400;
  Iif (input.flag12) flag |= 0x0800;
  Iif (input.flag13) flag |= 0x1000;
  Iif (input.flag14) flag |= 0x2000;
  Iif (input.flag15) flag |= 0x4000;
  Iif (input.flag16) flag |= 0x8000;
  variableAddFlags(input.variable, flag);
};
 
module.exports = {
  id,
  description: l10n("EVENT_ADD_FLAGS_DESC"),
  autoLabel,
  groups,
  subGroups,
  fields,
  compile,
};