laneya2

cave exploration game
git clone https://git.ce9e.org/laneya2.git

commit
837c95dae8c8f48466f33a4ba80c27e10cf90b87
parent
7a7b5bee1133bd39a89337c6b09e279184808659
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-10-05 10:19
fix: do not wait for items in between socket connection and handlers

Diffstat

M static/main.js 16 ++++++++--------

1 files changed, 8 insertions, 8 deletions


diff --git a/static/main.js b/static/main.js

@@ -5,12 +5,7 @@ var $pre = document.querySelector('pre');
    5     5 var params = new URLSearchParams(location.search);
    6     6 var gameId = params.get('game');
    7     7 
    8    -1 var socketProtocol = location.protocol.replace('http', 'ws');
    9    -1 var socket = new WebSocket(`${socketProtocol}//${location.host}/ws/${gameId}`);
   10    -1 
   11    -1 var send = function(data) {
   12    -1     socket.send(JSON.stringify(data));
   13    -1 };
   -1     8 var ITEMS = await fetch('/items.json').then(r => r.json());
   14     9 
   15    10 var COLORS = {
   16    11     'player': 4,
@@ -18,8 +13,6 @@ var COLORS = {
   18    13     'pile': 3,
   19    14 };
   20    15 
   21    -1 var ITEMS = await fetch('/items.json').then(r => r.json());
   22    -1 
   23    16 var inRect = function(pos, rect, withWalls) {
   24    17     if (withWalls) {
   25    18         return pos.x >= rect.x1 - 1 && pos.x <= rect.x2 + 1
@@ -340,6 +333,13 @@ var screen = {
  340   333     },
  341   334 };
  342   335 
   -1   336 var socketProtocol = location.protocol.replace('http', 'ws');
   -1   337 var socket = new WebSocket(`${socketProtocol}//${location.host}/ws/${gameId}`);
   -1   338 
   -1   339 var send = function(data) {
   -1   340     socket.send(JSON.stringify(data));
   -1   341 };
   -1   342 
  343   343 socket.onclose = function() {
  344   344     alert('Connection lost');
  345   345 };