@champions-digital-game/mod-sdk 0.49.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/mc-pack.js +1 -1
- package/package.json +1 -1
- package/types/content/src/index.d.ts +1 -1
- package/types/engine/src/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @champions-digital-game/mod-sdk
|
|
2
2
|
|
|
3
3
|
The mod SDK for [Marvel Champions Digital](https://github.com/quincarter/marvel-champions-digital-game) content
|
|
4
|
-
packs, version 0.
|
|
4
|
+
packs, version 0.50.0: the pack schema, the ability DSL the game's own cards are written in, and the `mc-pack`
|
|
5
5
|
tool that validates, builds, tests and imports packs. It carries the game's rules engine, so `mc-pack test` plays
|
|
6
6
|
real headless games.
|
|
7
7
|
|
|
@@ -11,10 +11,10 @@ of Fantasy Flight Games and Marvel.
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
npm install --save-dev @champions-digital-game/mod-sdk@0.
|
|
14
|
+
npm install --save-dev @champions-digital-game/mod-sdk@0.50.0
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
The SDK is versioned with the game: a pack built with SDK 0.
|
|
17
|
+
The SDK is versioned with the game: a pack built with SDK 0.50.0 runs on app 0.50.0 and later. Every game
|
|
18
18
|
release also carries this package as a tarball, which installs the same way (`npm install --save-dev ./<file>.tgz`).
|
|
19
19
|
|
|
20
20
|
## A pack's source folder
|
package/dist/mc-pack.js
CHANGED
|
@@ -23,4 +23,4 @@ validate, build and test run the pack's own code: they import its abilities/inde
|
|
|
23
23
|
user's access to files, the network and the environment. Run them only on a pack you trust, or in a sandbox (a CI
|
|
24
24
|
job with no secrets).
|
|
25
25
|
|
|
26
|
-
Exit codes: 0 success, 1 the pack has a problem, 2 usage error.`,UsageError=class extends Error{},VALUE_FLAGS=new Set(["out","games","scenario","max-commands","id","app"]),BOOLEAN_FLAGS=new Set(["allow-unscripted","publish","help","version"]);function parseArgs(argv){let positional=[],flags=new Map;for(let i=0;i<argv.length;i++){let arg=argv[i];if(arg==="-h")flags.set("help",!0);else if(arg==="-v")flags.set("version",!0);else if(arg.startsWith("--")){let eq=arg.indexOf("="),name=eq<0?arg.slice(2):arg.slice(2,eq);if(BOOLEAN_FLAGS.has(name)){if(eq>=0)throw new UsageError(`--${name} takes no value`);flags.set(name,!0)}else if(VALUE_FLAGS.has(name)){let value2=eq>=0?arg.slice(eq+1):argv[++i];if(value2===void 0||value2==="")throw new UsageError(`--${name} needs a value`);flags.set(name,value2)}else throw new UsageError(`unknown option --${name}`)}else positional.push(arg)}return{positional,flags}}var value=(parsed,name)=>{let v=parsed.flags.get(name);return typeof v=="string"?v:void 0};function positiveInt(parsed,name){let raw=value(parsed,name);if(raw===void 0)return;let n=Number(raw);if(!Number.isInteger(n)||n<1)throw new UsageError(`--${name} must be a whole number of at least 1`);return n}function packDir(parsed,command){let[dir,...extra]=parsed.positional;if(dir===void 0)throw new UsageError(`${command} needs a folder`);if(extra.length>0)throw new UsageError(`${command} takes one folder, got ${parsed.positional.length}`);let full=resolve(dir);if(!existsSync(full))throw new UsageError(`${dir}: no such folder`);return full}function allowOnly(parsed,command,allowed){for(let name of parsed.flags.keys())if(!allowed.includes(name))throw new UsageError(`${command} does not take --${name}`)}var errorText=error=>error instanceof Error?error.message:String(error);async function loadBuilt(dir){let pack=assemblePack(await loadPackSource(dir,{importModule:packModuleImporter()}));return readPackInput(pack.manifest,pack.files)}function formatIssues(issues){let{defects,unscripted}=splitIssues(issues),lines=[];if(defects.length>0){lines.push(`${defects.length} problem${defects.length===1?"":"s"}:`);for(let issue of defects)lines.push(` ${issue.path}: ${issue.message}`)}if(unscripted.length>0){lines.push(`${unscripted.length} unscripted abilit${unscripted.length===1?"y":"ies"} (write them in abilities/):`);for(let issue of unscripted)lines.push(` ${issue.path}: ${issue.message}`)}return lines}async function validateCommand(parsed,io){allowOnly(parsed,"validate",["allow-unscripted","publish"]);let dir=packDir(parsed,"validate"),pack=await loadBuilt(dir),publish=parsed.flags.has("publish"),draft=existsSync(join(dir,"DRAFT"));publish&&draft&&io.out(`${pack.manifest.id}: a DRAFT, never published; the publish check is skipped`);let issues=[...validatePack(pack),...publish&&!draft?publishIssues(pack.manifest):[]],{defects,unscripted}=splitIssues(issues),name=`${pack.manifest.id}@${pack.manifest.version}`;if(issues.length===0)return io.out(`${name}: valid (${pack.cards.length} cards, ${Object.keys(pack.abilities).length} abilities)`),EXIT_OK;let lines=formatIssues(issues);if(defects.length===0&&parsed.flags.has("allow-unscripted")){io.out(`${name}: valid, ${unscripted.length} abilit${unscripted.length===1?"y":"ies"} to script`);for(let line of lines)io.out(line);return EXIT_OK}io.err(`${name}: invalid`);for(let line of lines)io.err(line);return EXIT_PACK_PROBLEM}async function buildCommand(parsed,io){allowOnly(parsed,"build",["out"]);let dir=packDir(parsed,"build"),out=value(parsed,"out");if(out===void 0)throw new UsageError("build needs --out <dir>");try{let result=await buildPack(dir,resolve(out),{importModule:packModuleImporter()}),{manifest}=result;return io.out(`${manifest.id}@${manifest.version}: built ${result.zipPath}`),io.out(` ${result.zipBytes} bytes, sha256 ${result.zipSha256}`),io.out(` ${manifest.files.length} files, ${manifest.totalBytes} bytes unzipped`),io.out(` requires app ${manifest.requires.app}; DSL features: ${manifest.requires.dslFeatures.join(", ")||"none"}`),EXIT_OK}catch(error){if(!(error instanceof PackBuildError))throw error;io.err("build failed: the pack is invalid");for(let line of formatIssues(error.issues))io.err(line);return EXIT_PACK_PROBLEM}}var describeGame=game=>{let where=game.deck===SMOKE_BASE_DECK?` at ${game.campaign?`${game.campaign}/${game.node} (${game.scenario})`:game.scenario}${game.modularSet?` with ${game.modularSet}`:""}${game.difficulty?`, ${game.difficulty}`:""}`:"",head=` ${game.deck}${where} seed ${game.seed}: `;if(!game.ok)return`${head}FAILED: ${game.error??"unknown error"}`;let played=game.packCardsPlayed.length>0?`; pack cards played or revealed: ${game.packCardsPlayed.join(", ")}`:"";return`${head}${game.outcome??"ended"} in round ${game.rounds} (${game.commands} commands)${played}`};async function testCommand(parsed,io){allowOnly(parsed,"test",["games","scenario","max-commands"]);let dir=packDir(parsed,"test"),scenario=value(parsed,"scenario")??"rhino";if(!SMOKE_SCENARIOS.includes(scenario))throw new UsageError(`--scenario must be one of ${SMOKE_SCENARIOS.join(", ")}`);let games=positiveInt(parsed,"games")??3,maxCommands=positiveInt(parsed,"max-commands"),pack=await loadBuilt(dir),issues=validatePack(pack);if(issues.length>0){io.err(`${pack.manifest.id}: not tested, the pack is invalid (run mc-pack validate)`);for(let line of formatIssues(issues))io.err(line);return EXIT_PACK_PROBLEM}io.out(`${pack.manifest.id}@${pack.manifest.version}: ${games} game(s) per deck, scenario and modular set (Core scenario: ${scenario})`);let result=smokeTestPack(pack,{games,scenario,...maxCommands!==void 0?{maxCommands}:{},onGame:game=>(game.ok?io.out:io.err)(describeGame(game))});for(let note of result.notes)io.out(`note: ${note}`);let failed=result.games.filter(g=>!g.ok).length;return failed>0?(io.err(`${failed} of ${result.games.length} game(s) failed`),EXIT_PACK_PROBLEM):(io.out(`all ${result.games.length} game(s) passed`),EXIT_OK)}async function importCommand(parsed,io){allowOnly(parsed,"import-marvelcdb",["out","id","app"]);let src=packDir(parsed,"import-marvelcdb"),out=value(parsed,"out"),packId=value(parsed,"id"),app=value(parsed,"app"),report=await importMarvelCdbPack(src,{...out!==void 0?{outDir:resolve(out)}:{},...packId!==void 0?{packId}:{},...app!==void 0?{app}:{}}),text=formatImportReport(report);if(!report.normalized||report.validationIssues.length>0)return io.err(text),EXIT_PACK_PROBLEM;if(io.out(text),report.unscriptedIssues.length>0){io.out(`${report.unscriptedIssues.length} abilities to script, listed in abilities/index.ts:`);for(let issue of report.unscriptedIssues)io.out(` ${issue.path}: ${issue.message}`)}return io.out(report.outDir?`written to ${report.outDir}`:"dry run: nothing written (pass --out <dir>)"),EXIT_OK}var COMMANDS={validate:validateCommand,build:buildCommand,test:testCommand,"import-marvelcdb":importCommand};async function runCli(argv,io=consoleIo){let[command,...rest]=argv;try{if(command===void 0||command==="--help"||command==="-h"||command==="help")return io.out(USAGE),command===void 0?EXIT_USAGE:EXIT_OK;if(command==="--version"||command==="-v")return io.out("0.
|
|
26
|
+
Exit codes: 0 success, 1 the pack has a problem, 2 usage error.`,UsageError=class extends Error{},VALUE_FLAGS=new Set(["out","games","scenario","max-commands","id","app"]),BOOLEAN_FLAGS=new Set(["allow-unscripted","publish","help","version"]);function parseArgs(argv){let positional=[],flags=new Map;for(let i=0;i<argv.length;i++){let arg=argv[i];if(arg==="-h")flags.set("help",!0);else if(arg==="-v")flags.set("version",!0);else if(arg.startsWith("--")){let eq=arg.indexOf("="),name=eq<0?arg.slice(2):arg.slice(2,eq);if(BOOLEAN_FLAGS.has(name)){if(eq>=0)throw new UsageError(`--${name} takes no value`);flags.set(name,!0)}else if(VALUE_FLAGS.has(name)){let value2=eq>=0?arg.slice(eq+1):argv[++i];if(value2===void 0||value2==="")throw new UsageError(`--${name} needs a value`);flags.set(name,value2)}else throw new UsageError(`unknown option --${name}`)}else positional.push(arg)}return{positional,flags}}var value=(parsed,name)=>{let v=parsed.flags.get(name);return typeof v=="string"?v:void 0};function positiveInt(parsed,name){let raw=value(parsed,name);if(raw===void 0)return;let n=Number(raw);if(!Number.isInteger(n)||n<1)throw new UsageError(`--${name} must be a whole number of at least 1`);return n}function packDir(parsed,command){let[dir,...extra]=parsed.positional;if(dir===void 0)throw new UsageError(`${command} needs a folder`);if(extra.length>0)throw new UsageError(`${command} takes one folder, got ${parsed.positional.length}`);let full=resolve(dir);if(!existsSync(full))throw new UsageError(`${dir}: no such folder`);return full}function allowOnly(parsed,command,allowed){for(let name of parsed.flags.keys())if(!allowed.includes(name))throw new UsageError(`${command} does not take --${name}`)}var errorText=error=>error instanceof Error?error.message:String(error);async function loadBuilt(dir){let pack=assemblePack(await loadPackSource(dir,{importModule:packModuleImporter()}));return readPackInput(pack.manifest,pack.files)}function formatIssues(issues){let{defects,unscripted}=splitIssues(issues),lines=[];if(defects.length>0){lines.push(`${defects.length} problem${defects.length===1?"":"s"}:`);for(let issue of defects)lines.push(` ${issue.path}: ${issue.message}`)}if(unscripted.length>0){lines.push(`${unscripted.length} unscripted abilit${unscripted.length===1?"y":"ies"} (write them in abilities/):`);for(let issue of unscripted)lines.push(` ${issue.path}: ${issue.message}`)}return lines}async function validateCommand(parsed,io){allowOnly(parsed,"validate",["allow-unscripted","publish"]);let dir=packDir(parsed,"validate"),pack=await loadBuilt(dir),publish=parsed.flags.has("publish"),draft=existsSync(join(dir,"DRAFT"));publish&&draft&&io.out(`${pack.manifest.id}: a DRAFT, never published; the publish check is skipped`);let issues=[...validatePack(pack),...publish&&!draft?publishIssues(pack.manifest):[]],{defects,unscripted}=splitIssues(issues),name=`${pack.manifest.id}@${pack.manifest.version}`;if(issues.length===0)return io.out(`${name}: valid (${pack.cards.length} cards, ${Object.keys(pack.abilities).length} abilities)`),EXIT_OK;let lines=formatIssues(issues);if(defects.length===0&&parsed.flags.has("allow-unscripted")){io.out(`${name}: valid, ${unscripted.length} abilit${unscripted.length===1?"y":"ies"} to script`);for(let line of lines)io.out(line);return EXIT_OK}io.err(`${name}: invalid`);for(let line of lines)io.err(line);return EXIT_PACK_PROBLEM}async function buildCommand(parsed,io){allowOnly(parsed,"build",["out"]);let dir=packDir(parsed,"build"),out=value(parsed,"out");if(out===void 0)throw new UsageError("build needs --out <dir>");try{let result=await buildPack(dir,resolve(out),{importModule:packModuleImporter()}),{manifest}=result;return io.out(`${manifest.id}@${manifest.version}: built ${result.zipPath}`),io.out(` ${result.zipBytes} bytes, sha256 ${result.zipSha256}`),io.out(` ${manifest.files.length} files, ${manifest.totalBytes} bytes unzipped`),io.out(` requires app ${manifest.requires.app}; DSL features: ${manifest.requires.dslFeatures.join(", ")||"none"}`),EXIT_OK}catch(error){if(!(error instanceof PackBuildError))throw error;io.err("build failed: the pack is invalid");for(let line of formatIssues(error.issues))io.err(line);return EXIT_PACK_PROBLEM}}var describeGame=game=>{let where=game.deck===SMOKE_BASE_DECK?` at ${game.campaign?`${game.campaign}/${game.node} (${game.scenario})`:game.scenario}${game.modularSet?` with ${game.modularSet}`:""}${game.difficulty?`, ${game.difficulty}`:""}`:"",head=` ${game.deck}${where} seed ${game.seed}: `;if(!game.ok)return`${head}FAILED: ${game.error??"unknown error"}`;let played=game.packCardsPlayed.length>0?`; pack cards played or revealed: ${game.packCardsPlayed.join(", ")}`:"";return`${head}${game.outcome??"ended"} in round ${game.rounds} (${game.commands} commands)${played}`};async function testCommand(parsed,io){allowOnly(parsed,"test",["games","scenario","max-commands"]);let dir=packDir(parsed,"test"),scenario=value(parsed,"scenario")??"rhino";if(!SMOKE_SCENARIOS.includes(scenario))throw new UsageError(`--scenario must be one of ${SMOKE_SCENARIOS.join(", ")}`);let games=positiveInt(parsed,"games")??3,maxCommands=positiveInt(parsed,"max-commands"),pack=await loadBuilt(dir),issues=validatePack(pack);if(issues.length>0){io.err(`${pack.manifest.id}: not tested, the pack is invalid (run mc-pack validate)`);for(let line of formatIssues(issues))io.err(line);return EXIT_PACK_PROBLEM}io.out(`${pack.manifest.id}@${pack.manifest.version}: ${games} game(s) per deck, scenario and modular set (Core scenario: ${scenario})`);let result=smokeTestPack(pack,{games,scenario,...maxCommands!==void 0?{maxCommands}:{},onGame:game=>(game.ok?io.out:io.err)(describeGame(game))});for(let note of result.notes)io.out(`note: ${note}`);let failed=result.games.filter(g=>!g.ok).length;return failed>0?(io.err(`${failed} of ${result.games.length} game(s) failed`),EXIT_PACK_PROBLEM):(io.out(`all ${result.games.length} game(s) passed`),EXIT_OK)}async function importCommand(parsed,io){allowOnly(parsed,"import-marvelcdb",["out","id","app"]);let src=packDir(parsed,"import-marvelcdb"),out=value(parsed,"out"),packId=value(parsed,"id"),app=value(parsed,"app"),report=await importMarvelCdbPack(src,{...out!==void 0?{outDir:resolve(out)}:{},...packId!==void 0?{packId}:{},...app!==void 0?{app}:{}}),text=formatImportReport(report);if(!report.normalized||report.validationIssues.length>0)return io.err(text),EXIT_PACK_PROBLEM;if(io.out(text),report.unscriptedIssues.length>0){io.out(`${report.unscriptedIssues.length} abilities to script, listed in abilities/index.ts:`);for(let issue of report.unscriptedIssues)io.out(` ${issue.path}: ${issue.message}`)}return io.out(report.outDir?`written to ${report.outDir}`:"dry run: nothing written (pass --out <dir>)"),EXIT_OK}var COMMANDS={validate:validateCommand,build:buildCommand,test:testCommand,"import-marvelcdb":importCommand};async function runCli(argv,io=consoleIo){let[command,...rest]=argv;try{if(command===void 0||command==="--help"||command==="-h"||command==="help")return io.out(USAGE),command===void 0?EXIT_USAGE:EXIT_OK;if(command==="--version"||command==="-v")return io.out("0.50.0"),EXIT_OK;let run=COMMANDS[command];if(!run)throw new UsageError(`unknown command "${command}"`);let parsed=parseArgs(rest);return parsed.flags.has("help")?(io.out(USAGE),EXIT_OK):await run(parsed,io)}catch(error){return error instanceof UsageError?(io.err(`mc-pack: ${error.message}`),io.err("run mc-pack --help for usage"),EXIT_USAGE):(io.err(`mc-pack ${command}: ${errorText(error)}`),EXIT_PACK_PROBLEM)}}process.exitCode=await runCli(process.argv.slice(2));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@champions-digital-game/mod-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "The mod SDK for Marvel Champions Digital content packs: the pack schema, the ability DSL, and the mc-pack validate, build, test and import-marvelcdb tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"card-game",
|
|
@@ -3,7 +3,7 @@ export declare const CONTENT_VERSION = "0.0.0";
|
|
|
3
3
|
* Schema version for the card data shape itself (independent of how many
|
|
4
4
|
* cards/cycles have been ingested). Bump when a breaking shape change lands.
|
|
5
5
|
*/
|
|
6
|
-
export declare const SCHEMA_VERSION = "0.
|
|
6
|
+
export declare const SCHEMA_VERSION = "0.50.0";
|
|
7
7
|
export * from "./schema/index.js";
|
|
8
8
|
export * from "./data/index.js";
|
|
9
9
|
export * from "./import/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const ENGINE_VERSION = "0.
|
|
1
|
+
export declare const ENGINE_VERSION = "0.50.0";
|
|
2
2
|
export type { PlayerId, InstanceId, ChoiceId, EncounterDeckId, FrameId, GroupId, TeamId } from "./ids.js";
|
|
3
3
|
export { playerId, instanceId, choiceId, encounterDeckId, frameId, groupId, teamId } from "./ids.js";
|
|
4
4
|
export type { GroupRef, PodNeutralArea, PodNeutralSetup, PodSetup, PodState, SharedEvent, SharedPodState, SharedResult, SharedThreatCause, } from "./pod.js";
|