41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { collisionLayersOf } from '../model/collisionLayers';
|
||
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;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* The named collision layers of the project (#152). Colliders name a layer by number, so removing
|
||
* one shifts what every collider below it points at – which is why the dialog only ever hands over
|
||
* a whole list, and why the list is read through `collisionLayersOf` here as well.
|
||
*/
|
||
export class SetCollisionLayersCommand implements Command {
|
||
readonly label = 'Collision layers';
|
||
private previous: string[] = [];
|
||
|
||
constructor(private readonly names: readonly string[]) {}
|
||
|
||
execute(project: Project): void {
|
||
this.previous = project.collisionLayers;
|
||
project.collisionLayers = collisionLayersOf({ collisionLayers: this.names });
|
||
}
|
||
|
||
undo(project: Project): void {
|
||
project.collisionLayers = this.previous;
|
||
}
|
||
}
|