Add review and resume buttons to game interface.

This commit is contained in:
yukirij 2024-09-08 14:34:07 -07:00
parent c39c05969e
commit f22f8cde3b
3 changed files with 108 additions and 16 deletions

View File

@ -1078,8 +1078,12 @@ const INTERFACE = {
let turn = INTERFACE_DATA.history.length; let turn = INTERFACE_DATA.history.length;
if(INTERFACE_DATA.history.length > 0) { if(INTERFACE_DATA.history.length > 0) {
if(INTERFACE_DATA.history[INTERFACE_DATA.history.length-1].source == 2) { if(INTERFACE_DATA.replay_turn == 0) {
turn = 0; if(INTERFACE_DATA.history[INTERFACE_DATA.history.length-1].source == 2) {
turn = 0;
}
} else {
turn = INTERFACE_DATA.replay_turn;
} }
} }

View File

@ -587,13 +587,57 @@ const SCENES = {
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }), UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }), UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
]; ];
if(data.mode == INTERFACE.Mode.Review) {
buttons_top.push(UI.button(LANG("play"), () => { if(data.player != 0) {
LOAD(SCENES.GamePractice, { if(data.mode == INTERFACE.Mode.Review) {
history: INTERFACE_DATA.history, let callback_resume = function() {
turn: INTERFACE_DATA.replay_turn, LOAD(SCENES.Game, {
token:this.token,
player:this.player,
turn:-1,
mode:INTERFACE.Mode.Player,
});
MESSAGE_SESSION_VIEW(this.token, true);
}
callback_resume = callback_resume.bind({
token: data.token,
player: data.player,
}); });
}));
buttons_top.push(UI.button(LANG("resume"), callback_resume));
} else {
let callback_review = function() {
LOAD(SCENES.Game, {
token:this.token,
turn:-1,
player:this.player,
mode:INTERFACE.Mode.Review,
});
MESSAGE_SESSION_VIEW(this.token, false);
}
callback_review = callback_review.bind({
token: data.token,
player: data.player,
});
buttons_top.push(UI.button(LANG("review"), callback_review));
}
}
if(data.mode == INTERFACE.Mode.Review) {
let play_callback = function() {
LOAD(SCENES.GamePractice, {
token:this.token,
player:this.player,
history:INTERFACE_DATA.history,
turn:INTERFACE_DATA.replay_turn,
})
}
play_callback = play_callback.bind({
token: data.token,
player: data.player,
});
buttons_top.push(UI.button(LANG("play"), play_callback));
} }
UI.nav(buttons_top, buttons_bottom); UI.nav(buttons_top, buttons_bottom);
@ -625,6 +669,10 @@ const SCENES = {
MAIN.appendChild(canvas); MAIN.appendChild(canvas);
INTERFACE.init(data.token, data.mode); INTERFACE.init(data.token, data.mode);
console.log(data.turn);
if(data.turn != -1) {
INTERFACE_DATA.replay_turn = data.turn;
}
history.pushState(null, "Dzura - Game", "/game/" + PACK.base64(data.token).slice(0, -1)); history.pushState(null, "Dzura - Game", "/game/" + PACK.base64(data.token).slice(0, -1));
return true; return true;
@ -652,22 +700,44 @@ const SCENES = {
this.game = null; this.game = null;
} }
load(data) { load(data) {
let buttons_top = [
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
UI.button(LANG("auto"), () => { INTERFACE.auto(); }),
];
if(data !== null) {
if(data.history.length > 0) {
let callback_review = function() {
LOAD(SCENES.Game, {
token:this.token,
turn:INTERFACE_DATA.history_begin.length,
player:this.player,
mode:INTERFACE.Mode.Review,
});
MESSAGE_SESSION_VIEW(this.token, false);
}
callback_review = callback_review.bind({
token: data.token,
player: data.player,
});
buttons_top.push(UI.button(LANG("review"), callback_review));
}
}
let buttons_bottom = [ ]; let buttons_bottom = [ ];
buttons_bottom.push(UI.button(LANG("undo"), () => { INTERFACE.undo(); })); buttons_bottom.push(UI.button(LANG("undo"), () => { INTERFACE.undo(); }));
buttons_bottom.push(UI.button(LANG("reset"), () => { INTERFACE.reset(); })); buttons_bottom.push(UI.button(LANG("reset"), () => { INTERFACE.reset(); }));
buttons_bottom.push(UI.button(LANG("back"), () => { LOAD(SCENES.Browse); })); buttons_bottom.push(UI.button(LANG("back"), () => { LOAD(SCENES.Browse); }));
UI.nav([ UI.nav(buttons_top, buttons_bottom);
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
UI.button(LANG("auto"), () => { INTERFACE.auto(); }),
], buttons_bottom);
let canvas = document.createElement("canvas"); let canvas = document.createElement("canvas");
canvas.setAttribute("id", "game"); canvas.setAttribute("id", "game");
MAIN.appendChild(canvas); MAIN.appendChild(canvas);
INTERFACE.init(null, INTERFACE.Mode.Local); INTERFACE.init(data, INTERFACE.Mode.Local);
if(data !== null) { if(data !== null) {
for(let i = 0; i < data.turn; ++i) { for(let i = 0; i < data.turn; ++i) {
INTERFACE_DATA.history_begin.push(data.history[i]); INTERFACE_DATA.history_begin.push(data.history[i]);
@ -936,6 +1006,8 @@ function LOAD_URL() {
let token = UNPACK.base64(parts[2] + "="); let token = UNPACK.base64(parts[2] + "=");
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:token, token:token,
player:0,
turn:-1,
mode:INTERFACE.Mode.Review, mode:INTERFACE.Mode.Review,
}); });
MESSAGE_SESSION_VIEW(token, false); MESSAGE_SESSION_VIEW(token, false);

View File

@ -190,20 +190,30 @@ const UI = {
let join_callback = function() { let join_callback = function() {
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:this.token, token:this.token,
player:this.player,
turn:-1,
mode:INTERFACE.Mode.Player, mode:INTERFACE.Mode.Player,
}); });
MESSAGE_SESSION_VIEW(this.token, true); MESSAGE_SESSION_VIEW(this.token, true);
}; };
join_callback = join_callback.bind({token: records[r].token}); join_callback = join_callback.bind({
token: records[r].token,
player: records[r].player,
});
let spectate_callback = function() { let spectate_callback = function() {
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:this.token, token:this.token,
player:this.player,
turn:-1,
mode:INTERFACE.Mode.Review, mode:INTERFACE.Mode.Review,
}); });
MESSAGE_SESSION_VIEW(this.token, false); MESSAGE_SESSION_VIEW(this.token, false);
}; };
spectate_callback = spectate_callback.bind({token: records[r].token}); spectate_callback = spectate_callback.bind({
token: records[r].token,
player: records[r].player,
});
if(records[r].player != 0) { if(records[r].player != 0) {
let button_resume = UI.button(LANG("resume"), join_callback); let button_resume = UI.button(LANG("resume"), join_callback);
@ -246,6 +256,8 @@ const UI = {
SCENE_FORWARD = SCENE; SCENE_FORWARD = SCENE;
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:this.token, token:this.token,
player:0,
turn:-1,
mode:INTERFACE.Mode.Player, mode:INTERFACE.Mode.Player,
}); });
MESSAGE_SESSION_VIEW(this.token, true); MESSAGE_SESSION_VIEW(this.token, true);
@ -256,6 +268,8 @@ const UI = {
SCENE_FORWARD = SCENE; SCENE_FORWARD = SCENE;
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:this.token, token:this.token,
player:0,
turn:-1,
mode:INTERFACE.Mode.Review, mode:INTERFACE.Mode.Review,
}); });
MESSAGE_SESSION_VIEW(this.token, false); MESSAGE_SESSION_VIEW(this.token, false);
@ -335,6 +349,8 @@ const UI = {
SCENE_FORWARD = SCENE; SCENE_FORWARD = SCENE;
LOAD(SCENES.Game, { LOAD(SCENES.Game, {
token:this.token, token:this.token,
player:0,
turn:-1,
mode:INTERFACE.Mode.Review, mode:INTERFACE.Mode.Review,
}); });
MESSAGE_SESSION_VIEW(this.token, false); MESSAGE_SESSION_VIEW(this.token, false);