statki/public/assets/js/spa_lib.js
MaciejkaG a212161733 Major changes
- Improved PWA support on mobile.
- Added Vs. AI game menu.
- Added the first AI algorithm.
- Vs. AI is now available with every option leading to simple bot
- Fixed a bug where placing ships in certain rotation around the boundaries of the board would wrongly colour them when sunk.
- Improved code clarity and comments
- Added an option in the settings to change your nickname
- Added version display in the settings
- Slightly improved box scaling and layout
- Made multiple improvements to the PWA support
- Added multiple minor features
- Brought back full SPA URL functionality, now if you copy a URL to specific view/page in the menu and go into it, you will actually arrive at that page if it's not restricted.
2024-04-14 19:17:20 +02:00

54 lines
1.8 KiB
JavaScript

var activeView;
var returnLock = false;
function switchView(viewContainerId, useReplaceState=false) {
if (!returnLock && viewContainerId !== activeView) {
$(`.container`).css({ opacity: 0, animation: "OutAnim 0.2s 1 ease" });
setTimeout(() => {
$(`.container`).css("display", "none");
$(`.container#${viewContainerId}`).css({ display: "flex", opacity: 1, animation: "InAnim 0.2s 1 ease" });
let path = $(`.container#${viewContainerId}`).data("path");
let title = $(`.container#${viewContainerId}`).data("title");
if (useReplaceState) {
history.replaceState(null, "", path ? path : "/");
} else {
history.pushState(null, title ? title : "Statki", path ? path : "/");
}
activeView = viewContainerId;
}, 200);
}
}
function lockUI(doLock) {
if (doLock) {
$("body").css("pointer-events", "none");
$(".container").css("opacity", "0.4");
} else {
$("body").css("pointer-events", "inherit");
$(".container").css("opacity", "1");
}
}
const initialURLParams = new URLSearchParams(window.location.search);
const initialPath = initialURLParams.get('path');
window.addEventListener("load", () => {
if (initialPath != null) {
let elem = document.querySelector(`.container[data-path="${initialPath}"]:not(.container[data-pathlock])`);
if (elem != null) {
switchView(elem.id, true);
}
}
});
addEventListener("popstate", (event) => {
event.preventDefault();
if (!returnLock) {
let elem = document.querySelector(`.container[data-path="${window.location.pathname}"]`);
if (elem != null) {
switchView(elem.id, true);
}
}
});