Use new playbill updates

This commit is contained in:
Endeavorance 2025-03-21 16:40:47 -04:00
parent c1f3c6cade
commit f7f861a1cb
8 changed files with 81 additions and 210 deletions

View file

@ -1,14 +1,5 @@
import path from "node:path";
import {
type Ability,
type Blueprint,
type Item,
type Method,
Playbill,
type Resource,
type Rule,
type Species,
} from "@proscenium/playbill";
import { type AnyPlaybillComponent, Playbill } from "@proscenium/playbill";
import { Glob } from "bun";
import z from "zod";
import { loadYAMLFileOrFail } from "#util";
@ -33,11 +24,7 @@ const BindingSchema = z.object({
terms: z.record(z.string(), z.string()).default({}),
});
type Binding = z.infer<typeof BindingSchema>;
export interface BoundPlaybill {
_raw: Binding;
// File information
bindingFilePath: string;
bindingFileDirname: string;
@ -93,7 +80,12 @@ export async function loadFromBinding(
const fileGlobs = binding.files;
const bindingFileDirname = path.dirname(resolvedBindingPath);
const playbill = new Playbill();
const playbill = new Playbill(
binding.name,
binding.author,
binding.description,
binding.version,
);
// If this is extending another binding, load that first
for (const includePath of binding.include) {
@ -151,86 +143,15 @@ export async function loadFromBinding(
await Promise.all(fileLoadPromises);
// Decorate the playbill with the binding metadata
playbill.name = binding.name;
playbill.author = binding.author ?? "Anonymous";
playbill.version = binding.version;
playbill.description = binding.description ?? "";
const abilities: Ability[] = [];
const bluprints: Blueprint[] = [];
const methods: Method[] = [];
const species: Species[] = [];
const items: Item[] = [];
const rules: Rule[] = [];
const resources: Resource[] = [];
// Aggregate all components before adding to playbill to allow for
// ensuring components are added in a valid order
// Aggregate all loaded components
const loadedComponents: AnyPlaybillComponent[] = [];
for (const file of componentFiles) {
// Load components from the file into the playbill
for (const component of file.components) {
switch (component.type) {
case "ability":
abilities.push(component.component);
break;
case "blueprint":
bluprints.push(component.component);
break;
case "method":
methods.push(component.component);
break;
case "species":
species.push(component.component);
break;
case "item":
items.push(component.component);
break;
case "rule":
rules.push(component.component);
break;
case "resource":
resources.push(component.component);
break;
default:
throw new Error("Unknown component type");
}
}
loadedComponents.push(...file.components);
}
// Add resources first
for (const resource of resources) {
playbill.addResource(resource);
}
// Add abilities before methods, species, and blueprints
for (const ability of abilities) {
playbill.addAbility(ability);
}
// Add species before blueprints
for (const specie of species) {
playbill.addSpecies(specie);
}
// Add methods after abilities
for (const method of methods) {
playbill.addMethod(method);
}
// Add items
for (const item of items) {
playbill.addItem(item);
}
// Add blueprints after methods, species, items, and abilities
for (const blueprint of bluprints) {
playbill.addBlueprint(blueprint);
}
// Add rules
for (const rule of rules) {
playbill.addRule(rule);
}
// Add all components to the playbill
// (This method ensures proper addition order maintain correctness)
playbill.addManyComponents(loadedComponents);
// Add all definitions
for (const [term, definition] of Object.entries(binding.terms)) {
@ -238,7 +159,6 @@ export async function loadFromBinding(
}
return {
_raw: binding,
bindingFilePath: bindingPath,
bindingFileDirname,
files: filePathsWithoutBindingFile,