planet-wars/backend/static/script/maps.js

40 lines
940 B
JavaScript
Raw Normal View History

2020-03-26 20:25:33 +01:00
const ids = {};
2020-03-27 10:31:56 +01:00
["map_holder", "name", "turns", "nop"].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
}
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
console.log(obj);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = async function() {
console.log(this);
console.log(await this.text());
// TODO: make response visible
};
xhr.open("POST", "/lobby");
xhr.send(JSON.stringify(obj));
}