From 8439ce87ac2a6ad433b916c7c1dc5ba720afa895 Mon Sep 17 00:00:00 2001 From: yukirij Date: Thu, 5 Sep 2024 10:51:58 -0700 Subject: [PATCH] Add undo button to practice. --- www/js/game.js | 2 +- www/js/interface.js | 9 +++++++++ www/js/language.js | 1 + www/js/scene.js | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/www/js/game.js b/www/js/game.js index 6127027..7fa51dc 100644 --- a/www/js/game.js +++ b/www/js/game.js @@ -526,7 +526,7 @@ GAME.Game = class { } if(pieces_blocking == 1 && stride > 0) { - // Apply blocking to last . + // Apply blocking to last piece tile. for(let idist = 1; idist < dist; idist++) { if(this.board.tiles[tiles[tiles.length - idist].tile].piece !== null) { tiles[tiles.length - idist].block = dir_mask; diff --git a/www/js/interface.js b/www/js/interface.js index 0f487fb..8aec5d1 100644 --- a/www/js/interface.js +++ b/www/js/interface.js @@ -1005,6 +1005,15 @@ const INTERFACE = { INTERFACE.replay_jump(INTERFACE_DATA.history.length, false); }, + undo() { + INTERFACE_DATA.auto_mode = null; + if(INTERFACE_DATA.history.length > 0) { + GAME.init(); + INTERFACE_DATA.history.pop(); + INTERFACE.replay_jump(INTERFACE_DATA.history.length, false); + } + }, + message(code, data) { if(data === null) { return; } diff --git a/www/js/language.js b/www/js/language.js index 9032ad2..2e7a775 100644 --- a/www/js/language.js +++ b/www/js/language.js @@ -47,6 +47,7 @@ LANGUAGE.Terms = { back: new LANGUAGE.Term( "Back", "戻る" ), resign: new LANGUAGE.Term( "Resign", "投了" ), confirm: new LANGUAGE.Term( "Confirm", "確認" ), + undo: new LANGUAGE.Term( "Undo", "待った" ), reset: new LANGUAGE.Term( "Reset", "リセット" ), auto: new LANGUAGE.Term( "Auto", "自動" ), diff --git a/www/js/scene.js b/www/js/scene.js index 8adabd9..89d2528 100644 --- a/www/js/scene.js +++ b/www/js/scene.js @@ -642,6 +642,7 @@ const SCENES = { } load(data) { let buttons_bottom = [ ]; + buttons_bottom.push(UI.button(LANG("undo"), () => { INTERFACE.undo(); })); buttons_bottom.push(UI.button(LANG("reset"), () => { INTERFACE.reset(); })); buttons_bottom.push(UI.button(LANG("back"), () => { LOAD(SCENES.Browse); }));