home · contact · privacy
Make sign design sizes variable.
[plomrogue2] / rogue_chat.html
index 1847c0904ec9f7452efc718fa9265521e0bd7686..5338e9daf323f1f8aef596ea5634407d2182d391 100644 (file)
@@ -933,12 +933,15 @@ let tui = {
             this.log_msg(i + ': ' + direction);
         };
     } else if (this.mode.name == 'enter_design') {
-        this.log_msg('@ The design you enter must be '
-                     + game.player.carrying.design[0][0] + ' lines of max '
-                     + game.player.carrying.design[0][1] + ' characters width each');
         if (game.player.carrying.type_ == 'Hat') {
+            this.log_msg('@ The design you enter must be '
+                         + game.player.carrying.design[0][0] + ' lines of max '
+                         + game.player.carrying.design[0][1] + ' characters width each');
             this.log_msg('@ Legal characters: ' + game.players_hat_chars);
             this.log_msg('@ (Eat cookies to extend the ASCII characters available for drawing.)');
+        } else {
+            this.log_msg('@ Width of first line determines maximum width for remaining design')
+            this.log_msg('@ Finish design by entering an empty line (multiple space characters do not count as empty)')
         }
     } else if (this.mode.name == 'command_thing') {
         server.send(['TASK:COMMAND', 'HELP']);
@@ -1078,31 +1081,55 @@ let tui = {
       this.inputEl.value = "";
       this.switch_mode('play');
   },
-  enter_ascii_art: function(command, height, width, with_pw=false) {
-      if (this.inputEl.value.length > width) {
-          this.log_msg('? wrong input length, must be max ' + width + '; try again');
-          return;
-      } else if (this.inputEl.value.length < width) {
-          while (this.inputEl.value.length < width) {
-              this.inputEl.value += ' ';
-          }
-      }
-      this.log_msg('  ' + this.inputEl.value);
-      this.full_ascii_draw += this.inputEl.value;
-      this.ascii_draw_stage += 1;
-      if (this.ascii_draw_stage < height) {
-          this.restore_input_values();
-      } else {
-          if (with_pw) {
-              server.send([command, this.full_ascii_draw, this.password]);
-          } else {
-              server.send([command, this.full_ascii_draw]);
-          }
-          this.full_ascii_draw = '';
-          this.ascii_draw_stage = 0;
-          this.inputEl.value = '';
-          this.switch_mode('edit');
-      }
+    enter_ascii_art: function(command, height, width, with_pw=false, with_size=false) {
+        if (with_size && this.ascii_draw_stage == 0) {
+            width = this.inputEl.value.length;
+            if (width > 36) {
+                this.log_msg('? wrong input length, must be max 36; try again');
+                return;
+            }
+            if (width != game.player.carrying.design[0][1]) {
+                game.player.carrying.design[1] = '';
+                game.player.carrying.design[0][1] = width;
+            }
+        } else if (this.inputEl.value.length > width) {
+            this.log_msg('? wrong input length, must be max ' + width + '; try again');
+            return;
+        }
+        this.log_msg('  ' + this.inputEl.value);
+        if (with_size && ['', ' '].includes(this.inputEl.value) && this.ascii_draw_stage > 0) {
+          height = this.ascii_draw_stage;
+        } else {
+            if (with_size) {
+                height = this.ascii_draw_stage + 2;
+            }
+            while (this.inputEl.value.length < width) {
+                this.inputEl.value += ' ';
+            }
+            this.full_ascii_draw += this.inputEl.value;
+        }
+        if (with_size) {
+            game.player.carrying.design[0][0] = height;
+        }
+        this.ascii_draw_stage += 1;
+        if (this.ascii_draw_stage < height) {
+            this.restore_input_values();
+        } else {
+            if (with_pw && with_size) {
+                server.send([command + '_SIZE',
+                             unparser.to_yx(game.player.carrying.design[0]),
+                             this.password]);
+            }
+            if (with_pw) {
+                server.send([command, this.full_ascii_draw, this.password]);
+            } else {
+                server.send([command, this.full_ascii_draw]);
+            }
+            this.full_ascii_draw = '';
+            this.ascii_draw_stage = 0;
+            this.inputEl.value = '';
+            this.switch_mode('edit');
+        }
   },
   draw_map: function() {
     if (!game.turn_complete && this.map_lines.length == 0) {
@@ -1570,8 +1597,12 @@ let explorer = {
             if (t.design) {
                 const line_length = t.design[0][1];
                 info += '-'.repeat(line_length + 4) + '\n';
-                const regexp = RegExp('.{1,' + line_length + '}', 'g');
-                const lines = t.design[1].match(regexp);
+                console.log(line_length)
+                let lines = ['']
+                if (line_length > 0) {
+                    const regexp = RegExp('.{1,' + line_length + '}', 'g');
+                    lines = t.design[1].match(regexp);
+                }
                 for (const line of lines) {
                     info += '| ' + line + ' |\n';
                 }
@@ -1644,9 +1675,15 @@ tui.inputEl.addEventListener('keydown', (event) => {
     } else if (tui.mode.name == 'enter_face' && event.key == 'Enter') {
         tui.enter_ascii_art('PLAYER_FACE', 3, 6);
     } else if (tui.mode.name == 'enter_design' && event.key == 'Enter') {
-        tui.enter_ascii_art('THING_DESIGN',
-                            game.player.carrying.design[0][0],
-                            game.player.carrying.design[0][1], true);
+        if (game.player.carrying.type_ == 'Hat') {
+            tui.enter_ascii_art('THING_DESIGN',
+                                game.player.carrying.design[0][0],
+                                game.player.carrying.design[0][1], true);
+        } else {
+            tui.enter_ascii_art('THING_DESIGN',
+                                game.player.carrying.design[0][0],
+                                game.player.carrying.design[0][1], true, true);
+        }
     } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') {
         server.send(['TASK:COMMAND', tui.inputEl.value]);
         tui.inputEl.value = "";