2020-03-26 20:25:33 +01:00
|
|
|
const ids = {};
|
2020-03-28 20:55:39 +01:00
|
|
|
["map_holder", "name", "turns", "nop", "lobby"].forEach(id => ids[id] = document.getElementById(id));
|
2020-03-26 20:25:33 +01:00
|
|
|
|
|
|
|
var last_map;
|
2020-03-27 18:35:56 +01:00
|
|
|
var last_url;
|
2020-03-26 20:25:33 +01:00
|
|
|
|
|
|
|
async function handle_map_click(url, event) {
|
|
|
|
if (last_map) {
|
|
|
|
last_map.classList.remove("selected");
|
|
|
|
}
|
|
|
|
last_map = event.target;
|
|
|
|
event.target.classList.add("selected");
|
2020-03-27 18:35:56 +01:00
|
|
|
last_url = url;
|
2020-03-26 20:25:33 +01:00
|
|
|
const c = await fetch(url);
|
|
|
|
ids["map_holder"].innerHTML = await c.text();
|
2020-03-27 10:31:56 +01:00
|
|
|
}
|
|
|
|
|
2020-03-28 20:55:39 +01:00
|
|
|
async function refresh_state() {
|
|
|
|
const c = await fetch("/partial/state");
|
|
|
|
ids["lobby"].innerHTML = await c.text();
|
|
|
|
}
|
|
|
|
|
2020-03-27 10:31:56 +01:00
|
|
|
async function start_game() {
|
2020-03-27 18:35:56 +01:00
|
|
|
const obj = {
|
|
|
|
"nop": parseInt(ids["nop"].value),
|
|
|
|
"name": ids["name"].value,
|
|
|
|
"map": last_url,
|
|
|
|
"max_turns": parseInt(ids["turns"].value),
|
|
|
|
};
|
2020-03-27 10:31:56 +01:00
|
|
|
|
2020-03-27 18:35:56 +01:00
|
|
|
const xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.onreadystatechange = async function() {
|
|
|
|
console.log(this);
|
|
|
|
// TODO: make response visible
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.open("POST", "/lobby");
|
|
|
|
xhr.send(JSON.stringify(obj));
|
2020-03-28 20:55:39 +01:00
|
|
|
|
|
|
|
setTimeout(
|
|
|
|
() => refresh_state(),
|
|
|
|
200
|
|
|
|
);
|
2020-03-27 18:35:56 +01:00
|
|
|
}
|
2020-03-28 20:55:39 +01:00
|
|
|
|
|
|
|
window.onload = () => refresh_state();
|