All files / src/lib/project/migration/versions 410to420.ts

100% Statements 24/24
100% Branches 12/12
100% Functions 2/2
100% Lines 21/21

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 669x           9x     6x 5x 5x 80x 80x 80x   80x   80x         5x         1x     9x           9x     9x 5x   5x       5x         5x         4x     9x          
import {
  ScriptEventMigrationFn,
  ProjectResourcesMigration,
  createScriptEventsMigrator,
} from "lib/project/migration/helpers";
 
export const migrateFrom410r1To420r1Event: ScriptEventMigrationFn = (
  scriptEvent
) => {
  if (scriptEvent.args && scriptEvent.command === "EVENT_SWITCH") {
    const args: Record<string, unknown> = { ...scriptEvent.args };
    for (let i = 0; i < 16; i++) {
      const key = `value${i}`;
      const defaultValue = i + 1;
      const storedValue = args[key];
      const value =
        typeof storedValue === "number" ? storedValue : defaultValue;
      // Convert to constvalue
      args[key] = {
        type: "number",
        value,
      };
    }
    return {
      ...scriptEvent,
      args,
    };
  }
  return scriptEvent;
};
 
export const migrate410r1To420r1: ProjectResourcesMigration = {
  from: { version: "4.1.0", release: "1" },
  to: { version: "4.2.0", release: "1" },
  migrationFn: createScriptEventsMigrator(migrateFrom410r1To420r1Event),
};
 
export const migrateFrom420r1To420r2Event: ScriptEventMigrationFn = (
  scriptEvent
) => {
  if (scriptEvent.args && scriptEvent.command === "EVENT_WAIT") {
    const args: Record<string, unknown> = { ...scriptEvent.args };
    // Convert to constvalue
    args["frames"] = {
      type: "number",
      value: typeof args["frames"] === "number" ? args["frames"] : 30,
    };
    args["time"] = {
      type: "number",
      value: typeof args["time"] === "number" ? args["time"] : 0.5,
    };
 
    return {
      ...scriptEvent,
      args,
    };
  }
  return scriptEvent;
};
 
export const migrate420r1To420r2: ProjectResourcesMigration = {
  from: { version: "4.2.0", release: "1" },
  to: { version: "4.2.0", release: "2" },
  migrationFn: createScriptEventsMigrator(migrateFrom420r1To420r2Event),
};