Add review and resume buttons to game interface.
This commit is contained in:
parent
c39c05969e
commit
f22f8cde3b
@ -1078,9 +1078,13 @@ const INTERFACE = {
|
||||
let turn = INTERFACE_DATA.history.length;
|
||||
|
||||
if(INTERFACE_DATA.history.length > 0) {
|
||||
if(INTERFACE_DATA.replay_turn == 0) {
|
||||
if(INTERFACE_DATA.history[INTERFACE_DATA.history.length-1].source == 2) {
|
||||
turn = 0;
|
||||
}
|
||||
} else {
|
||||
turn = INTERFACE_DATA.replay_turn;
|
||||
}
|
||||
}
|
||||
|
||||
if(data.dawn.length > 0) { INTERFACE_DATA.handles[0] = data.dawn; }
|
||||
|
@ -587,13 +587,57 @@ const SCENES = {
|
||||
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
|
||||
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
|
||||
];
|
||||
|
||||
if(data.player != 0) {
|
||||
if(data.mode == INTERFACE.Mode.Review) {
|
||||
buttons_top.push(UI.button(LANG("play"), () => {
|
||||
let callback_resume = function() {
|
||||
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);
|
||||
@ -625,6 +669,10 @@ const SCENES = {
|
||||
MAIN.appendChild(canvas);
|
||||
|
||||
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));
|
||||
return true;
|
||||
@ -652,22 +700,44 @@ const SCENES = {
|
||||
this.game = null;
|
||||
}
|
||||
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 = [ ];
|
||||
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); }));
|
||||
|
||||
UI.nav([
|
||||
UI.button(LANG("rotate"), () => { INTERFACE.rotate(); }),
|
||||
UI.button(LANG("mirror"), () => { INTERFACE.mirror(); }),
|
||||
UI.button(LANG("auto"), () => { INTERFACE.auto(); }),
|
||||
], buttons_bottom);
|
||||
UI.nav(buttons_top, buttons_bottom);
|
||||
|
||||
let canvas = document.createElement("canvas");
|
||||
canvas.setAttribute("id", "game");
|
||||
MAIN.appendChild(canvas);
|
||||
|
||||
INTERFACE.init(null, INTERFACE.Mode.Local);
|
||||
INTERFACE.init(data, INTERFACE.Mode.Local);
|
||||
if(data !== null) {
|
||||
for(let i = 0; i < data.turn; ++i) {
|
||||
INTERFACE_DATA.history_begin.push(data.history[i]);
|
||||
@ -936,6 +1006,8 @@ function LOAD_URL() {
|
||||
let token = UNPACK.base64(parts[2] + "=");
|
||||
LOAD(SCENES.Game, {
|
||||
token:token,
|
||||
player:0,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
MESSAGE_SESSION_VIEW(token, false);
|
||||
|
20
www/js/ui.js
20
www/js/ui.js
@ -190,20 +190,30 @@ const UI = {
|
||||
let join_callback = function() {
|
||||
LOAD(SCENES.Game, {
|
||||
token:this.token,
|
||||
player:this.player,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Player,
|
||||
});
|
||||
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() {
|
||||
LOAD(SCENES.Game, {
|
||||
token:this.token,
|
||||
player:this.player,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
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) {
|
||||
let button_resume = UI.button(LANG("resume"), join_callback);
|
||||
@ -246,6 +256,8 @@ const UI = {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.Game, {
|
||||
token:this.token,
|
||||
player:0,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Player,
|
||||
});
|
||||
MESSAGE_SESSION_VIEW(this.token, true);
|
||||
@ -256,6 +268,8 @@ const UI = {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.Game, {
|
||||
token:this.token,
|
||||
player:0,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
MESSAGE_SESSION_VIEW(this.token, false);
|
||||
@ -335,6 +349,8 @@ const UI = {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.Game, {
|
||||
token:this.token,
|
||||
player:0,
|
||||
turn:-1,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
MESSAGE_SESSION_VIEW(this.token, false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user