From: Christian Heller Date: Sat, 19 Dec 2020 01:46:10 +0000 (+0100) Subject: Add writable signs. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7B%20web_path%20%7D%7D/decks/todo?a=commitdiff_plain;h=69849fbd3ecdf9f937d1353a8ffbd96bfb44b742;p=plomrogue2 Add writable signs. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 9cdab97..8422161 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -383,6 +383,37 @@ def cmd_THING_HAT_DESIGN(game, thing_id, design): t.design = design cmd_THING_HAT_DESIGN.argtypes = 'int:pos string' +def cmd_THING_DESIGN(game, design, pw, connection_id): + player = game.get_player(connection_id) + if not player: + raise GameError('need to be logged in for this') + if not player.carrying: + raise GameError('need to carry a thing to re-draw it') + if not game.can_do_thing_with_pw(player.carrying, pw): + raise GameError('wrong password for thing') + if not hasattr(player.carrying, 'design'): + raise GameError('carried thing not designable') + size = player.carrying.design_size + if len(design) != size.y * size.x: + raise GameError('design for carried thing of wrong length') + player.carrying.design = design + game.changed = True + game.record_change(player.carrying.position, 'other') +cmd_THING_DESIGN.argtypes = 'string string' + +def cmd_GOD_THING_DESIGN(game, thing_id, design): + t = game.get_thing(thing_id) + if not t: + raise GameError('thing of ID %s not found' % thing_id) + if not hasattr(t, 'design'): + raise GameError('thing of ID %s not designable' % thing_id) + if len(design) != t.design_size.y * t.design_size.x: + raise GameError('design for thing of ID %s of wrong length' % thing_id) + t.design = design +cmd_GOD_THING_DESIGN.argtypes = 'int:pos string' + +# TODO: refactor similar god and player commands + def cmd_THING_DOOR_KEY(game, key_id, door_id): key = game.get_thing(key_id) if not key: diff --git a/plomrogue/game.py b/plomrogue/game.py index 088db9d..cfc4271 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -306,9 +306,13 @@ class Game(GameBase): quote(t.thing_char)), c_id) if hasattr(t, 'installable') and not t.portable: self.io.send('THING_INSTALLED %s' % (t.id_), c_id) - if hasattr(t, 'design'): + if t.type_ == 'Hat': self.io.send('THING_HAT %s %s' % (t.id_, quote(t.design)), c_id) + elif hasattr(t, 'design'): + self.io.send('THING_DESIGN %s %s %s' + % (t.id_, t.design_size, quote(t.design)), + c_id) for t in [t for t in player.seen_things if t.carrying]: # send this last so all carryable things are already created self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_), @@ -560,6 +564,8 @@ class Game(GameBase): elif t.type_ == 'Hat': write(f, 'THING_HAT_DESIGN %s %s' % (t.id_, quote(t.design))) + elif hasattr(t, 'design'): + write(f, 'GOD_THING_DESIGN %s %s' % (t.id_, quote(t.design))) elif t.type_ == 'MusicPlayer': write(f, 'THING_MUSICPLAYER_SETTINGS %s %s %s %s' % (t.id_, int(t.playing), t.playlist_index, int(t.repeat))) diff --git a/plomrogue/things.py b/plomrogue/things.py index 2c3f540..46ea770 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -174,6 +174,21 @@ class ThingInstallable(Thing): +class Thing_SignSpawner(ThingSpawner): + child_type = 'Sign' + + + +class Thing_Sign(ThingInstallable): + symbol_hint = '?' + design_size = YX(16, 36) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.design = 'x' * self.design_size.y * self.design_size.x + + + class Thing_DoorSpawner(ThingSpawner): child_type = 'Door' @@ -276,6 +291,7 @@ class Thing_Hat(Thing): design = ' +--+ ' + ' | | ' + '======' spinnable = True cookable = True + design_size = YX(3, 6) def spin(self): new_design = '' diff --git a/rogue_chat.html b/rogue_chat.html index 82bfbed..f7d0234 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -73,6 +73,7 @@ terminal rows: + @@ -110,6 +111,7 @@ terminal rows:
  • +
  • @@ -176,13 +178,18 @@ let mode_helps = { }, 'enter_face': { 'short': 'edit face', - 'intro': '@ enter face line (enter nothing to abort):', + 'intro': '@ enter face line:', 'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.' }, + 'enter_design': { + 'short': 'edit design', + 'intro': '@ enter design:', + 'long': 'Enter design for carried thing as ASCII art.' + }, 'enter_hat': { 'short': 'edit hat', - 'intro': '@ enter hat line (enter nothing to abort):', - 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..' + 'intro': '@ enter hat line:', + 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.' }, 'write': { 'short': 'edit tile', @@ -511,6 +518,9 @@ let server = { } else if (tokens[0] === 'THING_HAT') { let t = game.get_thing_temp(tokens[1]); t.hat = tokens[2]; + } else if (tokens[0] === 'THING_DESIGN') { + let t = game.get_thing_temp(tokens[1]); + t.design = [parser.parse_yx(tokens[2]), tokens[3]]; } else if (tokens[0] === 'THING_CHAR') { let t = game.get_thing_temp(tokens[1]); t.thing_char = tokens[2]; @@ -711,6 +721,7 @@ let tui = { mode_drop_thing: new Mode('drop_thing', true), mode_enter_face: new Mode('enter_face', true), mode_enter_hat: new Mode('enter_hat', true), + mode_enter_design: new Mode('enter_design', true), mode_admin_enter: new Mode('admin_enter', true), mode_admin: new Mode('admin'), mode_control_pw_pw: new Mode('control_pw_pw', true), @@ -749,8 +760,9 @@ let tui = { this.mode_control_tile_draw.available_modes = ["admin_enter"] this.mode_control_tile_draw.available_actions = ["toggle_tile_draw"]; this.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing", - "password", "chat", "study", "play", - "admin_enter", "enter_face", "enter_hat"] + "enter_design", "password", "chat", "study", + "play", "admin_enter", "enter_face", + "enter_hat"] this.mode_edit.available_actions = ["move", "flatten", "install", "toggle_map_mode"] this.inputEl = document.getElementById("input"); @@ -822,6 +834,9 @@ let tui = { return fail('not carrying anything droppable'); } else if (mode_name == 'enter_hat' && !game.player.hat) { return fail('not wearing hat to edit', 'edit'); + } else if (mode_name == 'enter_design' && (!game.player.carrying + || !game.player.carrying.design)) { + return fail('not carrying designable to edit', 'edit'); } if (mode_name == 'admin_enter' && this.is_admin) { mode_name = 'admin'; @@ -891,7 +906,6 @@ let tui = { directed_moves['DOWNRIGHT'] = [1, 0]; } } - console.log(directed_moves); let select_range = {}; for (const direction in directed_moves) { const move = directed_moves[direction]; @@ -979,6 +993,11 @@ let tui = { } else if (this.mode.name == 'enter_hat') { this.inputEl.value = game.player.hat.slice(start, end); } + } else if (this.mode.name == 'enter_design') { + const width = game.player.carrying.design[0][1]; + const start = this.ascii_draw_stage * width; + const end = (this.ascii_draw_stage + 1) * width; + this.inputEl.value = game.player.carrying.design[1].slice(start, end); } }, recalc_input_lines: function() { @@ -1068,22 +1087,26 @@ let tui = { this.inputEl.value = ""; this.switch_mode('play'); }, - enter_ascii_art: function(command) { - if (this.inputEl.value.length > 6) { - this.log_msg('? wrong input length, must be max 6; try again'); + 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 < 6) { - while (this.inputEl.value.length < 6) { + } 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 < 3) { + if (this.ascii_draw_stage < height) { this.restore_input_values(); } else { - server.send([command, this.full_ascii_draw]); + 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 = ''; @@ -1502,6 +1525,21 @@ let explorer = { info_to_cache += t.face.slice(6, 12) + '\n'; info_to_cache += t.face.slice(12, 18) + '\n'; } + if (t.design) { + const line_length = t.design[0][1]; + if (t.type_ == 'Sign') { + info_to_cache += '-'.repeat(line_length + 4) + '\n'; + } + const regexp = RegExp('.{1,' + line_length + '}', 'g'); + const lines = t.design[1].match(regexp); + console.log(lines); + for (const line of lines) { + info_to_cache += '| ' + line + ' |\n'; + } + if (t.type_ == 'Sign') { + info_to_cache += '-'.repeat(line_length + 4) + '\n'; + } + } } } let terrain_char = game.map[position_i] @@ -1599,9 +1637,13 @@ tui.inputEl.addEventListener('keydown', (event) => { server.send(['LOGIN', tui.inputEl.value]); tui.inputEl.value = ""; } else if (tui.mode.name == 'enter_face' && event.key == 'Enter') { - tui.enter_ascii_art('PLAYER_FACE'); + tui.enter_ascii_art('PLAYER_FACE', 3, 6); } else if (tui.mode.name == 'enter_hat' && event.key == 'Enter') { - tui.enter_ascii_art('PLAYER_HAT'); + tui.enter_ascii_art('PLAYER_HAT', 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); } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') { server.send(['TASK:COMMAND', tui.inputEl.value]); tui.inputEl.value = ""; diff --git a/rogue_chat.py b/rogue_chat.py index 5c07276..71a94c7 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -17,7 +17,8 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_GOD_PLAYERS_HAT_CHARS, cmd_PLAYER_HAT, cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY, cmd_THING_CRATE_ITEM, cmd_MAP_CONTROL_PRESETS, - cmd_THING_SPAWNPOINT_CREATED) + cmd_THING_SPAWNPOINT_CREATED, cmd_GOD_THING_DESIGN, + cmd_THING_DESIGN) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR, Task_INTOXICATE, Task_COMMAND, Task_INSTALL, @@ -30,7 +31,8 @@ from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner, Thing_Cookie, Thing_CookieSpawner, Thing_Psychedelic, Thing_PsychedelicSpawner, Thing_DoorKey, Thing_Crate, Thing_CrateSpawner, Thing_Stimulant, - Thing_StimulantSpawner) + Thing_StimulantSpawner, Thing_Sign, + Thing_SignSpawner) from plomrogue.config import config game = Game(config['savefile']) @@ -76,6 +78,8 @@ game.register_command(cmd_PLAYER_HAT) game.register_command(cmd_THING_HAT_DESIGN) game.register_command(cmd_THING_DOOR_KEY) game.register_command(cmd_THING_CRATE_ITEM) +game.register_command(cmd_THING_DESIGN) +game.register_command(cmd_GOD_THING_DESIGN) game.register_command(cmd_MAP_CONTROL_PRESETS) game.register_command(cmd_THING_SPAWNPOINT_CREATED) game.register_task(Task_WAIT) @@ -113,6 +117,8 @@ game.register_thing_type(Thing_Crate) game.register_thing_type(Thing_CrateSpawner) game.register_thing_type(Thing_Stimulant) game.register_thing_type(Thing_StimulantSpawner) +game.register_thing_type(Thing_Sign) +game.register_thing_type(Thing_SignSpawner) game.read_savefile() game.io.start_loop() for port in config['servers']: diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index f7ac8cf..a6471ee 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -53,13 +53,18 @@ mode_helps = { }, 'enter_face': { 'short': 'edit face', - 'intro': '@ enter face line (enter nothing to abort):', + 'intro': '@ enter face line:', 'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom..' }, + 'enter_design': { + 'short': 'edit design', + 'intro': '@ enter design:', + 'long': 'Enter design for carried thing as ASCII art.' + }, 'enter_hat': { 'short': 'edit hat', - 'intro': '@ enter hat line (enter nothing to abort):', - 'long': 'Draw your face as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.' + 'intro': '@ enter hat line:', + 'long': 'Draw your hat as ASCII art. The string you enter must be 18 characters long, and will be divided on display into 3 lines of 6 characters each, from top to bottom. Eat cookies to extend the ASCII characters available for drawing.' }, 'write': { 'short': 'edit tile', @@ -248,6 +253,11 @@ def cmd_THING_HAT(game, thing_id, hat): t.hat = hat cmd_THING_HAT.argtypes = 'int:pos string' +def cmd_THING_DESIGN(game, thing_id, size, design): + t = game.get_thing_temp(thing_id) + t.design = [size, design] +cmd_THING_DESIGN.argtypes = 'int:pos yx_tuple string' + def cmd_THING_CHAR(game, thing_id, c): t = game.get_thing_temp(thing_id) t.thing_char = c @@ -392,6 +402,7 @@ class Game(GameBase): self.register_command(cmd_THING_CHAR) self.register_command(cmd_THING_FACE) self.register_command(cmd_THING_HAT) + self.register_command(cmd_THING_DESIGN) self.register_command(cmd_THING_CARRYING) self.register_command(cmd_THING_INSTALLED) self.register_command(cmd_TERRAIN) @@ -502,6 +513,7 @@ class TUI: mode_drop_thing = Mode('drop_thing', has_input_prompt=True) mode_enter_face = Mode('enter_face', has_input_prompt=True) mode_enter_hat = Mode('enter_hat', has_input_prompt=True) + mode_enter_design = Mode('enter_design', has_input_prompt=True) is_admin = False tile_draw = False @@ -524,7 +536,7 @@ class TUI: "toggle_tile_draw"] self.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing", "enter_face", "enter_hat", - "password", + "enter_design", "password", "chat", "study", "play", "admin_enter"] self.mode_edit.available_actions = ["move", "flatten", "install", "toggle_map_mode"] @@ -558,6 +570,7 @@ class TUI: 'flatten': 'F', 'switch_to_enter_face': 'f', 'switch_to_enter_hat': 'H', + 'switch_to_enter_design': 'D', 'switch_to_take_thing': 'z', 'switch_to_drop_thing': 'u', 'teleport': 'p', @@ -672,6 +685,11 @@ class TUI: self.input_ = self.game.player.face[start:end] elif self.mode.name == 'enter_hat': self.input_ = self.game.player.hat[start:end] + elif self.mode.name == 'enter_design': + width = self.game.player.carrying.design[0].x + start = self.ascii_draw_stage * width + end = (self.ascii_draw_stage + 1) * width + self.input_ = self.game.player.carrying.design[1][start:end] def send_tile_control_command(self): self.send('SET_TILE_CONTROL %s %s' % @@ -712,6 +730,10 @@ class TUI: return fail('not carrying anything droppable') if mode_name == 'enter_hat' and not hasattr(self.game.player, 'hat'): return fail('not wearing hat to edit', 'edit') + if mode_name == 'enter_design' and\ + (not self.game.player.carrying or + not hasattr(self.game.player.carrying, 'design')): + return fail('not carrying designable to edit', 'edit') if mode_name == 'admin_enter' and self.is_admin: mode_name = 'admin' self.mode = getattr(self, 'mode_' + mode_name) @@ -824,6 +846,18 @@ class TUI: info_to_cache += t.face[0:6] + '\n' info_to_cache += t.face[6:12] + '\n' info_to_cache += t.face[12:18] + '\n' + if hasattr(t, 'design'): + import textwrap + line_length = t.design[0].x + wrapper = textwrap.TextWrapper(drop_whitespace=False, + width=line_length) + lines = wrapper.wrap(t.design[1]) + if t.type_ == 'Sign': + info_to_cache += '-' * (line_length + 4) + '\n' + for line in lines: + info_to_cache += '| %s |\n' % line + if t.type_ == 'Sign': + info_to_cache += '-' * (line_length + 4) + '\n' terrain_char = self.game.map_content[pos_i] terrain_desc = '?' if terrain_char in self.game.terrains: @@ -1116,19 +1150,24 @@ class TUI: self.input_ = '' self.switch_mode('play') - def enter_ascii_art(command): - if len(self.input_) > 6: - self.log_msg('? wrong input length, must be max 6; try again') + def enter_ascii_art(command, height, width, with_pw=False): + if len(self.input_) > width: + self.log_msg('? wrong input length, ' + 'must be max %s; try again' % width) return - if len(self.input_) < 6: - self.input_ += ' ' * (6 - len(self.input_)) + if len(self.input_) < width: + self.input_ += ' ' * (width - len(self.input_)) self.log_msg(' ' + self.input_) self.full_ascii_draw += self.input_ self.ascii_draw_stage += 1 - if self.ascii_draw_stage < 3: + if self.ascii_draw_stage < height: self.restore_input_values() else: - self.send('%s %s' % (command, quote(self.full_ascii_draw))) + if with_pw: + self.send('%s %s %s' % (command, quote(self.full_ascii_draw), + quote(self.password))) + else: + self.send('%s %s' % (command, quote(self.full_ascii_draw))) self.full_ascii_draw = "" self.ascii_draw_stage = 0 self.input_ = "" @@ -1245,9 +1284,13 @@ class TUI: self.send('LOGIN ' + quote(self.input_)) self.input_ = "" elif self.mode.name == 'enter_face' and key == '\n': - enter_ascii_art('PLAYER_FACE') + enter_ascii_art('PLAYER_FACE', 3, 6) elif self.mode.name == 'enter_hat' and key == '\n': - enter_ascii_art('PLAYER_HAT') + enter_ascii_art('PLAYER_HAT', 3, 6) + elif self.mode.name == 'enter_design' and key == '\n': + enter_ascii_art('THING_DESIGN', + self.game.player.carrying.design[0].y, + self.game.player.carrying.design[0].x, True) elif self.mode.name == 'take_thing' and key == '\n': pick_selectable('PICK_UP') elif self.mode.name == 'drop_thing' and key == '\n':