* 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:
ajuvercr 2020-04-11 08:21:08 +02:00 committed by GitHub
parent 6b7fd4eff3
commit 33abe9515f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 347 additions and 337 deletions

View file

@ -36,12 +36,9 @@ async function start_game() {
};
xhr.open("POST", "/lobby");
xhr.send(JSON.stringify(obj));
xhr.addEventListener("loadend", refresh_state);
setTimeout(
() => refresh_state(),
200
);
xhr.send(JSON.stringify(obj));
}
window.onload = () => refresh_state();

View file

@ -50,3 +50,20 @@
content: "\f091";
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;
}

View file

@ -4,7 +4,7 @@
<h2 class="handle">
<label for="handle_{{loop.index}}">
<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>
</h2>
<div class="content">

View file

@ -4,29 +4,47 @@ import { ConfigIniParser } from 'config-ini-parser'
const OPTIONS = document.getElementById("options");
const game_location = LOCATION + "static/games/mod.ini";
if (OPTIONS) {
fetch(game_location)
.then((r) => r.text())
.then((response) => {
parse_ini(response);
}).catch(console.error);
} else {
const options = document.getElementsByClassName("options");
if (options[0]) {
const options_div = <HTMLDivElement> options[0];
if (options_div.children[0]) {
setTimeout(
() => options_div.children[0].dispatchEvent(new Event('click')),
200,
);
}
}
var game_name, game_file;
document.getElementById("addbutton").onclick = function() {
const loc = window.location;
const query = `?game=${game_file}&name=${game_name}`;
navigator.clipboard.writeText(loc.origin+loc.pathname+encodeURI(query)).then(() => {
console.log("Success");
}, () => {
console.log("Failed");
});
}
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) {
game_file = location;
game_name = name;
set_loading(true);
fetch(location)

View file

@ -30,10 +30,6 @@ const SLIDER = <HTMLInputElement>document.getElementById("turnSlider");
const FILESELECTOR = <HTMLInputElement> document.getElementById("fileselect");
const SPEED = <HTMLInputElement> document.getElementById("speed");
document.getElementById("addbutton").onclick = function() {
FILESELECTOR.click();
}
export function set_loading(loading: boolean) {
if (loading) {
if (!LOADER.classList.contains("loading")) {

View file

@ -195,47 +195,31 @@ p {
position: absolute;
top: 10px;
right: 10px;
width: 40px;
height: 40px;
width: 0;
height: 0;
}
.button:before,
.button:after {
.button::before {
content: "";
position: absolute;
background-color: grey;
display: block;
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:after {
background-color: white;
.button:hover::before {
color: #ff7f00;
}
.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
* Licensed under FreeBSD License.
* See http://animista.net/license for more info.
* w: http://animista.net, t: @cssanimista
* ---------------------------------------------- */
/**
* ----------------------------------------
* animation slide-top
@ -263,8 +247,6 @@ p {
transform: translate(-50%, -150%);
}
}
/**
* ----------------------------------------
* Copy from https://www.w3schools.com/howto/howto_js_rangeslider.asp