* make lobby game post refresh page better * frontend side of handling specific games * add link button in lobby * add share button
This commit is contained in:
parent
6b7fd4eff3
commit
33abe9515f
6 changed files with 347 additions and 337 deletions
|
@ -36,12 +36,9 @@ async function start_game() {
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.open("POST", "/lobby");
|
xhr.open("POST", "/lobby");
|
||||||
xhr.send(JSON.stringify(obj));
|
xhr.addEventListener("loadend", refresh_state);
|
||||||
|
|
||||||
setTimeout(
|
xhr.send(JSON.stringify(obj));
|
||||||
() => refresh_state(),
|
|
||||||
200
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = () => refresh_state();
|
window.onload = () => refresh_state();
|
|
@ -50,3 +50,20 @@
|
||||||
content: "\f091";
|
content: "\f091";
|
||||||
transform: translate(-30px, 0px);
|
transform: translate(-30px, 0px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.link::before {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
float: left;
|
||||||
|
margin: 0 -20px 0 0;
|
||||||
|
font-family: 'fontawesome';
|
||||||
|
content: "\f14c";
|
||||||
|
transform: translate(-20px, 0px);
|
||||||
|
color: antiquewhite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover::before {
|
||||||
|
color: #ff7f00;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
<h2 class="handle">
|
<h2 class="handle">
|
||||||
<label for="handle_{{loop.index}}">
|
<label for="handle_{{loop.index}}">
|
||||||
<span>{{state.name}} ({% if state.state %}{{state.state.map}}{% else %}{{state.map}}{% endif %})</span>
|
<span>{{state.name}} ({% if state.state %}{{state.state.map}}{% else %}{{state.map}}{% endif %})</span>
|
||||||
<span style="float: right">{% if state.type == "Playing" %}{{ state.connected }}/{{state.total}}{% endif %}</span>
|
<span style="float: right">{% if state.type == "Playing" %}{{ state.connected }}/{{state.total}}{% else %}<a class="link" href='/visualizer?name={{state.name | safe }}&game=/games/{{state.file | safe}}'></a>{% endif %}</span>
|
||||||
</label>
|
</label>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|
|
@ -4,29 +4,47 @@ import { ConfigIniParser } from 'config-ini-parser'
|
||||||
|
|
||||||
const OPTIONS = document.getElementById("options");
|
const OPTIONS = document.getElementById("options");
|
||||||
|
|
||||||
|
|
||||||
const game_location = LOCATION + "static/games/mod.ini";
|
const game_location = LOCATION + "static/games/mod.ini";
|
||||||
|
|
||||||
if (OPTIONS) {
|
var game_name, game_file;
|
||||||
fetch(game_location)
|
|
||||||
.then((r) => r.text())
|
document.getElementById("addbutton").onclick = function() {
|
||||||
.then((response) => {
|
const loc = window.location;
|
||||||
parse_ini(response);
|
const query = `?game=${game_file}&name=${game_name}`;
|
||||||
}).catch(console.error);
|
navigator.clipboard.writeText(loc.origin+loc.pathname+encodeURI(query)).then(() => {
|
||||||
} else {
|
console.log("Success");
|
||||||
const options = document.getElementsByClassName("options");
|
}, () => {
|
||||||
if (options[0]) {
|
console.log("Failed");
|
||||||
const options_div = <HTMLDivElement> options[0];
|
});
|
||||||
if (options_div.children[0]) {
|
|
||||||
setTimeout(
|
|
||||||
() => options_div.children[0].dispatchEvent(new Event('click')),
|
|
||||||
200,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function on_load() {
|
||||||
|
console.log("ON LOAD");
|
||||||
|
if (OPTIONS) {
|
||||||
|
const r = await fetch(game_location);
|
||||||
|
const response = await r.text();
|
||||||
|
parse_ini(response);
|
||||||
|
} else {
|
||||||
|
const options = document.getElementsByClassName("options");
|
||||||
|
const urlVars = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
if (urlVars.get("game") && urlVars.get("name")) {
|
||||||
|
console.log(urlVars.get("game")+' '+urlVars.get("name"))
|
||||||
|
handle(urlVars.get("game"),urlVars.get("name"))
|
||||||
|
} else if (options[0]) {
|
||||||
|
const options_div = <HTMLDivElement> options[0];
|
||||||
|
if (options_div.children[0]) {
|
||||||
|
options_div.children[0].dispatchEvent(new Event('click'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener("load", on_load, false);
|
||||||
|
|
||||||
export function handle(location, name: string) {
|
export function handle(location, name: string) {
|
||||||
|
game_file = location;
|
||||||
|
game_name = name;
|
||||||
|
|
||||||
set_loading(true);
|
set_loading(true);
|
||||||
|
|
||||||
fetch(location)
|
fetch(location)
|
||||||
|
|
|
@ -30,10 +30,6 @@ const SLIDER = <HTMLInputElement>document.getElementById("turnSlider");
|
||||||
const FILESELECTOR = <HTMLInputElement> document.getElementById("fileselect");
|
const FILESELECTOR = <HTMLInputElement> document.getElementById("fileselect");
|
||||||
const SPEED = <HTMLInputElement> document.getElementById("speed");
|
const SPEED = <HTMLInputElement> document.getElementById("speed");
|
||||||
|
|
||||||
document.getElementById("addbutton").onclick = function() {
|
|
||||||
FILESELECTOR.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function set_loading(loading: boolean) {
|
export function set_loading(loading: boolean) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
if (!LOADER.classList.contains("loading")) {
|
if (!LOADER.classList.contains("loading")) {
|
||||||
|
|
|
@ -195,47 +195,31 @@ p {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 10px;
|
right: 10px;
|
||||||
width: 40px;
|
width: 0;
|
||||||
height: 40px;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:before,
|
.button::before {
|
||||||
.button:after {
|
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
display: block;
|
||||||
background-color: grey;
|
float: left;
|
||||||
|
margin: 0 -20px 0 0;
|
||||||
|
font-family: 'fontawesome';
|
||||||
|
content: "\f1e1";
|
||||||
|
transform: translate(-1em, 0px);
|
||||||
|
color: antiquewhite;
|
||||||
|
font-size: 1.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:hover:before,
|
.button:hover::before {
|
||||||
.button:hover:after {
|
color: #ff7f00;
|
||||||
background-color: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.button:before {
|
|
||||||
top: 0;
|
|
||||||
left: 50%;
|
|
||||||
width: 6px;
|
|
||||||
height: 100%;
|
|
||||||
margin-left: -3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button:after {
|
|
||||||
top: 50%;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 6px;
|
|
||||||
margin-top: -3px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------
|
/* ----------------------------------------------
|
||||||
* Generated by Animista on 2019-9-17 14:35:13
|
* Generated by Animista on 2019-9-17 14:35:13
|
||||||
* Licensed under FreeBSD License.
|
* Licensed under FreeBSD License.
|
||||||
* See http://animista.net/license for more info.
|
* See http://animista.net/license for more info.
|
||||||
* w: http://animista.net, t: @cssanimista
|
* w: http://animista.net, t: @cssanimista
|
||||||
* ---------------------------------------------- */
|
* ---------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ----------------------------------------
|
* ----------------------------------------
|
||||||
* animation slide-top
|
* animation slide-top
|
||||||
|
@ -263,8 +247,6 @@ p {
|
||||||
transform: translate(-50%, -150%);
|
transform: translate(-50%, -150%);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ----------------------------------------
|
* ----------------------------------------
|
||||||
* Copy from https://www.w3schools.com/howto/howto_js_rangeslider.asp
|
* Copy from https://www.w3schools.com/howto/howto_js_rangeslider.asp
|
||||||
|
|
Loading…
Reference in a new issue