40 lines
1.1 KiB
Plaintext

<!DOCTYPE html>
<html>
<head>
<title>Blab</title>
</head>
<body>
<h1>Hello, world!</h1>
<p id="iteration">Iteration: {{ iteration }}<p>
<ul id="objects">
{% for object in objects %}
<li>{{ object.name }} @ {{ object.x }}, {{ object.y }}</li>
{% endfor %}
</ul>
<script>
ws = new WebSocket("ws://localhost:3030/state");
ws.onopen = function() {
console.log("Connected");
}
ws.onmessage = function(e) {
const data = JSON.parse(e.data);
document.getElementById("iteration").innerText = `Iteration: ${data.iteration}`;
const ul = document.getElementById("objects");
while(ul.firstChild) { ul.removeChild(ul.lastChild) }
for (n in data.objects) {
const ob = data.objects[n];
const li = document.createElement("li");
li.innerText = `${ob.name} @ ${ob.x}, ${ob.y}`;
ul.append(li);
}
};
</script>
</body>
</html>