From: Christian Heller Date: Tue, 27 Oct 2020 02:34:42 +0000 (+0100) Subject: Simplify log_msg. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/condition_descriptions?a=commitdiff_plain;h=f571ed54e432ba540b4a1b2a4ad63f71aa91ef40;p=plomrogue2-experiments Simplify log_msg. --- diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 6fee53c..82df80c 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -176,18 +176,18 @@ let tui = { terminal.drawBox(terminal.rows - 1, terminal.cols / 2, 1, terminal.cols / 2); terminal.write(terminal.rows - 1, terminal.cols / 2, chat.input_line); }, - log_msg: function(msg, indent=0) { - let line_length = (terminal.cols / 2) - indent; + log_msg: function(msg) { + let line_length = (terminal.cols / 2); let chunk = ""; for (let i = 0, x = 0; i < msg.length; i++, x++) { if (x >= line_length) { - chat.history.unshift(' '.repeat(indent) + chunk); + chat.history.unshift(chunk); chunk = ""; x = 0; }; chunk += msg[i]; } - chat.history.unshift(' '.repeat(indent) + chunk); + chat.history.unshift(chunk); while (chat.history.length > terminal.rows - 2) { chat.history.pop(); }; @@ -198,25 +198,25 @@ let tui = { }, log_help: function() { tui.log_msg(""); - tui.log_msg("HELP", 1); - tui.log_msg("chat mode commands:", 1); + tui.log_msg("HELP"); + tui.log_msg("chat mode commands:"); tui.log_msg(""); - tui.log_msg("/login USER - register as USER", 3); - tui.log_msg("/msg USER TEXT - send TEXT to USER", 3); - tui.log_msg("/help - show this help", 3); - tui.log_msg("/play - switch to play mode", 3); + tui.log_msg("/login USER - register as USER"); + tui.log_msg("/msg USER TEXT - send TEXT to USER"); + tui.log_msg("/help - show this help"); + tui.log_msg("/play - switch to play mode"); tui.log_msg(""); - tui.log_msg("play mode commands:", 1); - tui.log_msg("w, a, s, d - move avatar", 3); - tui.log_msg("f - flatten surroundings", 3); - tui.log_msg("e - write following ASCII character", 3); - tui.log_msg("c - switch to chat mode", 3); - tui.log_msg("? - switch to explore mode", 3); + tui.log_msg("play mode commands:"); + tui.log_msg("w, a, s, d - move avatar"); + tui.log_msg("f - flatten surroundings"); + tui.log_msg("e - write following ASCII character"); + tui.log_msg("c - switch to chat mode"); + tui.log_msg("? - switch to explore mode"); tui.log_msg(""); - tui.log_msg("explore mode commands:", 1); - tui.log_msg("w, a, s, d - move question mark", 3); - tui.log_msg("c - switch to chat mode", 3); - tui.log_msg("p - switch to play mode", 3); + tui.log_msg("explore mode commands:"); + tui.log_msg("w, a, s, d - move question mark"); + tui.log_msg("c - switch to chat mode"); + tui.log_msg("p - switch to play mode"); tui.log_msg(""); }, draw_info: function() { @@ -267,27 +267,27 @@ websocket.onmessage = function (event) { tui.draw_turn_line(); tui.draw_map(); tui.refresh(); - } else if (tokens[0] === 'LOG') { - tui.log_msg(tokens[1], 1); + } else if (tokens[0] === 'CHAT') { + tui.log_msg('# ' + tokens[1], 1); tui.refresh(); } else if (tokens[0] === 'PLAYER_ID') { game.player_id = parseInt(tokens[1]); } else if (tokens[0] === 'META') { - tui.log_msg(tokens[1]); + tui.log_msg('@ ' + tokens[1]); tui.refresh(); } else if (tokens[0] === 'UNHANDLED_INPUT') { - tui.log_msg('unknown command'); + tui.log_msg('? unknown command'); tui.refresh(); } else if (tokens[0] === 'ARGUMENT_ERROR') { - tui.log_msg('syntax error: ' + tokens[1]); + tui.log_msg('? syntax error: ' + tokens[1]); tui.refresh(); } else if (tokens[0] === 'GAME_ERROR') { - tui.log_msg('game error: ' + tokens[1]); + tui.log_msg('? game error: ' + tokens[1]); tui.refresh(); } else if (tokens[0] === 'PONG') { console.log('PONG'); } else { - tui.log_msg('unhandled input: ' + event.data); + tui.log_msg('? unhandled input: ' + event.data); tui.refresh(); } } @@ -342,16 +342,17 @@ document.addEventListener('keydown', (event) => { if (tokens.length > 1) { websocket.send('LOGIN ' + quote(tokens[1])); } else { - tui.log_msg('need login name'); + tui.log_msg('? need login name'); } } else if (tokens[0] == '/msg') { if (tokens.length > 2) { + // FIXME only sends first word websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(tokens[2])); } else { - tui.log_msg('need message target and message'); + tui.log_msg('? need message target and message'); } } else { - tui.log_msg('unknown command'); + tui.log_msg('? unknown command'); } } else { websocket.send('ALL ' + quote(chat.input_line));