Two compilers that walk a graph the same way walk it through one emitter (#85)
game-maker / suite (push) Failing after 2m22s
game-maker / gate (push) Successful in 2m53s

Refactoring round two: the particle and shader compilers share emitGraph.ts (cycle detection,
duplicate names, emit order) and keep only their rules. FontLibrary and TextureLibrary sit on
FileLibrary (base URL, loading/failed bookkeeping, listeners); SoundLibrary keeps its own
contract. The three Create*Command share ImportFileCommand, the three renames share
RenameCommand - class names stay. bandBounds() in framing.ts and portNameField() in
portSection.ts replace in-file clones, and three comments that told history now state the rule.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5 committed 2026-09-16 19:28:28 +02:00
1 parent bf0be66c9d
commit d3563897d8
16 files changed
+376 -379

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
/**
* Uploaded files the view draws with, keyed by file name. Nothing is evicted: file names are
* content addressed, so a loaded file can never go stale. A miss is not an error – the subclass
* starts the load and reports "not yet", and `onChange` fires when the file lands.
*/
export abstract class FileLibrary<T> {
private base: string;
private readonly loading = new Set<string>();
/** Never retried, so one broken reference cannot spam the network. */
private readonly failed = new Set<string>();
private readonly listeners = new Set<() => void>();
constructor(
base: string,
private readonly tag: string,
) {
this.base = base;
}
/** Where the files are served from. Set once at start-up, before anything draws. */
configure(base: string): void {
this.base = base.replace(/\/+$/, '');
}
/** Runs `fn` whenever a file has arrived; returns the unsubscribe. */
onChange(fn: () => void): () => void {
this.listeners.add(fn);
return () => this.listeners.delete(fn);
}
protected abstract fetchFile(url: string, file: string): Promise<T>;
/** Keeps what arrived; the listeners run right after. */
protected abstract keep(file: string, loaded: T): void;
protected startLoading(file: string): void {
if (this.loading.has(file) || this.failed.has(file)) return;
this.loading.add(file);
void this.fetchFile(`${this.base}/${file}`, file).then(
(loaded) => {
this.loading.delete(file);
this.keep(file, loaded);
for (const listener of this.listeners) listener();
},
(error: unknown) => {
this.loading.delete(file);
this.failed.add(file);
console.error(`[${this.tag}] cannot load ${file}`, error);
},
);
}
}