import Life from "../src/life.js";
import { installFsJsonLoader, loadLocalStorage } from "../src/runtime/node.js";
import { installEventBus } from "../src/runtime/shared.js";

installFsJsonLoader();
installEventBus();
await loadLocalStorage("__test_localStorage.json");

async function debug() {
  const life = new Life();
  await life.initial();

  life.restart({
    CHR: 5, // charm
    INT: 5, // intelligence
    STR: 5, // strength
    MNY: 5, // money
    SPR: 5, // spirit
    TLT: [1134, 1048, 1114], // talents
  });

  const lifeTrajectory = [];
  let trajectory;

  do {
    trajectory = life.next();
    lifeTrajectory.push(trajectory);

    const { age, content } = trajectory;
    console.debug(
      "---------------------------------",
      `\n-- ${age}岁\n   `,
      content
        .map(({ type, description, name, postEvent }) => {
          switch (type) {
            case "TLT":
              return `天赋【${name}】发动：${description}`;
            case "EVT":
              return description + (postEvent ? `\n    ${postEvent}` : "");
            default:
              return "";
          }
        })
        .filter(Boolean)
        .join("\n    "),
    );
  } while (!trajectory.isEnd);

  return lifeTrajectory;
}

debug();
