Skip to main content
This release is 2 versions behind 0.0.29 — the latest version of @n1xx1/ocgcore-wasm. Jump to latest

ProjectIgnis' EDOPro Core built for WebAssembly using emscripten.

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Browsers
JSR Score
88%
Published
2 weeks ago (0.0.27)

ocgcore-wasm

ProjectIgnis' EDOPro Core built for WebAssembly using emscripten.

The async version requires JS Promise Integration (JSPI) and Type reflection. Use the flag --experimental-wasm-stack-switching with node.

Example

Initialize sync version

const scriptPath = "...";
const cards = loadCardDatabase();

const lib = await createCore({ sync: true });

const handle = lib.createDuel({
  flags: OcgDuelMode.MODE_MR5,
  seed: [1n, 1n, 1n, 1n],
  team1: {
    drawCountPerTurn: 1,
    startingDrawCount: 5,
    startingLP: 8000,
  },
  team2: {
    drawCountPerTurn: 1,
    startingDrawCount: 5,
    startingLP: 8000,
  },
  cardReader: (code) => {
    const card = cards.get(code);
    if (!card) {
      console.warn("missing card: ", code);
    }
    return card ?? null;
  },
  scriptReader: (script) => {
    const filePath = script.match(/c\d+\.lua/)
      ? path.join(scriptPath, "official", script)
      : path.join(scriptPath, script);

    try {
      return readFileSync(filePath, "utf-8");
    } catch (e) {
      console.log(`error reading script "${script}", ${e}`);
      throw e;
    }
  },
  errorHandler: (type, text) => {
    console.warn(type, text);
  },
});

if (!handle) {
  throw new Error("failed to create");
}

Processing

await lib.startDuel(handle);

while (true) {
  const status = await lib.duelProcess(handle);

  const data = lib.duelGetMessage(handle);
  data.forEach((d) => console.log(d));

  if (status === OcgProcessResult.END) {
    break;
  }
  if (status === OcgProcessResult.CONTINUE) {
    continue;
  }

  // send response
  lib.duelSetResponse(handle, getNextResponse());
}
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @n1xx1/ocgcore-wasm

Import symbol

import * as mod from "@n1xx1/ocgcore-wasm";

Add Package

npx jsr add @n1xx1/ocgcore-wasm

Import symbol

import * as mod from "@n1xx1/ocgcore-wasm";

Add Package

yarn dlx jsr add @n1xx1/ocgcore-wasm

Import symbol

import * as mod from "@n1xx1/ocgcore-wasm";

Add Package

pnpm dlx jsr add @n1xx1/ocgcore-wasm

Import symbol

import * as mod from "@n1xx1/ocgcore-wasm";

Add Package

bunx jsr add @n1xx1/ocgcore-wasm

Import symbol

import * as mod from "@n1xx1/ocgcore-wasm";