aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/ts
diff options
context:
space:
mode:
authorMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-04 01:53:24 +0200
committerMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-04 01:53:24 +0200
commit292257d627bd1dfeafd772ac6457e2f54c2b73ba (patch)
treeb7962648b87ab709e8529075ce912950019adaee /frontend/ts
parenteee4ee32dd667ed6efd31ddcf8f64217b7e16b60 (diff)
downloadfia-292257d627bd1dfeafd772ac6457e2f54c2b73ba.tar.gz
fia-292257d627bd1dfeafd772ac6457e2f54c2b73ba.tar.zst
fia-292257d627bd1dfeafd772ac6457e2f54c2b73ba.zip
One step closer to the end
Diffstat (limited to 'frontend/ts')
-rw-r--r--frontend/ts/login.ts26
-rw-r--r--frontend/ts/startGame.ts27
2 files changed, 53 insertions, 0 deletions
diff --git a/frontend/ts/login.ts b/frontend/ts/login.ts
new file mode 100644
index 0000000..4ef46ab
--- /dev/null
+++ b/frontend/ts/login.ts
@@ -0,0 +1,26 @@
+import startGame from "./startGame.js";
+
+let html = /* html */ `
+ <div class="container text-center fs-1" style="margin-top: 45vh;">
+ <label for="username">Vad heter du?</label>
+ <input type="text" name="username" required>
+ <button type="button" class="btn btn-light btn-lg" onclick="login">Starta spelet</button>
+ </div>
+`;
+
+async function login() {
+ let username = document.getElementsByTagName("input")[0].innerHTML,
+ res = await fetch("/login", {
+ method: "POST",
+ headers: {
+ Accept: "application/json",
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({ username: username })
+ });
+ res = await res.json();
+ startGame(res);
+}
+
+document.body.innerHTML = html;
+document.getElementsByTagName("button")[0].onclick = login;
diff --git a/frontend/ts/startGame.ts b/frontend/ts/startGame.ts
new file mode 100644
index 0000000..50ef068
--- /dev/null
+++ b/frontend/ts/startGame.ts
@@ -0,0 +1,27 @@
+function getCanvasAndCtx(): [HTMLCanvasElement, CanvasRenderingContext2D] {
+ let canvas = document.getElementsByTagName("canvas")[0],
+ ctx = canvas.getContext("2d");
+ if (ctx === null) {
+ document.write("ur muther is fat, stop using IE");
+ throw new Error("PLayer is using browser older that his mom");
+ } else return [canvas, ctx];
+}
+function setOpponents(data: object, body: string) {
+ let a = [
+ {
+ id: 1,
+ color: "red",
+ }
+ ]
+ document.body.innerHTML = body;
+}
+export default async function startGame (data: object) {
+ let body = await (await fetch("/map.html")).text();
+ setOpponents(data, body);
+ let [canvas, ctx] = getCanvasAndCtx();
+ let img = new Image(600, 600);
+ img.width = 600;
+ img.height = 600;
+ img.src = "https://www.egierki.pl/app/uploads/2020/05/Ludo-Play.jpg";
+ img.onload = () => ctx.drawImage(img, 0, 0);
+}