From: Christian Heller Date: Thu, 29 Oct 2020 01:34:25 +0000 (+0100) Subject: Guide user interaction based on server availability. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/gitweb.js?a=commitdiff_plain;h=b40edea3eed5b03e8b5ff87edcd1faebe24888cc;p=plomrogue2-experiments Guide user interaction based on server availability. --- diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index f878776..d7e0018 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -124,11 +124,16 @@ let server = { this.websocket = new WebSocket(url); this.websocket.onopen = function(event) { window.setInterval(function() { server.send(['PING']) }, 30000); - server.send(['GET_GAMESTATE']); + tui.log_msg("@ server connected!"); + tui.init_login(); }; }, send: function(tokens) { - this.websocket.send(unparser.untokenize(tokens)); + if (this.websocket.readyState !== WebSocket.OPEN) { + tui.log_msg('server disconnected :('); + } else { + this.websocket.send(unparser.untokenize(tokens)); + } } } @@ -164,6 +169,7 @@ class Mode { this.shows_annotations = shows_annotations; } } +let mode_waiting_for_server = new Mode('waiting_for_server', false, false); let mode_login = new Mode('login', true, false); let mode_chat = new Mode('chat', true, false); let mode_annotate = new Mode('annotate', true, true); @@ -172,7 +178,7 @@ let mode_study = new Mode('study', false, true); let mode_edit = new Mode('edit', false, false); let tui = { - mode: mode_login, + mode: mode_waiting_for_server, log: [], input_prompt: '> ', input: '', @@ -184,7 +190,11 @@ let tui = { init: function() { this.recalc_input_lines(); this.height_header = this.height_turn_line + this.height_mode_line; - this.log_msg("Please enter your username:"); + this.log_msg("@ waiting for server connection ..."); + }, + init_login: function() { + this.log_msg("@ please enter your username:"); + this.switch_mode(mode_login); }, switch_mode: function(mode, keep_pos=false) { if (mode == mode_study && !keep_pos) { @@ -404,8 +414,9 @@ server.websocket.onmessage = function (event) { tui.log_msg('@ ' + tokens[1]); tui.refresh(); } else if (tokens[0] === 'LOGIN_OK') { - tui.log_msg('@ ' + tokens[1]); + server.send(['GET_GAMESTATE']); tui.log_help(); + tui.log_msg('@ ' + tokens[1]); tui.switch_mode(mode_chat); } else if (tokens[0] === 'ANNOTATION') { let position = parser.parse_yx(tokens[1]);