home · contact · privacy
Add player-identifying meta characters next to @ symbols.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 14 Nov 2020 00:36:30 +0000 (01:36 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 14 Nov 2020 00:36:30 +0000 (01:36 +0100)
plomrogue/commands.py
plomrogue/game.py
rogue_chat_curses.py
rogue_chat_nocanvas_monochrome.html

index 1c59abfd0b4ca9e4bcb82351297cf1bab59c321b..229285fb8c7f291ff02458367b11e40f89cdb6a9 100644 (file)
@@ -82,6 +82,7 @@ def cmd_LOGIN(game, nick, connection_id):
     t = game.thing_types['Player'](game)
     t.position = YX(game.map.size.y // 2, game.map.size.x // 2)
     game.things += [t]  # TODO refactor into Thing.__init__?
+    t.player_char = game.get_next_player_char()
     game.sessions[connection_id] = t.id_
     game.io.send('LOGIN_OK', connection_id)
     t.nickname = nick
index 1ffbf1acfa186f900d96a8252bd5db58dd5fa0a8..29e2de15fe605f92f11cebc967815927ea9b7fd8 100755 (executable)
@@ -4,6 +4,7 @@ from plomrogue.errors import GameError, PlayError
 from plomrogue.io import GameIO
 from plomrogue.misc import quote
 from plomrogue.mapping import YX, MapGeometrySquare, Map
+import string
 
 
 
@@ -48,6 +49,8 @@ class Game(GameBase):
         self.map_control_passwords = {}
         self.annotations = {}
         self.portals = {}
+        self.player_chars = string.digits + string.ascii_letters
+        self.player_char_i = -1
         if os.path.exists(self.io.save_file):
             if not os.path.isfile(self.io.save_file):
                 raise GameError('save file path refers to non-file')
@@ -76,7 +79,6 @@ class Game(GameBase):
         return True
 
     def get_string_options(self, string_option_type):
-        import string
         if string_option_type == 'direction':
             return self.map_geometry.get_directions()
         elif string_option_type == 'char':
@@ -110,6 +112,9 @@ class Game(GameBase):
                 if hasattr(t, 'nickname'):
                     self.io.send('THING_NAME %s %s' % (t.id_,
                                                        quote(t.nickname)), c_id)
+                if hasattr(t, 'player_char'):
+                    self.io.send('THING_CHAR %s %s' % (t.id_,
+                                                       quote(t.player_char)), c_id)
             for yx in [yx for yx in self.portals
                        if player.fov_stencil[yx] == '.']:
                 self.io.send('PORTAL %s %s' % (yx, quote(self.portals[yx])), c_id)
@@ -187,6 +192,12 @@ class Game(GameBase):
             return 1
         return max([t.id_ for t in self.things]) + 1
 
+    def get_next_player_char(self):
+        self.player_char_i += 1
+        if self.player_char_i >= len(self.player_chars):
+            self.player_char_i = 0
+        return self.player_chars[self.player_char_i]
+
     def save(self):
 
       def write(f, msg):
index 3b110bae0b091dff9e8967f60fce7e8584961741..22ebc01aa526831a9c077c1e7f49bb19e213982d 100755 (executable)
@@ -87,6 +87,12 @@ def cmd_THING_NAME(game, thing_id, name):
         t.name = name
 cmd_THING_NAME.argtypes = 'int:nonneg string'
 
+def cmd_THING_CHAR(game, thing_id, c):
+    t = game.get_thing(thing_id)
+    if t:
+        t.player_char = c
+cmd_THING_CHAR.argtypes = 'int:nonneg char'
+
 def cmd_MAP(game, geometry, size, content):
     map_geometry_class = globals()['MapGeometry' + geometry]
     game.map_geometry = map_geometry_class(size)
@@ -183,6 +189,7 @@ class Game(GameBase):
         self.register_command(cmd_THING)
         self.register_command(cmd_THING_TYPE)
         self.register_command(cmd_THING_NAME)
+        self.register_command(cmd_THING_CHAR)
         self.register_command(cmd_MAP)
         self.register_command(cmd_MAP_CONTROL)
         self.register_command(cmd_PORTAL)
@@ -445,7 +452,10 @@ class TUI:
                 info = 'TERRAIN: %s\n' % self.game.map_content[pos_i]
                 for t in self.game.things:
                     if t.position == self.explorer:
-                        info += 'THING: %s' % t.type_
+                        info += 'THING: %s / %s' % (t.type_,
+                                                    self.game.thing_types[t.type_])
+                        if hasattr(t, 'player_char'):
+                            info += t.player_char
                         if hasattr(t, 'name'):
                             info += ' (name: %s)' % t.name
                         info += '\n'
@@ -497,10 +507,12 @@ class TUI:
                 used_positions = []
                 for t in self.game.things:
                     symbol = self.game.thing_types[t.type_]
+                    meta_char = ' '
+                    if hasattr(t, 'player_char'):
+                        meta_char = t.player_char
                     if t.position in used_positions:
-                        map_lines_split[t.position.y][t.position.x] = symbol + '+'
-                    else:
-                        map_lines_split[t.position.y][t.position.x] = symbol + ' '
+                        meta_char = '+'
+                    map_lines_split[t.position.y][t.position.x] = symbol + meta_char
                     used_positions += [t.position]
             if self.mode.shows_info:
                 map_lines_split[self.explorer.y][self.explorer.x] = '??'
index 4956cbdc3beccb39222fc26f571462cd4482c4a1..c0ee072d7d634fcd2872cdf0c41f0b099a801b31 100644 (file)
@@ -214,6 +214,11 @@ let server = {
             if (t) {
                 t.name_ = tokens[2];
             };
+        } else if (tokens[0] === 'THING_CHAR') {
+            let t = game.get_thing(tokens[1], false);
+            if (t) {
+                t.player_char = tokens[2];
+            };
         } else if (tokens[0] === 'TASKS') {
             game.tasks = tokens[1].split(',')
         } else if (tokens[0] === 'THING_TYPE') {
@@ -453,11 +458,14 @@ let tui = {
         for (const thing_id in game.things) {
             let t = game.things[thing_id];
             let symbol = game.thing_types[t.type_];
+            let meta_char = ' ';
+            if (t.player_char) {
+                meta_char = t.player_char;
+            }
             if (used_positions.includes(t.position.toString())) {
-                map_lines_split[t.position[0]][t.position[1]] = symbol + '+';
-            } else {
-                map_lines_split[t.position[0]][t.position[1]] = symbol + ' ';
+                meta_char = '+';
             };
+            map_lines_split[t.position[0]][t.position[1]] = symbol + meta_char;
             used_positions.push(t.position.toString());
         };
     }
@@ -714,7 +722,11 @@ let explorer = {
         for (let t_id in game.things) {
              let t = game.things[t_id];
              if (t.position[0] == this.position[0] && t.position[1] == this.position[1]) {
-                 info += "THING: " + t.type_;
+                 let symbol = game.thing_types[t.type_];
+                 info += "THING: " + t.type_ + " / " + symbol;
+                 if (t.player_char) {
+                     info += t.player_char;
+                 };
                  if (t.name_) {
                      info += " (name: " + t.name_ + ")";
                  }