import type { Project } from '../model/Project'; import type { Command } from './Command'; export class RenameProjectCommand implements Command { readonly label = 'Rename project'; private previous = ''; constructor(private readonly name: string) {} execute(project: Project): void { this.previous = project.name; project.name = this.name; } undo(project: Project): void { project.name = this.previous; } } /** "Sprite", "Sprite 2", "Sprite 3" … – the first name not yet used by an asset. */ export function nextAssetName(project: Project, base: string): string { const taken = new Set(project.assets.map((a) => a.name)); if (!taken.has(base)) return base; for (let i = 2; ; i++) { const candidate = `${base} ${i}`; if (!taken.has(candidate)) return candidate; } }