Refactor scene management to use preload procedures.
This commit is contained in:
parent
f4e6d9bacf
commit
b2a035931a
@ -732,6 +732,8 @@ pub async fn thread_system(mut app:App, bus:Bus<protocol::QRPacket>)
|
||||
send_user_status.push(session.p_dusk.user);
|
||||
|
||||
session.undo = 0;
|
||||
} else {
|
||||
println!("notice: bad play {} {} {}", play.source, play.from, play.to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
let MAIN = null;
|
||||
let MENU = null;
|
||||
let SCENE = null;
|
||||
let SCENE_STACK = [ ];
|
||||
|
||||
let CONNECTED = false;
|
||||
let SOCKET = null;
|
||||
|
@ -1355,8 +1355,11 @@ const INTERFACE = {
|
||||
}
|
||||
},
|
||||
|
||||
message(code, data) {
|
||||
if(data === null) { return; }
|
||||
message(msg) {
|
||||
if(msg === null) { return; }
|
||||
|
||||
let code = msg.code;
|
||||
let data = msg.data;
|
||||
|
||||
switch(code) {
|
||||
case OpCode.GameState: {
|
||||
|
@ -1,7 +1,7 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
SCENE = SCENES.Offline;
|
||||
LOAD(SCENES.Init);
|
||||
SCENE.load(SCENES.Offline);
|
||||
SCENE.load(SCENES.Init);
|
||||
|
||||
document.addEventListener("beforeunload", UNLOAD);
|
||||
window.addEventListener("popstate", LOAD_URL);
|
||||
document.addEventListener("beforeunload", SCENE.unload);
|
||||
window.addEventListener("popstate", SCENE.load_url);
|
||||
});
|
||||
|
796
www/js/scene.js
796
www/js/scene.js
File diff suppressed because it is too large
Load Diff
@ -41,7 +41,8 @@ function RESUME() {
|
||||
secret,
|
||||
]);
|
||||
} else {
|
||||
LOAD_URL();
|
||||
console.log("HERE");
|
||||
SCENE.load_url();
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ function MESSAGE(event) {
|
||||
sessionStorage.clear();
|
||||
}
|
||||
|
||||
LOAD_URL();
|
||||
SCENE.load_url();
|
||||
} break;
|
||||
|
||||
case OpCode.Deauthenticate: {
|
||||
@ -566,7 +567,13 @@ function MESSAGE(event) {
|
||||
console.log("RECV Undefined " + code);
|
||||
return;
|
||||
}
|
||||
if(SCENE.message !== undefined) { SCENE.message(code, data) };
|
||||
|
||||
if(data !== null) {
|
||||
SCENE.message({
|
||||
code: code,
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function MESSAGE_COMPOSE(data) {
|
||||
|
50
www/js/ui.js
50
www/js/ui.js
@ -127,15 +127,15 @@ const UI = {
|
||||
|
||||
if(sessionStorage.getItem("auth") === null) {
|
||||
if(features.auth === true) {
|
||||
left.appendChild(UI.button(LANG("register"), () => { LOAD(SCENES.Register); }));
|
||||
left.appendChild(UI.button(LANG("login"), () => { LOAD(SCENES.Authenticate); }));
|
||||
left.appendChild(UI.button(LANG("register"), () => { SCENE.load(SCENES.Register); }));
|
||||
left.appendChild(UI.button(LANG("login"), () => { SCENE.load(SCENES.Authenticate); }));
|
||||
}
|
||||
} else {
|
||||
if(features.session === true) {
|
||||
let button_challenge = UI.button(LANG("requests"), () => { LOAD(SCENES.ChallengeList); });
|
||||
let button_challenge = UI.button(LANG("requests"), () => { SCENE.load(SCENES.Requests); });
|
||||
button_challenge.setAttribute("id", "button-requests");
|
||||
|
||||
left.appendChild(UI.button(LANG("users"), () => { LOAD(SCENES.Challenge); }));
|
||||
left.appendChild(UI.button(LANG("users"), () => { SCENE.load(SCENES.Users); }));
|
||||
left.appendChild(button_challenge);
|
||||
}
|
||||
}
|
||||
@ -166,24 +166,24 @@ const UI = {
|
||||
let top = [ ];
|
||||
let bottom = [ ];
|
||||
|
||||
top.push(UI.button(LANG("browse"), () => { LOAD(SCENES.Browse); }, page == "browse"));
|
||||
top.push(UI.button(LANG("browse"), () => { SCENE.load(SCENES.Browse); }, page == "browse"));
|
||||
if(sessionStorage.getItem("auth") !== null) {
|
||||
let button_resume = UI.button(LANG("resume"), () => { LOAD(SCENES.Continue); }, page == "continue");
|
||||
let button_resume = UI.button(LANG("resume"), () => { SCENE.load(SCENES.Continue); }, page == "continue");
|
||||
button_resume.setAttribute("id", "button-resume");
|
||||
|
||||
top.push(button_resume);
|
||||
//top.push(UI.button("Join", () => { LOAD(SCENES.Join); }, page == "join"));
|
||||
//top.push(UI.button("Join", () => { SCENE.load(SCENES.Join); }, page == "join"));
|
||||
}
|
||||
top.push(UI.button(LANG("live"), () => { LOAD(SCENES.Live); }, page == "live"));
|
||||
top.push(UI.button(LANG("history"), () => { LOAD(SCENES.History); }, page == "history"));
|
||||
top.push(UI.button(LANG("practice"), () => { LOAD(SCENES.GamePractice); }, page == "practice"));
|
||||
top.push(UI.button(LANG("guide"), () => { LOAD(SCENES.Guide); }, page == "guide"));
|
||||
top.push(UI.button(LANG("about"), () => { LOAD(SCENES.About); }, page == "about"));
|
||||
top.push(UI.button(LANG("live"), () => { SCENE.load(SCENES.Live); }, page == "live"));
|
||||
top.push(UI.button(LANG("history"), () => { SCENE.load(SCENES.History); }, page == "history"));
|
||||
top.push(UI.button(LANG("practice"), () => { SCENE.load(SCENES.GamePractice); }, page == "practice"));
|
||||
top.push(UI.button(LANG("guide"), () => { SCENE.load(SCENES.Guide); }, page == "guide"));
|
||||
top.push(UI.button(LANG("about"), () => { SCENE.load(SCENES.About); }, page == "about"));
|
||||
|
||||
if(CONTEXT.Auth !== null) {
|
||||
bottom.push(UI.button(LANG("account"), () => { LOAD(SCENES.Account); }));
|
||||
bottom.push(UI.button(LANG("account"), () => { SCENE.load(SCENES.Account); }));
|
||||
}
|
||||
bottom.push(UI.button(LANG("extras"), () => { LOAD(SCENES.Extras) }, page == "extras"));
|
||||
bottom.push(UI.button(LANG("extras"), () => { SCENE.load(SCENES.Extras) }, page == "extras"));
|
||||
|
||||
UI.nav(top, bottom);
|
||||
}
|
||||
@ -194,16 +194,16 @@ const UI = {
|
||||
let buttons_bottom = [ ];
|
||||
|
||||
// Top Buttons
|
||||
buttons_top.push(UI.button("Profile", () => { LOAD(SCENES.Profile, { handle:CONTEXT.Auth.handle }) }, page == "profile"));
|
||||
buttons_top.push(UI.button("Profile", () => { SCENE.load(SCENES.Profile, { handle:CONTEXT.Auth.handle }) }, page == "profile"));
|
||||
buttons_top.push(UI.button("History", () => { }, page == "history"));
|
||||
|
||||
// Bottom Buttons
|
||||
if(data === null || data.handle === CONTEXT.Auth.handle) {
|
||||
buttons_bottom.push(UI.button("Account", () => { LOAD(SCENES.Account) }, page == "account"));
|
||||
buttons_bottom.push(UI.button("Subscription", () => { LOAD(SCENES.Subscription) }, page == "subscription"));
|
||||
buttons_bottom.push(UI.button("Invitations", () => { LOAD(SCENES.Invitations) }, page == "invitations"));
|
||||
buttons_bottom.push(UI.button("Account", () => { SCENE.load(SCENES.Account) }, page == "account"));
|
||||
buttons_bottom.push(UI.button("Subscription", () => { SCENE.load(SCENES.Subscription) }, page == "subscription"));
|
||||
buttons_bottom.push(UI.button("Invitations", () => { SCENE.load(SCENES.Invitations) }, page == "invitations"));
|
||||
}
|
||||
buttons_bottom.push(UI.button(LANG("back"), () => { LOAD(SCENES.Browse); }));
|
||||
buttons_bottom.push(UI.button(LANG("back"), () => { SCENE.load(SCENES.Browse); }));
|
||||
|
||||
UI.nav(buttons_top, buttons_bottom);
|
||||
},
|
||||
@ -216,7 +216,7 @@ const UI = {
|
||||
|
||||
let buttons = [ ];
|
||||
let join_callback = function() {
|
||||
LOAD(SCENES.GameLoad, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Player,
|
||||
});
|
||||
@ -226,7 +226,7 @@ const UI = {
|
||||
});
|
||||
|
||||
let spectate_callback = function() {
|
||||
LOAD(SCENES.GameLoad, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
@ -278,7 +278,7 @@ const UI = {
|
||||
let buttons = [ ];
|
||||
let join_callback = function() {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.GameLoad, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Player,
|
||||
});
|
||||
@ -287,7 +287,7 @@ const UI = {
|
||||
|
||||
let spectate_callback = function() {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.GameLoad, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
@ -327,7 +327,7 @@ const UI = {
|
||||
for(let r = 0; r < records.length; ++r) {
|
||||
let buttons = [ ];
|
||||
let join_callback = function() {
|
||||
LOAD(SCENES.Game, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Player,
|
||||
});
|
||||
@ -367,7 +367,7 @@ const UI = {
|
||||
let buttons = [ ];
|
||||
let view_callback = function() {
|
||||
SCENE_FORWARD = SCENE;
|
||||
LOAD(SCENES.GameLoad, {
|
||||
SCENE.load(SCENES.Game, {
|
||||
token:this.token,
|
||||
mode:INTERFACE.Mode.Review,
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user