editor fixes and undo/redo
This commit is contained in:
@@ -324,8 +324,8 @@ export class EditTrackState extends State<States> {
|
||||
this.ghostSegment = undefined;
|
||||
this.closestEnd = undefined;
|
||||
} else if (this.selectedSegment) {
|
||||
track.registerSegment(this.selectedSegment);
|
||||
this.selectedSegment = new StraightTrack();
|
||||
track.registerSegment(this.selectedSegment.cleanCopy());
|
||||
// this.selectedSegment = new StraightTrack();
|
||||
} else {
|
||||
this.selectedSegment = undefined;
|
||||
}
|
||||
@@ -355,16 +355,36 @@ export class EditTrackState extends State<States> {
|
||||
this.ghostSegment = undefined;
|
||||
});
|
||||
|
||||
this.currentSegment = track.lastSegment;
|
||||
// this.currentSegment = track.lastSegment;
|
||||
inputManager.onKey("z", () => {
|
||||
if (inputManager.getKeyState("Control")) {
|
||||
const segment = track.lastSegment;
|
||||
if (!segment) return;
|
||||
this.redoBuffer.push(segment);
|
||||
if (this.redoBuffer.length > 100) {
|
||||
this.redoBuffer.shift();
|
||||
}
|
||||
track.unregisterSegment(segment);
|
||||
}
|
||||
});
|
||||
inputManager.onKey("y", () => {
|
||||
if (inputManager.getKeyState("Control")) {
|
||||
const segment = this.redoBuffer.pop();
|
||||
if (!segment) return;
|
||||
track.registerSegment(segment);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO
|
||||
// Cache trains and save
|
||||
}
|
||||
redoBuffer: TrackSegment[] = [];
|
||||
override stop(): void {
|
||||
const inputManager = getContextItem<InputManager>("inputManager");
|
||||
inputManager.offKey("e");
|
||||
inputManager.offKey("w");
|
||||
inputManager.offKey("Escape");
|
||||
inputManager.offMouse("left");
|
||||
if (this.heldEvents.size > 0) {
|
||||
for (const [key, cb] of this.heldEvents) {
|
||||
if (cb) {
|
||||
|
Reference in New Issue
Block a user