Two compilers that walk a graph the same way walk it through one emitter (#85)
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:
1 parent
bf0be66c9d
commit
d3563897d8
16 files changed
+376
-379
No files matched your search
@@ -17,7 +17,7 @@ import {
|
||||
variableDef,
|
||||
} from '../properties/PropertySchema';
|
||||
import { type Removed, removeFirst, restoreAt } from '../util/list';
|
||||
import { type Command, CommandError } from './Command';
|
||||
import { type Command, CommandError, RenameCommand } from './Command';
|
||||
import { renameVariablePorts } from './portCommands';
|
||||
import { requireVariableOwner } from './require';
|
||||
|
||||
@@ -117,26 +117,16 @@ export class RemoveVariableCommand implements Command {
|
||||
}
|
||||
|
||||
/** Renames everywhere: definition, default, instance overrides and the graph nodes referring to it. */
|
||||
export class RenameVariableCommand implements Command {
|
||||
readonly label: string;
|
||||
|
||||
export class RenameVariableCommand extends RenameCommand {
|
||||
constructor(
|
||||
private readonly assetId: string,
|
||||
private readonly from: string,
|
||||
private readonly to: string,
|
||||
from: string,
|
||||
to: string,
|
||||
) {
|
||||
this.label = `Rename variable ${from}`;
|
||||
super(`Rename variable ${from}`, from, to);
|
||||
}
|
||||
|
||||
execute(project: Project): void {
|
||||
this.rename(project, this.from, this.to);
|
||||
}
|
||||
|
||||
undo(project: Project): void {
|
||||
this.rename(project, this.to, this.from);
|
||||
}
|
||||
|
||||
private rename(project: Project, from: string, to: string): void {
|
||||
protected rename(project: Project, from: string, to: string): void {
|
||||
const asset = requireVariableOwner(project, this.assetId);
|
||||
if (from === to) return;
|
||||
if (!isValidVariableName(to)) throw new CommandError(INVALID_NAME);
|
||||
@@ -316,27 +306,17 @@ export class RemoveStructFieldCommand implements Command {
|
||||
}
|
||||
}
|
||||
|
||||
export class RenameStructFieldCommand implements Command {
|
||||
readonly label: string;
|
||||
|
||||
export class RenameStructFieldCommand extends RenameCommand {
|
||||
constructor(
|
||||
private readonly assetId: string,
|
||||
private readonly key: string,
|
||||
private readonly from: string,
|
||||
private readonly to: string,
|
||||
from: string,
|
||||
to: string,
|
||||
) {
|
||||
this.label = `Rename field ${from}`;
|
||||
super(`Rename field ${from}`, from, to);
|
||||
}
|
||||
|
||||
execute(project: Project): void {
|
||||
this.rename(project, this.from, this.to);
|
||||
}
|
||||
|
||||
undo(project: Project): void {
|
||||
this.rename(project, this.to, this.from);
|
||||
}
|
||||
|
||||
private rename(project: Project, from: string, to: string): void {
|
||||
protected rename(project: Project, from: string, to: string): void {
|
||||
const owner = requireFieldOwner(project, this.assetId, this.key);
|
||||
if (from === to) return;
|
||||
if (!isValidFieldName(to)) throw new CommandError(INVALID_FIELD);
|
||||
|
||||
Reference in new issue
Block a user