From 021e4276cce114de08c0ce3c5e781ffc2184d4ee Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 31 Oct 2020 11:17:03 +0100
Subject: [PATCH] Refactor key movement initialization.

---
 new2/rogue_chat_nocanvas_monochrome.html | 33 ++++++++++++------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html
index ffe0132..754021f 100644
--- a/new2/rogue_chat_nocanvas_monochrome.html
+++ b/new2/rogue_chat_nocanvas_monochrome.html
@@ -200,17 +200,27 @@ let tui = {
   height_turn_line: 1,
   height_mode_line: 1,
   height_input: 1,
-  key_up: 'w',
-  key_down: 's',
-  key_left: 'a',
-  key_right: 'd',
-  movement_keys_desc: 'w, a, s, d',
   init: function() {
       this.inputEl = document.getElementById("input");
       this.inputEl.focus();
       this.recalc_input_lines();
       this.height_header = this.height_turn_line + this.height_mode_line;
       this.log_msg("@ waiting for server connection ...");
+      this.init_wasd();
+  },
+  init_wasd: function() {
+    if (wasd_selector.value == 'w, a, s, d') {
+        tui.key_up = 'w';
+        tui.key_down = 's';
+        tui.key_left = 'a';
+        tui.key_right = 'd';
+    } else if (wasd_selector.value == 'arrow keys') {
+        tui.key_up = 'ArrowUp';
+        tui.key_down = 'ArrowDown';
+        tui.key_left = 'ArrowLeft';
+        tui.key_right = 'ArrowRight';
+    };
+    tui.movement_keys_desc = wasd_selector.value;
   },
   init_login: function() {
       this.log_msg("@ please enter your username:");
@@ -580,18 +590,7 @@ tui.inputEl.addEventListener('keydown', (event) => {
 }, false);
 
 wasd_selector.addEventListener('input', function() {
-    if (wasd_selector.value == 'w, a, s, d') {
-        tui.key_up = 'w';
-        tui.key_down = 's';
-        tui.key_left = 'a';
-        tui.key_right = 'd';
-    } else if (wasd_selector.value == 'arrow keys') {
-        tui.key_up = 'ArrowUp';
-        tui.key_down = 'ArrowDown';
-        tui.key_left = 'ArrowLeft';
-        tui.key_right = 'ArrowRight';
-    };
-    tui.movement_keys_desc = wasd_selector.value;
+    tui.init_wasd();
 }, false);
 rows_selector.addEventListener('input', function() {
     terminal.initialize();
-- 
2.30.2