Bind U to undo
This commit is contained in:
parent
854ad03523
commit
ba7e715222
@ -215,8 +215,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<button class="control-undo" type="button" title="undo">
|
<button class="control-undo" type="button" title="undo">
|
||||||
<svg class="svg-icon" viewBox="0 0 16 16"><path d="M6,5 6,2 1,7 6,12 6,9 A 10,10 60 0,1 15,12 A 10,10 90 0,0 6,5"></path></svg>
|
<svg class="svg-icon" viewBox="0 0 16 16"><path d="M6,5 6,2 1,7 6,12 6,9 A 10,10 60 0,1 15,12 A 10,10 90 0,0 6,5"></path></svg>
|
||||||
<span class="-optional-label">undo</span>
|
<span class="-optional-label">undo</span> <span class="keyhint"><kbd>u</kbd></span></button>
|
||||||
</button>
|
|
||||||
<button class="control-rewind" type="button" title="rewind">
|
<button class="control-rewind" type="button" title="rewind">
|
||||||
<svg class="svg-icon" viewBox="0 0 16 16"><path d="M1,8 7,2 7,14 z M9,8 15,2 15,14 z"></path></svg>
|
<svg class="svg-icon" viewBox="0 0 16 16"><path d="M1,8 7,2 7,14 z M9,8 15,2 15,14 z"></path></svg>
|
||||||
<span class="-optional-label">rewind</span> <span class="keyhint"><kbd>z</kbd></span></button>
|
<span class="-optional-label">rewind</span> <span class="keyhint"><kbd>z</kbd></span></button>
|
||||||
|
|||||||
54
js/main.js
54
js/main.js
@ -475,27 +475,7 @@ class Player extends PrimaryView {
|
|||||||
});
|
});
|
||||||
this.undo_button = this.root.querySelector('.control-undo');
|
this.undo_button = this.root.querySelector('.control-undo');
|
||||||
this.undo_button.addEventListener('click', ev => {
|
this.undo_button.addEventListener('click', ev => {
|
||||||
let player_cell = this.level.player.cell;
|
this.undo_last_move();
|
||||||
// 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();
|
|
||||||
ev.target.blur();
|
ev.target.blur();
|
||||||
});
|
});
|
||||||
this.rewind_button = this.root.querySelector('.control-rewind');
|
this.rewind_button = this.root.querySelector('.control-rewind');
|
||||||
@ -666,6 +646,14 @@ class Player extends PrimaryView {
|
|||||||
{
|
{
|
||||||
this.set_state('rewinding');
|
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]) {
|
if (this.key_mapping[ev.key]) {
|
||||||
@ -1514,6 +1502,30 @@ class Player extends PrimaryView {
|
|||||||
this.level.undo();
|
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
|
// Redraws every frame, unless the game isn't running
|
||||||
redraw() {
|
redraw() {
|
||||||
let update_progress;
|
let update_progress;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user