]> git.cworth.org Git - lmno.games/blobdiff - lmno.js
empires: Add a top-level static page for the Empires game
[lmno.games] / lmno.js
diff --git a/lmno.js b/lmno.js
index f1f9cd7f874a1f193382283a5a6a350deefc0b74..e4785a86d4fe8ae282ae2102a3c3bebaf2b8f414 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -30,3 +30,26 @@ function lmno_join(form) {
 
   form.reset();
 }
+
+function new_loadend() {
+  if (this.status == 200) {
+    /* Response contains the game ID which we simply point the browser to. */
+    const game_id = JSON.parse(this.response);
+    window.location.href = ('/' + game_id);
+    return;
+  }
+
+  add_message("danger", `An error occured creating a new game (${this.status}).`);
+}
+
+function lmno_new(engine) {
+  console.log("In lmno_new");
+  const request = new XMLHttpRequest();
+  request.addEventListener("loadend", new_loadend);
+
+  request.open("POST", "/new/" + engine);
+  request.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
+  request.send();
+
+  return false;
+}