@champions-digital-game/mod-sdk 0.51.0 → 0.52.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/build.js +1 -1
- package/dist/chunks/{chunk-TUJLFNR7.js → chunk-3ZP7JFBM.js} +1 -1
- package/dist/chunks/{chunk-JR3ALXBR.js → chunk-DH3FUEOQ.js} +1 -1
- package/dist/chunks/{chunk-EKR67REN.js → chunk-GIPUMXZ5.js} +4 -4
- package/dist/chunks/{chunk-S3DCO2A6.js → chunk-KWTX5B5J.js} +1 -1
- package/dist/chunks/{chunk-GK7LCLI7.js → chunk-RRZU6F4D.js} +1 -1
- package/dist/chunks/chunk-STQU5RJP.js +1 -0
- package/dist/chunks/{chunk-Y6B5ZZGK.js → chunk-XDNO5DKC.js} +1 -1
- package/dist/import.js +1 -1
- package/dist/index.js +1 -1
- package/dist/mc-pack.js +2 -2
- package/dist/testing.js +1 -1
- package/package.json +1 -1
- package/types/cards/src/dsl/abilities.d.ts +45 -0
- package/types/cards/src/dsl/effects.d.ts +14 -0
- package/types/content/src/index.d.ts +1 -1
- package/types/engine/src/choices.d.ts +2 -0
- package/types/engine/src/effects.d.ts +39 -2
- package/types/engine/src/index.d.ts +1 -1
- package/types/engine/src/query.d.ts +7 -0
- package/types/engine/src/resolve/hand-discard.d.ts +20 -0
- package/types/engine/src/spec.d.ts +7 -0
- package/types/engine/src/state.d.ts +16 -0
- package/types/engine/src/trigger-events.d.ts +40 -1
- package/dist/chunks/chunk-6F73M3HY.js +0 -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.52.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.52.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.52.0 runs on app 0.52.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/build.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PackBuildError,assemblePack,buildPack,loadPackSource,zipPack}from"./chunks/chunk-
|
|
1
|
+
import{PackBuildError,assemblePack,buildPack,loadPackSource,zipPack}from"./chunks/chunk-RRZU6F4D.js";import"./chunks/chunk-3ZP7JFBM.js";import"./chunks/chunk-GIPUMXZ5.js";export{PackBuildError,assemblePack,buildPack,loadPackSource,zipPack};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CAMPAIGNS,ENGINE_ONLY_DSL_EXAMPLES,PACK_COVER_MAX_BYTES,PACK_HOUSE_RULE_MODES,PACK_KINDS,PACK_PERMISSION_STATUSES,PLAYABLE_CARDS,PLAYABLE_DEPS,campaignDefinitionProblems,campaignInstructionsOf,customCardPrefix,customScenarioProblems,houseRuleMayRebuild,isBaseEncounterSetId,isBaseScenarioId,isLanguageTag,isPackCoverPath,isPackId,isSafePackPath,officialCardsByPictureCode,officialFaceOfCode,opsOfKind,packAchievementProblems,packCatalogFieldProblems,packStagedPictureCodes,parsePackCardImagePath,validateCard,validateDefinition,validateEncounterSet,validateScenario,validateStarterDeck,webpSize}from"./chunk-
|
|
1
|
+
import{CAMPAIGNS,ENGINE_ONLY_DSL_EXAMPLES,PACK_COVER_MAX_BYTES,PACK_HOUSE_RULE_MODES,PACK_KINDS,PACK_PERMISSION_STATUSES,PLAYABLE_CARDS,PLAYABLE_DEPS,campaignDefinitionProblems,campaignInstructionsOf,customCardPrefix,customScenarioProblems,houseRuleMayRebuild,isBaseEncounterSetId,isBaseScenarioId,isLanguageTag,isPackCoverPath,isPackId,isSafePackPath,officialCardsByPictureCode,officialFaceOfCode,opsOfKind,packAchievementProblems,packCatalogFieldProblems,packStagedPictureCodes,parsePackCardImagePath,validateCard,validateDefinition,validateEncounterSet,validateScenario,validateStarterDeck,webpSize}from"./chunk-GIPUMXZ5.js";function dslFeatures(registry,campaigns=[]){let found=new Set;for(let definition of Object.values(registry??{}))isRecord(definition)&&collectDefinition(definition,found);for(let definition of campaigns)isRecord(definition)&&collectCampaign(definition,found);return[...found].sort()}function campaignDefinitionsOf(campaigns){return(campaigns??[]).flatMap(entry=>isRecord(entry)&&isRecord(entry.definition)?[entry.definition]:[])}function collectCampaignExprs(value,found){if(Array.isArray(value)){for(let item of value)collectCampaignExprs(item,found);return}if(isRecord(value)){typeof value.kind=="string"&&(found.add(`campaign:${value.kind}`),recordFields(`campaign:${value.kind}`,value,found));for(let child of Object.values(value))collectCampaignExprs(child,found)}}function collectCampaign(definition,found){let graph=definition.graph;isRecord(graph)&&typeof graph.kind=="string"&&found.add(`campaign-graph:${graph.kind}`);for(let field of Array.isArray(definition.logFields)?definition.logFields:[])isRecord(field)&&isRecord(field.type)&&typeof field.type.kind=="string"&&found.add(`campaign-field:${field.type.kind}`);let instructions=[];try{instructions=campaignInstructionsOf(definition)}catch{}for(let instruction of instructions){if(!isRecord(instruction))continue;collectCampaignExprs([instruction.when,instruction.whenModes],found);let step=instruction.step;isRecord(step)&&(step.kind==="inGame"?(typeof step.window=="string"&&found.add(`campaign-window:${step.window}`),visit(step.effects,"effect",found)):collectCampaignExprs(step,found))}let nodes=isRecord(graph)&&Array.isArray(graph.nodes)?graph.nodes:[];for(let node of nodes)isRecord(node)&&node.scenarioRuleSpecs!==void 0&&visit(node.scenarioRuleSpecs,"rule",found);collectCampaignExprs([definition.elimination,definition.loss],found)}var isRecord=value=>typeof value=="object"&&value!==null&&!Array.isArray(value),isStringArray=value=>Array.isArray(value)&&value.length>0&&value.every(item=>typeof item=="string"),EFFECT_SLOTS={if:["then","otherwise"],replaceTriggeringEvent:["with"],enemyScheme:["wouldPlaceThreat"]};function slotFor(kind,slot,key){return key==="effects"?"effect":key==="rules"?"rule":slot==="effect"&&kind!==void 0&&EFFECT_SLOTS[kind]?.includes(key)?"effect":"expr"}function collectDefinition(definition,found){for(let[key,value]of Object.entries(definition))value!==void 0&&(key==="trigger"?collectTrigger(value,found):key==="cost"?collectCost(value,found):key==="effects"?visit(value,"effect",found):(found.add(`ability:${key}`),recordFields(`ability:${key}`,value,found),visit(value,slotFor(void 0,"expr",key),found)))}function recordFields(prefix,value,found,skip="kind"){if(isRecord(value))for(let[field,child]of Object.entries(value))field!==skip&&child!==void 0&&found.add(`${prefix}.${field}`)}function collectTrigger(trigger,found){if(isRecord(trigger)){typeof trigger.kind=="string"&&found.add(`trigger:${trigger.kind}`);for(let[key,value]of Object.entries(trigger))if(!(key==="kind"||value===void 0)){if(key==="on"){visit(value,"expr",found,!0);continue}found.add(`trigger-option:${key}`),recordFields(`trigger-option:${key}`,value,found),visit(value,slotFor(void 0,"expr",key),found)}}}function collectCost(cost,found){if(isRecord(cost)){for(let[key,value]of Object.entries(cost))if(value!==void 0)if(found.add(`cost:${key}`),key==="either"&&Array.isArray(value))for(let branch of value)collectCost(branch,found);else if(key==="conditional"&&isRecord(value)){collectCost(value.then,found),collectCost(value.else,found);let{then:_then,else:_else,...rest}=value;recordFields("cost:conditional",rest,found),visit(rest,"expr",found)}else recordFields(`cost:${key}`,value,found),visit(value,"expr",found)}}var TARGET_QUERY_FIELDS=["categories","inScenarioPlayArea","controller","engagedWith","trait","withoutTrait","anyTrait","withKeyword","withoutKeyword","keywordNotFromSelf","anyOf","not","cardTypeIs","playerSideScheme","accusation","chosenVillain","name","printedId","hostOfSelf","host","hasAttachment","canHaveAttached","canAttachTo","canAttachToCategory","canEnterPlay","canEnterPlayControllerStated","canFlip","facedown","flipped","starIcon","boostCard","printsBoostAbility","unique","printedResource","anyPrintedResource","printedResourceNamed","owner","aspect","anyAspect","exhausted","hasThreat","hasCounter","hasAccelerationToken","damaged","hasStatus","hasAnyStatus","canTakeStatus","self","maxPrintedHp","statCompare","remainingHpCompare","maxPrintedCost","minPrintedCost","attackableBy","canTakeAttackInProgress","canAttackOneOf","excludeSlots","excluding","inSlot","controlledBy","extensionOf","actsFor","engagedWithPlayer","inPlayAreaOf","signatureSideScheme","identitySetOf","nemesisMinionOf","obligationOf","nemesisSideSchemeOf","nemesisSetOf","sharesTraitWith","sharesTraitWithHeroOf","sharesTitleWith","otherFaceOf","encounterSetOf","scenarioSpecific","inEncounterSet","inCampaignLogField","titled","identitySetTitled","sameClassificationAs","classification","printedForm","abilityTiming","printsAbility","hasTaggedAbility"],SHARED_QUERY_FIELDS=new Set(["name","trait","aspect","self","owner","host","unique","exhausted","facedown","flipped","damaged","controller","not","anyOf","inSlot","excluding","titled","anyTrait","classification","printedForm"]),QUERY_FIELD_SET=new Set(TARGET_QUERY_FIELDS);function recordQueryFields(value,found){if(typeof value.kind=="string")return;let own=Object.keys(value).filter(key=>value[key]!==void 0&&QUERY_FIELD_SET.has(key));if(own.some(key=>!SHARED_QUERY_FIELDS.has(key)))for(let key of own)found.add(`query:${key}`)}function visit(value,slot,found,isPattern=!1){if(Array.isArray(value)){for(let item of value)visit(item,slot,found,isPattern);return}if(!isRecord(value))return;let kind=typeof value.kind=="string"?value.kind:void 0;recordQueryFields(value,found),kind!==void 0&&(found.add(`${slot}:${kind}`),recordFields(`${slot}:${kind}`,value,found));let on=value.on,hearsEvents=(isPattern||kind===void 0)&&(typeof on=="string"||isStringArray(on));if(hearsEvents)for(let event of typeof on=="string"?[on]:on)found.add(`event:${event}`);for(let[childKey,child]of Object.entries(value))hearsEvents&&childKey==="on"||visit(child,slotFor(kind,slot,childKey),found,childKey==="anyOf")}var SUPPORTED_DSL_FEATURES=dslFeatures({...PLAYABLE_DEPS.abilities,...ENGINE_ONLY_DSL_EXAMPLES},Object.values(CAMPAIGNS));var PACK_ABILITY_ID=/^x\.[a-z0-9]+(?:-[a-z0-9]+)*\.\d+[a-z]?\.[a-z0-9-]+$/;function definePackAbilities(definitions){let problems=[];for(let[id,definition]of Object.entries(definitions)){PACK_ABILITY_ID.test(id)||problems.push(`${id}: not an x.<pack-id>.<card number>.<slug> ability id`);for(let problem of validateDefinition(definition))problems.push(`${id}: ${problem}`)}if(problems.length>0)throw new Error(`invalid pack ability definitions:
|
|
2
2
|
${problems.join(`
|
|
3
3
|
`)}`);return definitions}var K=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),rotr=(x,n)=>x>>>n|x<<32-n;function sha256Hex(data){let h=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),length=data.length,padded=new Uint8Array(length+9+63>>6<<6);padded.set(data),padded[length]=128;let view=new DataView(padded.buffer);view.setUint32(padded.length-8,Math.floor(length/536870912),!1),view.setUint32(padded.length-4,length<<3>>>0,!1);let w=new Uint32Array(64);for(let offset=0;offset<padded.length;offset+=64){for(let i=0;i<16;i++)w[i]=view.getUint32(offset+i*4,!1);for(let i=16;i<64;i++){let s0=rotr(w[i-15],7)^rotr(w[i-15],18)^w[i-15]>>>3,s1=rotr(w[i-2],17)^rotr(w[i-2],19)^w[i-2]>>>10;w[i]=w[i-16]+s0+w[i-7]+s1|0}let[a,b,c,d,e,f,g,hh]=[h[0],h[1],h[2],h[3],h[4],h[5],h[6],h[7]];for(let i=0;i<64;i++){let s1=rotr(e,6)^rotr(e,11)^rotr(e,25),ch=e&f^~e&g,t1=hh+s1+ch+K[i]+w[i]|0,s0=rotr(a,2)^rotr(a,13)^rotr(a,22),maj=a&b^a&c^b&c,t2=s0+maj|0;hh=g,g=f,f=e,e=d+t1|0,d=c,c=b,b=a,a=t1+t2|0}h[0]=h[0]+a|0,h[1]=h[1]+b|0,h[2]=h[2]+c|0,h[3]=h[3]+d|0,h[4]=h[4]+e|0,h[5]=h[5]+f|0,h[6]=h[6]+g|0,h[7]=h[7]+hh|0}return[...h].map(n=>(n>>>0).toString(16).padStart(8,"0")).join("")}var isObj=value=>typeof value=="object"&&value!==null&&!Array.isArray(value),text=value=>typeof value=="string"&&value.trim()!=="";function isPlainJson(value){if(value===null||typeof value=="string"||typeof value=="boolean")return!0;if(typeof value=="number")return Number.isFinite(value);if(Array.isArray(value))return value.every(isPlainJson);if(isObj(value)){let proto=Object.getPrototypeOf(value);return(proto===Object.prototype||proto===null)&&Object.values(value).every(isPlainJson)}return!1}var LIMITED_OPS={spend:"spending a currency (a market or shop) is not available to a pack campaign yet",composeVillain:"choosing a villain between games is not available to a pack campaign yet",composeEncounterSets:"composing encounter sets between games is not available to a pack campaign yet",setAsideCards:"setting cards aside between games is not available to a pack campaign yet"};function checkPackCampaigns(input){let{add}=input,ids=new Set,requiredScenarioIds=new Set(input.required.scenarios.map(scenario=>scenario.id)),requiredSetIds=new Set(input.required.encounterSets.map(set=>set.id));for(let[index,entry]of input.campaigns.entries()){if(!isObj(entry)){add(`campaigns[${index}]`,"must be a campaign object");continue}let id=typeof entry.id=="string"?entry.id:"",at=`campaigns/${id||index}`;(input.packId===""||!id.startsWith(`${input.packId}-`)||id.length===input.packId.length+1)&&add(at,`campaign id must be "${input.packId}-<name>"`),Object.hasOwn(CAMPAIGNS,id)&&add(at,"campaign id is a base-game campaign id (the base game always wins)"),ids.has(id)&&add(at,"campaign id is used by two campaigns"),ids.add(id);for(let field of["name","description"])text(entry[field])||add(at,`${field} must be a non-empty string`);entry.tagline!==void 0&&!text(entry.tagline)&&add(at,"tagline must be a non-empty string"),text(entry.version)||add(at,"version must be a non-empty string");let definition=entry.definition;if(!isObj(definition)){add(at,"definition must be a campaign definition object");continue}isPlainJson(definition)||add(at,"definition must be plain JSON (no undefined, functions or NaN)"),definition.campaignId!==id&&add(at,`definition.campaignId must equal the campaign's id "${id}"`),definition.version!==entry.version&&add(at,"definition.version must equal the campaign's version");let problems=campaignDefinitionProblems(definition,{isCardId:input.isCardId,isScenarioId:scenarioId=>input.packScenarioIds.has(scenarioId)||isBaseScenarioId(scenarioId)||requiredScenarioIds.has(scenarioId)});for(let problem of problems)add(at,problem);if(!isReadable(definition))continue;let readable=definition;try{checkLimits(at,readable,add),checkRecord(at,entry,readable,input,requiredSetIds),checkStory(at,entry,readable,add)}catch(error){add(at,`could not be checked: ${error instanceof Error?error.message:String(error)}`)}if(entry.art!==void 0){let cover=isObj(entry.art)?entry.art.cover:void 0;!isObj(entry.art)||cover!==void 0&&(typeof cover!="string"||!isSafePackPath(cover))?add(at,"art must be { cover?: a pack file path }"):typeof cover=="string"&&!input.listedFiles.has(cover)&&add(at,`art.cover "${cover}" is not a listed file`)}}}function isReadable(definition){let graph=definition.graph,listOfObjects=value=>Array.isArray(value)&&value.every(isObj);return isObj(graph)&&listOfObjects(graph.nodes)&&graph.nodes.every(node=>Array.isArray(node.setup)&&Array.isArray(node.victory))&&listOfObjects(definition.logFields)}function checkLimits(at,definition,add){let graph=definition.graph;graph.kind!=="linear"&&add(at,`the graph must be "linear" (a "${String(graph.kind)}" graph is not available yet)`);for(let node of graph.nodes){let name=`node "${String(node.id)}"`;node.scenario?.kind!=="fixed"&&add(at,`${name}: the scenario must be "fixed" (a named scenario record)`),node.composition!==void 0&&node.composition.length>0&&add(at,`${name}: composition (choosing a villain or sets between games) is not available yet`),node.requiredModularSetIds!==void 0&&node.requiredModularSetIds.length>0&&add(at,`${name}: requiredModularSetIds is not available yet`)}definition.elimination!==void 0&&add(at,"an elimination policy is not available yet (it is part of an expert campaign)");let everything=[definition.everyNodeSetup,definition.everyNodeVictory,definition.conditionalInstructions,definition.logUpgrades,definition.loss,graph.nodes];for(let[kind,message]of Object.entries(LIMITED_OPS))opsOfKind(everything,kind).length>0&&add(at,message);opsOfKind(everything,"perSeatSet").length>0&&add(at,"a per-seat set (an expert campaign's numbered sets) is not available yet"),JSON.stringify(everything).includes('"unitCostExactly"')&&add(at,"a Unit Cost filter (a market) is not available yet"),JSON.stringify(everything).includes('"expertCampaign"')&&add(at,"an instruction gated by expertCampaign is not available yet (no expert campaign rules)"),definition.logFields.some(field=>field.whenModes!==void 0)&&add(at,"a log field gated by modes (whenModes) is not available yet")}function checkRecord(at,entry,definition,input,requiredSetIds){let{add}=input,record=entry.record;if(!isObj(record)){add(at,"record must be { scenarioIds, campaignSetIds }");return}let nodeScenarios=definition.graph.nodes.flatMap(node=>node.scenario?.kind==="fixed"?[String(node.scenario.scenarioId)]:[]),listed=record.scenarioIds;!Array.isArray(listed)||listed.some(scenarioId=>typeof scenarioId!="string")?add(at,"record.scenarioIds must be a list of scenario ids"):listed.join(`
|
|
4
4
|
`)!==nodeScenarios.join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{assemblePack}from"./chunk-
|
|
1
|
+
import{assemblePack}from"./chunk-RRZU6F4D.js";import{abilityRefsOf,readPackInput,splitIssues,validatePack}from"./chunk-3ZP7JFBM.js";import{PACK_KINDS,isLanguageTag,isPackId,packCardImagePath}from"./chunk-GIPUMXZ5.js";import{copyFileSync,existsSync,mkdirSync,readFileSync,readdirSync,rmSync,writeFileSync}from"node:fs";import{basename,dirname,join}from"node:path";var isObj=value=>typeof value=="object"&&value!==null&&!Array.isArray(value),str=value=>typeof value=="string"&&value!==""?value:void 0,normalizer;function registerMarvelCdbNormalizer(normalize){normalizer=normalize}async function loadNormalizer(){if(normalizer)return normalizer;let module=await import(new URL("../../content/scripts/marvelcdb/normalize.ts",import.meta.url).href);if(typeof module.normalizePack!="function")throw new Error("the content package's normalizePack is missing");return normalizer=module.normalizePack}var kebab=text=>text.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),KIND_ALIASES=Object.fromEntries(PACK_KINDS.flatMap(kind=>[[kind,kind],[`${kind}_pack`,kind]]));function dataFileOf(srcDir,modId){let named=join(srcDir,`${modId}.json`);if(existsSync(named))return named;let others=readdirSync(srcDir).filter(name=>name.endsWith(".json")&&name!=="mod.json");if(others.length!==1)throw new Error(`${srcDir}: expected ${modId}.json (or one .json besides mod.json)`);return join(srcDir,others[0])}var tailOf=code=>{let match=/^(.*\d)([a-z])$/.exec(code);return match?{key:match[1],letter:match[2]}:{key:code,letter:""}};function planCodes(records,packId){let order=[],visit=record2=>{let code=str(record2.code);if(code===void 0)throw new Error("a card record has no code");order.push(code),isObj(record2.linked_card)&&visit(record2.linked_card)};records.forEach(visit);let numbers=new Map,out=new Map;for(let code of order){if(out.has(code))throw new Error(`card code ${code} appears twice`);let{key,letter}=tailOf(code);numbers.has(key)||numbers.set(key,numbers.size+1);let n=numbers.get(key);out.set(code,`x.${packId}.${String(n).padStart(numbers.size>99?3:2,"0")}${letter}`)}return out}function planSets(records,packId){let all=records.flatMap(r=>isObj(r.linked_card)?[r,r.linked_card]:[r]),heroSet=all.map(r=>r.type_code==="hero"?str(r.card_set_code):void 0).find(Boolean),out=new Map;for(let record2 of all){let set=str(record2.card_set_code);if(!(set===void 0||out.has(set)))if(set===heroSet)out.set(set,packId);else{let rest=heroSet!==void 0&&set.startsWith(`${heroSet}_`)?set.slice(heroSet.length+1):set;out.set(set,`${packId}-${kebab(rest)}`)}}let finals=[...out.values()];if(new Set(finals).size!==finals.length)throw new Error("two source sets map to the same encounter set id");return out}var escapeRegExp=text=>text.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function makeRewriter(map){let keys=[...map.keys()].sort((a,b)=>b.length-a.length).map(escapeRegExp),pattern=new RegExp(`(?<![A-Za-z0-9_])(?:${keys.join("|")})(?![A-Za-z0-9_])`,"g"),walk=node=>typeof node=="string"?node.replace(pattern,hit=>map.get(hit)??hit):Array.isArray(node)?node.map(walk):isObj(node)?Object.fromEntries(Object.entries(node).filter(([key])=>key!=="images"&&key!=="image").map(([key,child])=>[key,walk(child)])):node;return walk}var collectorOf=finalCode=>(/\.(\d+[a-z]?)$/.exec(finalCode)?.[1]??finalCode).replace(/^0+(?=\d)/,"").toUpperCase();function toSourceCodes(curation,finalToSource){let source=code=>finalToSource.get(code)??code,pattern=new RegExp(`^(${[...finalToSource.keys()].map(escapeRegExp).join("|")})(?=\\.|$)`),fixKeys=record2=>isObj(record2)?Object.fromEntries(Object.entries(record2).map(([key,value])=>[key.replace(pattern,m=>source(m)),value])):record2,fixCode=list=>Array.isArray(list)?list.map(e=>isObj(e)&&typeof e.code=="string"?{...e,code:source(e.code)}:e):list,out={...curation};for(let key of["corrections","errata","ignoredRecords"])key in out&&(out[key]=fixCode(out[key]));for(let key of["cardNotes","scriptingNotes"])key in out&&(out[key]=fixKeys(out[key]));return out}function markFlipSides(records,notes,codes){let IDENTITY_TYPES=new Set(["hero","alter_ego","villain","main_scheme"]);return records.map(record2=>{let back=record2.linked_card,type=record2.type_code;if(!isObj(back)||back.hidden!==void 0||IDENTITY_TYPES.has(type)||IDENTITY_TYPES.has(back.type_code))return record2;let code=str(back.code)??"?";return notes.push(`marked ${codes.get(code)??code} as the hidden flip side of ${str(record2.name)??"?"}, as the API does`),{...record2,linked_card:{...back,hidden:!0}}})}function dashCostCorrections(records,finalOf,skip){let found=[];for(let record2 of records){let code=str(record2.code);if(code===void 0||skip.has(code))continue;let noCost=record2.cost===void 0||record2.cost===null;if(record2.permanent!==!0||!noCost||record2.cost_per_hero===!0||record2.type_code!=="upgrade"&&record2.type_code!=="support")continue;let what=`${String(record2.name)}: a permanent ${String(record2.type_code)} with no cost in the source reads as a printed dash cost (cannot be played, enters play through its own text)`;found.push({correction:{code,reason:what,evidence:"pack importer: permanent card, no cost in the MarvelCDB-shaped record; check the card image",specialCost:"dash"},auto:{code,finalCode:finalOf(code),what}})}return found}var APPENDED=new Set(["corrections","errata","scenarios","starterDecks","separateDecks","ignoredRecords"]);function mergeCuration(base,extra){let out={...base};for(let[key,value]of Object.entries(extra)){let current=out[key];APPENDED.has(key)&&Array.isArray(current)&&Array.isArray(value)?out[key]=[...current,...value]:isObj(current)&&isObj(value)?out[key]={...current,...value}:out[key]=value}return out}function semverOf(text){let match=/^\s*v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?![\d.])/.exec(text);return match?`${match[1]}.${match[2]??"0"}.${match[3]??"0"}`:void 0}function readMod(srcDir){let mod=JSON.parse(readFileSync(join(srcDir,"mod.json"),"utf8"));if(!isObj(mod)||!str(mod.id)||!str(mod.name)||!str(mod.kind)||!str(mod.author))throw new Error(`${join(srcDir,"mod.json")}: needs id, name, kind and author`);return mod}var subDirs=dir=>existsSync(dir)?readdirSync(dir,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name):[];function mapPictures(srcDir,codes){let copies=[],missing=[],unmatched=[],languages=subDirs(join(srcDir,"images")).sort();for(let lang of languages){let dir=join(srcDir,"images",lang),present=new Set(readdirSync(dir));for(let[source,final]of codes)present.delete(`${source}.webp`)?copies.push({from:join(dir,`${source}.webp`),to:packCardImagePath(lang,final)}):missing.push(`${lang}/${source}`);unmatched.push(...[...present].sort().map(name=>`images/${lang}/${name}`))}let altArt={};for(let lang of subDirs(join(srcDir,"alt-art")).sort()){let dir=join(srcDir,"alt-art",lang);for(let name of readdirSync(dir).sort()){let match=/^(.+)\.webp$/.exec(name);if(!match){unmatched.push(`alt-art/${lang}/${name}`);continue}let stem=match[1],own=codes.get(stem.replace(/-alt$/,"")),code=own!==void 0&&stem.endsWith("-alt")?own:stem,to=`alt-art/${lang}/${code}.webp`;(altArt[lang]??={})[code]=to,copies.push({from:join(dir,name),to})}}return{copies,languages,missing,unmatched,altArt}}var bytesOf=path=>new Uint8Array(readFileSync(path));function creditsMarkdown(mod,packId,languages,base){let translators=Object.entries(mod.languages??{}).filter(([lang,who])=>lang!=="base"&&who!=="author");return["# Credits","",`${mod.name} (\`${packId}\`) is a fan-made pack by ${mod.author}.`,"",`- Card design and art direction: ${mod.author}.`,...mod.template?[`- Card template: ${mod.template}.`]:[],...translators.map(([lang,who])=>`- Translation and layout (${lang}): ${who}.`),`- Pictures: ${languages.join(", ")} (base language ${base}).`,...mod.version?[`- Source version: ${mod.version}.`]:[],"","The card data was converted from MarvelCDB-shaped records with the mod SDK's `importMarvelCdbPack`.","Character art is Marvel comics art, as used by each author.","","Marvel Champions: The Card Game is the property of Fantasy Flight Games and Marvel.",""].join(`
|
|
2
2
|
`)}function permissionMarkdown(mod,granted){let p=mod.permission??{};return["# Permission","",granted?`${mod.author}, the author of ${mod.name}, gave permission for this pack to be distributed through the mod store.`:`**Permission is not recorded as granted for this pack (status: ${p.status??"none"}). Do not publish it.**`,"",`- Status: ${p.status??"not recorded"}`,`- Scope: ${p.scope??"not recorded"}`,`- Date: ${p.date??"not recorded"}`,"","Recorded in the pack's draft `mod.json`. The registry review asks for the evidence (a link or a quoted message).",""].join(`
|
|
3
3
|
`)}function abilityFacesOf(card){let faces=[],walk=(node,title)=>{if(Array.isArray(node))return void node.forEach(n=>walk(n,title));if(!isObj(node))return;let ids=Array.isArray(node.abilities)?node.abilities.flatMap(a=>isObj(a)&&typeof a.id=="string"?[a.id]:[]):[],here=str(node.faceName)??str(node.name)??title;if(ids.length>0){let text=isObj(node.text)?str(node.text.printed)??"":"";faces.push({title:here,text,ids})}for(let[key,child]of Object.entries(node))key!=="abilities"&&key!=="text"&&walk(child,here)};return walk(card,card.name),faces}function abilitiesStub(cards,packName){let ids=[],blocks=[];for(let card of cards)for(let face of abilityFacesOf(card)){let fresh=face.ids.filter(id=>!ids.includes(id));if(fresh.length===0)continue;ids.push(...fresh);let text=face.text.split(`
|
|
4
4
|
`).map(line=>` // ${line}`);blocks.push([` // ${String(card.id)} ${face.title} (${card.type})`,...text,...fresh.map(id=>` // ${id}`)].join(`
|