2019-09-21 18:56:46 +02:00
|
|
|
|
2019-09-24 15:38:04 +02:00
|
|
|
import { set_game_name, set_loading, LOCATION, set_instance } from './index'
|
2019-09-21 18:56:46 +02:00
|
|
|
import { ConfigIniParser } from 'config-ini-parser'
|
|
|
|
|
|
|
|
const OPTIONS = document.getElementById("options");
|
|
|
|
|
|
|
|
|
|
|
|
const game_location = LOCATION + "static/games/mod.ini";
|
|
|
|
|
|
|
|
fetch(game_location)
|
|
|
|
.then((r) => r.text())
|
|
|
|
.then((response) => {
|
2020-03-27 18:35:56 +01:00
|
|
|
if (OPTIONS) {
|
|
|
|
parse_ini(response);
|
|
|
|
} else {
|
|
|
|
console.log("Options is not defined, tera?");
|
|
|
|
}
|
2019-09-21 18:56:46 +02:00
|
|
|
}).catch(console.error);
|
|
|
|
|
2019-09-24 15:38:04 +02:00
|
|
|
export function handle(location, name: string) {
|
2019-09-21 20:13:57 +02:00
|
|
|
set_loading(true);
|
2019-09-21 18:56:46 +02:00
|
|
|
|
|
|
|
fetch(location)
|
|
|
|
.then((r) => r.text())
|
|
|
|
.then((response) => {
|
|
|
|
set_instance(response);
|
2019-09-24 15:38:04 +02:00
|
|
|
set_game_name(name);
|
2019-09-21 18:56:46 +02:00
|
|
|
}).catch(console.error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function create_option(location: string, name: string, turns: string, players: string): HTMLElement {
|
|
|
|
const div = document.createElement("div");
|
|
|
|
div.className = "option";
|
2019-09-24 15:38:04 +02:00
|
|
|
div.onclick = (_) => handle(location, name);
|
2020-03-27 18:35:56 +01:00
|
|
|
console.log("hello there");
|
|
|
|
console.log(`"${location}, "${name}"`);
|
2019-09-21 18:56:46 +02:00
|
|
|
let ps = "";
|
|
|
|
|
|
|
|
if (players) {
|
|
|
|
ps += "<p>Players</p>";
|
|
|
|
|
2019-09-24 14:29:13 +02:00
|
|
|
for (let [index, player] of players.split('"').entries()) {
|
|
|
|
if (index % 2 == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ps += `<p>${player}</p>`;
|
2019-09-21 18:56:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const html = `
|
|
|
|
<p>${name}</p>
|
|
|
|
<p>Turns: ${turns}</p>
|
|
|
|
` + ps;
|
|
|
|
|
|
|
|
div.innerHTML = html;
|
|
|
|
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parse_ini(inifile: string) {
|
|
|
|
const parser = new ConfigIniParser();
|
|
|
|
parser.parse(inifile);
|
|
|
|
|
|
|
|
const loc = parser.get(undefined, "path");
|
|
|
|
|
|
|
|
OPTIONS.innerHTML = '';
|
|
|
|
|
|
|
|
for (let name of parser.sections()) {
|
|
|
|
const game = parser.get(name, "name");
|
|
|
|
const turns = parser.get(name, "turns");
|
|
|
|
const players = parser.get(name, "players")
|
|
|
|
OPTIONS.appendChild(
|
|
|
|
create_option(loc+name, game , turns, players)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|