Bind U to undo

This commit is contained in:
Eevee (Evelyn Woods) committed 2021-03-13 19:02:11 -07:00
1 parent 854ad03523
commit ba7e715222
2 files changed
+34 -23

No files matched your search

+33 -21
View File
@@ -475,27 +475,7 @@ class Player extends PrimaryView {
});
this.undo_button = this.root.querySelector('.control-undo');
this.undo_button.addEventListener('click', ev => {
let player_cell = this.level.player.cell;
// Keep undoing until (a) we're on another cell and (b) we're not sliding, i.e. we're
// about to make a conscious move. Note that this means undoing all the way through
// force floors, even if you could override them!
let moved = false;
while (this.level.has_undo() &&
! (moved && this.level.player.slide_mode === null))
{
this.undo();
if (player_cell !== this.level.player.cell) {
moved = true;
}
}
// TODO set back to waiting if we hit the start of the level? but
// the stack trims itself so how do we know that
if (this.state === 'stopped') {
// Be sure to undo any success or failure
this.set_state('playing');
}
this.update_ui();
this._redraw();
this.undo_last_move();
ev.target.blur();
});
this.rewind_button = this.root.querySelector('.control-rewind');
@@ -666,6 +646,14 @@ class Player extends PrimaryView {
{
this.set_state('rewinding');
}
return;
}
if (ev.key === 'u') {
if (this.level.has_undo() &&
(this.state === 'stopped' || this.state === 'playing' || this.state === 'paused'))
{
this.undo_last_move();
}
}
if (this.key_mapping[ev.key]) {
@@ -1514,6 +1502,30 @@ class Player extends PrimaryView {
this.level.undo();
}
undo_last_move() {
let player_cell = this.level.player.cell;
// Keep undoing until (a) we're on another cell and (b) we're not sliding, i.e. we're
// about to make a conscious move. Note that this means undoing all the way through
// force floors, even if you could override them!
let moved = false;
while (this.level.has_undo() &&
! (moved && this.level.player.slide_mode === null))
{
this.undo();
if (player_cell !== this.level.player.cell) {
moved = true;
}
}
// TODO set back to waiting if we hit the start of the level? but
// the stack trims itself so how do we know that
if (this.state === 'stopped') {
// Be sure to undo any success or failure
this.set_state('playing');
}
this.update_ui();
this._redraw();
}
// Redraws every frame, unless the game isn't running
redraw() {
let update_progress;