Change practice auto language; add rotation persistence between games and review.

This commit is contained in:
yukirij 2024-10-06 17:53:11 -07:00
parent 06069dc354
commit 6e29ae42e8
3 changed files with 40 additions and 23 deletions

View File

@ -749,8 +749,8 @@ const INTERFACE = {
if(INTERFACE_DATA.Game.auto !== null) {
switch(INTERFACE_DATA.Game.auto) {
case 0: message = LANG("auto") + " " + LANG("dawn"); break;
case 1: message = LANG("auto") + " " + LANG("dusk"); break;
case 0: message = LANG("cpu") + " " + LANG("dawn"); break;
case 1: message = LANG("cpu") + " " + LANG("dusk"); break;
}
}
@ -1138,20 +1138,17 @@ const INTERFACE = {
},
},
init(token, mode) {
init(token, mode, params={}) {
GAME.init();
let player = 2;
let dawn = null;
let dusk = null;
INTERFACE_DATA = {
canvas: document.getElementById("game"),
context: null,
player: player,
rotate: 0,
rotate: params.rotate !== undefined? params.rotate : 0,
mirror: false,
hover: null,
@ -1308,8 +1305,13 @@ const INTERFACE = {
switch(code) {
case OpCode.GameState: {
INTERFACE_DATA.player = data.player;
if(INTERFACE_DATA.rotate >= 2) {
INTERFACE_DATA.rotate = (INTERFACE_DATA.rotate & 1) ^ (data.player & 1);
}
if(INTERFACE_DATA.mode == INTERFACE.Mode.Player) {
INTERFACE_DATA.player = data.player;
if(data.undo > 0) {
if((1 << INTERFACE_DATA.player) == data.undo) {
INTERFACE_DATA.Ui.request_undo = 1;

View File

@ -53,6 +53,7 @@ LANGUAGE.Terms = {
undo: new LANGUAGE.Term( "Undo", "待った" ),
reset: new LANGUAGE.Term( "Reset", "リセット" ),
auto: new LANGUAGE.Term( "Auto", "自動" ),
cpu: new LANGUAGE.Term("CPU", "CPU"),
users: new LANGUAGE.Term( "Users", "ユーザー" ),
requests: new LANGUAGE.Term( "Requests", "挑戦状" ),

View File

@ -587,10 +587,12 @@ const SCENES = {
this.mode = null;
this.token = null;
this.turn = null;
this.rotate = 0;
}
load(data) {
this.mode = data.mode;
this.token = data.token;
if(data.rotate !== undefined) { this.rotate = data.rotate; }
if(data.turn !== undefined) { this.turn = data.turn; }
MESSAGE_SESSION_VIEW(this.token, this.mode == INTERFACE.Mode.Player);
return true;
@ -604,6 +606,7 @@ const SCENES = {
token:this.token,
view:data,
turn:this.turn,
rotate:this.rotate,
});
} else {
LOAD(SCENES.Browse);
@ -650,6 +653,7 @@ const SCENES = {
LOAD(SCENES.GameLoad, {
token:this.token,
mode:INTERFACE.Mode.Player,
rotate:2 + ((INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate),
});
}
callback_resume = callback_resume.bind({
@ -662,6 +666,7 @@ const SCENES = {
LOAD(SCENES.GameLoad, {
token:this.token,
mode:INTERFACE.Mode.Review,
rotate:2 + ((INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate),
});
}
callback_review = callback_review.bind({
@ -686,6 +691,7 @@ const SCENES = {
token:this.token,
history:INTERFACE_DATA.Game.history,
turn:turn,
rotate:(INTERFACE_DATA.player & 1) ^ INTERFACE_DATA.rotate,
});
}
play_callback = play_callback.bind({
@ -725,7 +731,9 @@ const SCENES = {
MAIN.appendChild(canvas);
// Interface
INTERFACE.init(data.token, data.mode);
INTERFACE.init(data.token, data.mode, {
rotate:data.rotate,
});
if(data.turn !== null) {
INTERFACE_DATA.Replay.turn = data.turn;
}
@ -752,24 +760,23 @@ const SCENES = {
let buttons_top = [
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
UI.button(LANG("auto"), () => { INTERFACE.auto(); }),
UI.button(LANG("cpu"), () => { INTERFACE.auto(); }),
];
if(data !== null) {
if(data.history.length > 0) {
let callback_review = function() {
LOAD(SCENES.GameLoad, {
token:this.token,
mode:INTERFACE.Mode.Review,
turn:INTERFACE_DATA.Game.history_begin.length,
});
}
callback_review = callback_review.bind({
token: data.token,
let callback_review = function() {
LOAD(SCENES.GameLoad, {
token:this.token,
mode:INTERFACE.Mode.Review,
turn:INTERFACE_DATA.Game.history_begin.length,
rotate:2 + INTERFACE_DATA.rotate,
});
buttons_top.push(UI.button(LANG("review"), callback_review));
}
callback_review = callback_review.bind({
token: data.token,
});
buttons_top.push(UI.button(LANG("review"), callback_review));
}
let buttons_bottom = [ ];
@ -783,7 +790,14 @@ const SCENES = {
canvas.setAttribute("id", "game");
MAIN.appendChild(canvas);
INTERFACE.init(data, INTERFACE.Mode.Local);
let params = {};
if(data !== null) {
params = {
rotate:data.rotate !== undefined? data.rotate : 0,
};
}
INTERFACE.init(data, INTERFACE.Mode.Local, params);
if(data !== null) {
for(let i = 0; i < data.turn; ++i) {
INTERFACE_DATA.Game.history_begin.push(data.history[i]);