From c9df933bfbfa165b7d420b02c8a42b90f21b7636 Mon Sep 17 00:00:00 2001 From: yukirij Date: Sun, 18 Aug 2024 13:40:09 -0700 Subject: [PATCH] Add piece mirror; fix move hints on rotate. --- www/js/interface.js | 18 +++++++++++++++--- www/js/scene.js | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/www/js/interface.js b/www/js/interface.js index fe6bce4..d566378 100644 --- a/www/js/interface.js +++ b/www/js/interface.js @@ -394,6 +394,9 @@ const INTERFACE = { if(!is_hover) { draw.hints(piece); } // Draw piece icon + if(INTERFACE_DATA.mirror && (piece.player ^ (INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate) != 0) { + ctx.rotate(Math.PI); + } if(piece.promoted) { ctx.drawImage(GAME_ASSET.Image.Promote, -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.); } ctx.drawImage(GAME_ASSET.Image.Piece[piece.piece][piece.player], -icon_radius, -icon_radius, icon_radius * 2., icon_radius * 2.); @@ -558,7 +561,7 @@ const INTERFACE = { ctx.fillText(GAME_DATA.turn, width - gui_margin, gui_margin); // Game state message - let message = null; + let message = "Info"; ctx.fillStyle = INTERFACE.Color.Text; if(GAME_DATA.state.check) { @@ -593,6 +596,9 @@ const INTERFACE = { hints(piece) { let movement = piece.moves(); + if((INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate) { + movement = movement.rotate(); + } let moves = movement.direction; for(let mask = BITWISE.lsb(moves); moves > 0; mask = BITWISE.lsb(moves)) { @@ -703,6 +709,7 @@ const INTERFACE = { player: player, rotate: 0, + mirror: false, hover: null, select: null, @@ -805,9 +812,14 @@ const INTERFACE = { }, rotate() { - INTERFACE_DATA.rotate = +(!INTERFACE_DATA.rotate); + INTERFACE_DATA.rotate ^= 1; INTERFACE.draw(); - } + }, + + mirror() { + INTERFACE_DATA.mirror = !INTERFACE_DATA.mirror; + INTERFACE.draw(); + }, }; INTERFACE.Radius = 2.0 / Math.sqrt(3.0); diff --git a/www/js/scene.js b/www/js/scene.js index 73472cc..a39e559 100644 --- a/www/js/scene.js +++ b/www/js/scene.js @@ -506,6 +506,7 @@ const SCENES = { UI.nav([ UI.button("Rotate", () => { INTERFACE.rotate(); }), + UI.button("Mirror", () => { INTERFACE.mirror(); }), ], buttons_bottom); let canvas = document.createElement("canvas"); @@ -546,6 +547,7 @@ const SCENES = { UI.nav([ UI.button("Rotate", () => { INTERFACE.rotate(); }), + UI.button("Mirror", () => { INTERFACE.mirror(); }), ], buttons_bottom); let canvas = document.createElement("canvas");