Module: Lich::Common::RoomBlock
- Defined in:
- documented/common/room_block.rb
Overview
The Saga-identity stream (Frontend::CLIENT_STRING since #1700) renders a room in the main window as one inline element:
<room><name>[Area, Title] (230008)</name><description>...</description>
<exists>You also see ...</exists><crtrStatus .../><players>Also here: ...</players>
<exits>Obvious paths: <d>north</d>.</exits><extra></extra></room>
where the legacy stream (front ends sending their own Wrayth handshake) sends the roomName style, the roomDesc preset and one line per part. The rewrite targets that legacy layout; how the Saga client itself draws the block was not checked. The room components (room desc/objs/players/exits) are sent in both dialects and stay the parser's source of room state.
Constant Summary collapse
- BLOCK =
A complete block; the body never spans another
, so a block cut off before cannot swallow the next one in a multi-line string. %r{<room>(?<body>(?:(?!<room>).)*?)</room>}m.freeze
- COMPASS_DIRS =
The legacy stream's
value for each exit name the game lists in "Obvious paths:", in the exits line's order. { 'north' => 'n', 'northeast' => 'ne', 'east' => 'e', 'southeast' => 'se', 'south' => 's', 'southwest' => 'sw', 'west' => 'w', 'northwest' => 'nw', 'up' => 'up', 'down' => 'down', 'out' => 'out' }.freeze
- NAME_UID =
The room number the game ends a room name with: "[Area, Title] (230008)".
/\((\d+)\)\s*\z/.freeze
Class Method Summary collapse
-
.compass(exits) ⇒ String
The legacy stream's top-level compass for a room's exit names, in their order:
. -
.legacy_shape(server_string) ⇒ String
Rewrites a
block into the legacy stream's layout, so code written for the legacy stream sees the same shape in both dialects. -
.legacy_shape_with_compass(server_string) ⇒ String
The legacy layout for a front end, which also gets the line the Saga-identity stream no longer sends: the legacy stream followed the exits line of every room view with a top-level compass built from those exits,.
-
.without_description(server_string, room_id:, room_exits:) ⇒ String
Empties the description of every block for the character's own room, keeping the rest of the block as sent:.
Class Method Details
.compass(exits) ⇒ String
The legacy stream's top-level compass for a room's exit names, in their
order:
212 213 214 215 |
# File 'documented/common/room_block.rb', line 212 def compass(exits) dirs = exits.filter_map { |exit| %(<dir value="#{COMPASS_DIRS[exit]}"/>) if COMPASS_DIRS.key?(exit) } "<compass>#{dirs.join}</compass>" end |
.legacy_shape(server_string) ⇒ String
Rewrites a
56 57 58 59 60 |
# File 'documented/common/room_block.rb', line 56 def legacy_shape(server_string) return server_string unless server_string.include?('<room>') server_string.gsub(BLOCK) { legacy_lines(Regexp.last_match(:body)) } end |
.legacy_shape_with_compass(server_string) ⇒ String
The legacy layout for a front end, which also gets the line the Saga-identity stream no longer sends: the legacy stream followed the exits line of every room view with a top-level compass built from those exits,
Obvious paths: <d>north</d>, <d>southeast</d>.
<compass><dir value="n"/><dir value="se"/></compass>
and front ends update their compass (and Frostbite its map) only from that line. Here it ends a line of its own, as the game starts a new line after . Exit names without a compass value are left out; a room without exits gets an empty compass, which clears the last room's.
The game also sends a
Only for the client: scripts, reget and the parser use legacy_shape and never see the compass line.
87 88 89 90 91 92 93 94 |
# File 'documented/common/room_block.rb', line 87 def legacy_shape_with_compass(server_string) return server_string unless server_string.include?('<room>') server_string.gsub(BLOCK) do body = Regexp.last_match(:body) legacy_lines(body, compass: compass(exit_names(body))) end end |
.without_description(server_string, room_id:, room_exits:) ⇒ String
Empties the description of every block for the character's own room, keeping the rest of the block as sent:
<room><name>[Area, Title] (230008)</name><description></description><exists>...
legacy_shape then sends that room's description line without the roomDesc preset, as the legacy stream does while FLAG DESCRIPTION is OFF. A block for another room (a Moon Mage's Locate) keeps its description. A block is the character's room when the room number its name ends with is room_id (XMLData.room_id, from
Only for the client (RoomDescriptionFilter): scripts, reget and the parser keep the description.
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'documented/common/room_block.rb', line 117 def without_description(server_string, room_id:, room_exits:) return server_string unless server_string.include?('<room>') emptied = false out = server_string.gsub(BLOCK) do |block| body = Regexp.last_match(:body) next block unless current_room?(body, exit_names(body), room_id, room_exits) emptied = true block.sub(%r{<description>.*?</description>}m, '<description></description>') end emptied ? out : server_string end |