Class: Lich::Common::Map
- Inherits:
-
Object
- Object
- Lich::Common::Map
- Includes:
- Enumerable
- Defined in:
- documented/common/map/map_dr.rb,
documented/common/map/map_dr.rb,
documented/common/map/map_gs.rb,
documented/common/map/map_gs.rb
Overview
deprecated
Direct Known Subclasses
Constant Summary collapse
- @@loaded =
false- @@load_mutex =
Mutex.new
- @@current_room_mutex =
Mutex.new
- @@fuzzy_room_mutex =
Mutex.new
- @@uids =
{}
Instance Attribute Summary collapse
-
#check_location ⇒ Object
The title of the map room.
-
#climate ⇒ Object
The title of the map room.
-
#description ⇒ Object
The title of the map room.
-
#id ⇒ Object
readonly
The unique identifier for the map room.
-
#image ⇒ Object
The title of the map room.
-
#image_coords ⇒ Object
The title of the map room.
-
#location ⇒ Object
The title of the map room.
-
#paths ⇒ Object
The title of the map room.
-
#room_objects ⇒ Object
The title of the map room.
-
#tags ⇒ Object
The title of the map room.
-
#terrain ⇒ Object
The title of the map room.
-
#timeto ⇒ Object
The title of the map room.
-
#title ⇒ Object
The title of the map room.
-
#uid ⇒ Object
The title of the map room.
-
#unique_loot ⇒ Object
The title of the map room.
-
#wayto ⇒ Object
The title of the map room.
Class Method Summary collapse
-
.[](val) ⇒ Map?
Retrieves a map room by its ID or UID.
-
.clear ⇒ Boolean
Clears all map data and resets the state.
-
.current ⇒ Map?
Retrieves the current map room.
-
.current_or_new ⇒ Map?
Retrieves the current room or creates a new one if it doesn’t exist.
-
.current_room_id ⇒ Integer
Retrieves the current room ID.
-
.current_room_id=(id) ⇒ Integer
Sets the current room ID.
-
.dijkstra(source, destination = nil) ⇒ Array<Integer>, Array<Float>
Performs Dijkstra’s algorithm to find the shortest path.
-
.estimate_time(array) ⇒ Float
Estimates the time to travel through a series of rooms.
-
.findpath(source, destination) ⇒ Array<Integer>?
Finds a path from the source room to the destination.
- .fuzzy_room_id ⇒ Object
-
.get_free_id ⇒ Integer
Retrieves a free ID for a new map room.
-
.get_location ⇒ String?
Retrieves the current location based on the game state.
-
.ids_from_uid(n) ⇒ Array<Integer>
Retrieves room IDs associated with a given UID.
-
.images ⇒ Array<String>
Retrieves unique images from the map rooms.
-
.list ⇒ Array<Map>
Retrieves the list of all map rooms.
-
.load(filename = nil) ⇒ Boolean
Loads map data from files.
-
.load_dat(filename = nil) ⇒ Boolean
Loads map data from a DAT file.
-
.load_json(filename = nil) ⇒ Boolean
Loads map data from a JSON file.
-
.load_uids ⇒ void
Loads UIDs from the current map rooms into the UID mapping.
-
.load_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map.xml") ⇒ Boolean
Loads map data from an XML file.
-
.loaded ⇒ Boolean
Checks if the map has been loaded.
-
.locations ⇒ Array<String>
Retrieves unique locations from the map rooms.
-
.match_current(script) ⇒ Integer
Matches the current room based on the game state.
-
.match_fuzzy ⇒ Integer?
Matches a room using fuzzy logic.
-
.match_multi_ids(ids) ⇒ Integer?
Matches multiple room IDs to find a valid one.
-
.match_no_uid ⇒ Map?
Matches a room without a UID.
-
.previous ⇒ Map?
Retrieves the previous map room.
-
.previous_room_id ⇒ Integer?
Retrieves the previous room ID.
-
.previous_room_id=(id) ⇒ Integer
Sets the previous room ID.
-
.previous_uid ⇒ Integer?
Retrieves the previous room’s UID.
-
.reload ⇒ Boolean
Reloads the map data from the source.
-
.save(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.dat") ⇒ void
Saves the current map data to a DAT file.
-
.save_json(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.json") ⇒ void
Saves the current map data to a JSON file.
-
.save_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.xml") ⇒ void
Saves the current map data to an XML file.
-
.set_current(id) ⇒ Map?
Sets the current map room.
-
.set_fuzzy(id) ⇒ Map?
Sets a fuzzy current room ID.
-
.tags ⇒ Array<String>
Retrieves unique tags from the map rooms.
-
.to_json(*args) ⇒ String
Converts the map data to JSON format.
-
.uids ⇒ Hash<Integer, Array<Integer>>
Retrieves the mapping of UIDs to room IDs.
-
.uids_add(uid, id) ⇒ Object
Adds a room ID to the list of IDs associated with a given UID.
- .uids_clear ⇒ Object
Instance Method Summary collapse
-
#desc ⇒ String
Returns the description of the room.
-
#dijkstra(destination = nil) ⇒ Array<Integer>, Array<Float>
Performs Dijkstra’s algorithm for the current room.
-
#find_all_nearest_by_tag(tag_name) ⇒ Array<Integer>
Finds all nearest rooms with a specific tag.
-
#find_nearest(target_list) ⇒ Integer
Finds the nearest room from a list of target rooms.
-
#find_nearest_by_tag(tag_name) ⇒ Integer
Finds the nearest room with a specific tag.
- #fuzzy_room_id ⇒ Object
-
#geo ⇒ nil
Returns geographical information for the room.
-
#initialize(id, title, description, paths, uid = [], location = nil, climate = nil, terrain = nil, wayto = {}, timeto = {}, image = nil, image_coords = nil, tags = [], check_location = nil, unique_loot = nil) ⇒ Map
constructor
Initializes a new map room.
-
#inspect ⇒ String
Inspects the map room, showing its instance variables.
-
#map_name ⇒ String
Returns the name of the map.
-
#map_roomsize ⇒ Integer?
Returns the size of the room based on image coordinates.
-
#map_x ⇒ Integer?
Returns the X coordinate of the map image.
-
#map_y ⇒ Integer?
Returns the Y coordinate of the map image.
-
#outside? ⇒ Boolean
Checks if the current room is outside.
-
#path_to(destination) ⇒ Array<Integer>?
Finds a path to a specified destination.
-
#to_i ⇒ Integer
Converts the map room to an integer ID.
-
#to_json(*_args) ⇒ String
Converts the room data to JSON format.
-
#to_s ⇒ String
Converts the map room to a string representation.
Constructor Details
#initialize(id, title, description, paths, uid = [], location = nil, climate = nil, terrain = nil, wayto = {}, timeto = {}, image = nil, image_coords = nil, tags = [], check_location = nil, unique_loot = nil) ⇒ Map
Initializes a new map room.
42 43 44 45 |
# File 'documented/common/map/map_dr.rb', line 42 def initialize(id, title, description, paths, uid = [], location = nil, climate = nil, terrain = nil, wayto = {}, timeto = {}, image = nil, image_coords = nil, = [], check_location = nil, unique_loot = nil, _room_objects = nil) @id, @title, @description, @paths, @uid, @location, @climate, @terrain, @wayto, @timeto, @image, @image_coords, @tags, @check_location, @unique_loot = id, title, description, paths, uid, location, climate, terrain, wayto, timeto, image, image_coords, , check_location, unique_loot @@list[@id] = self end |
Instance Attribute Details
#check_location ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def check_location @check_location end |
#climate ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def climate @climate end |
#description ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def description @description end |
#id ⇒ Object (readonly)
The unique identifier for the map room.
21 22 23 |
# File 'documented/common/map/map_dr.rb', line 21 def id @id end |
#image ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def image @image end |
#image_coords ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def image_coords @image_coords end |
#location ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def location @location end |
#paths ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def paths @paths end |
#room_objects ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def room_objects @room_objects end |
#tags ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def @tags end |
#terrain ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def terrain @terrain end |
#timeto ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def timeto @timeto end |
#title ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def title @title end |
#uid ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def uid @uid end |
#unique_loot ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def unique_loot @unique_loot end |
#wayto ⇒ Object
The title of the map room.
23 24 25 |
# File 'documented/common/map/map_dr.rb', line 23 def wayto @wayto end |
Class Method Details
.[](val) ⇒ Map?
Retrieves a map room by its ID or UID.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'documented/common/map/map_dr.rb', line 82 def Map.[](val) Map.load unless @@loaded if (val.is_a?(Integer)) or val =~ /^[0-9]+$/ @@list[val.to_i] elsif val =~ /^u(-?\d+)$/i uid_request = $1.dup.to_i @@list[(Map.ids_from_uid(uid_request)[0]).to_i] else chkre = /#{val.strip.sub(/\.$/, '').gsub(/\.(?:\.\.)?/, '|')}/i chk = /#{Regexp.escape(val.strip)}/i @@list.find { |room| room.title.find { |title| title =~ chk } } || @@list.find { |room| room.description.find { |desc| desc =~ chk } } || @@list.find { |room| room.description.find { |desc| desc =~ chkre } } end end |
.clear ⇒ Boolean
Clears all map data and resets the state.
356 357 358 359 360 361 362 363 364 |
# File 'documented/common/map/map_dr.rb', line 356 def Map.clear @@load_mutex.synchronize { @@list.clear @@tags.clear @@loaded = false GC.start } true end |
.current ⇒ Map?
Retrieves the current map room.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'documented/common/map/map_dr.rb', line 110 def Map.current # returns Map/Room Map.load unless @@loaded if Script.current return @@list[@@current_room_id] if XMLData.room_count == @@current_room_count and !@@current_room_id.nil?; else return @@list[@@current_room_id] if XMLData.room_count == @@fuzzy_room_count and !@@current_room_id.nil?; end ids = (XMLData.room_id.zero? ? [] : Map.ids_from_uid(XMLData.room_id)) return Map.set_current(ids[0]) if (ids.size == 1) if ids.size > 1 and !@@current_room_id.nil? and (id = Map.match_multi_ids(ids)) return Map.set_current(id) end return Map.match_no_uid() end |
.current_or_new ⇒ Map?
Retrieves the current room or creates a new one if it doesn’t exist.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'documented/common/map/map_dr.rb', line 257 def Map.current_or_new # returns Map/Room return nil unless Script.current @@current_room_count = -1 @@fuzzy_room_count = -1 Map.load unless @@loaded room = nil id = Map.current ? Map.current.id : nil echo("Map: current room id is #{id.inspect}") unless id.nil? room = Map[id] unless XMLData.room_id.zero? || room.uid.include?(XMLData.room_id) room.uid << XMLData.room_id Map.uids_add(XMLData.room_id, room.id) echo "Map: Adding new uid for #{room.id}: #{XMLData.room_id}" end return Map.set_current(room.id) end id = Map.get_free_id title = [XMLData.room_title] description = [XMLData.room_description.strip] paths = [XMLData.room_exits_string.strip] uid = (XMLData.room_id.zero? ? [] : [XMLData.room_id]) room = Map.new(id, title, description, paths, uid) Map.uids_add(XMLData.room_id, room.id) unless XMLData.room_id.zero? echo "mapped new room, set current room to #{room.id}" return Map.set_current(id) end |
.current_room_id ⇒ Integer
Retrieves the current room ID.
54 |
# File 'documented/common/map/map_gs.rb', line 54 def Map.current_room_id; return @@current_room_id; end |
.current_room_id=(id) ⇒ Integer
Sets the current room ID.
58 |
# File 'documented/common/map/map_gs.rb', line 58 def Map.current_room_id=(id); return @@current_room_id = id; end |
.dijkstra(source, destination = nil) ⇒ Array<Integer>, Array<Float>
Performs Dijkstra’s algorithm to find the shortest path.
799 800 801 802 803 804 805 806 807 808 |
# File 'documented/common/map/map_dr.rb', line 799 def Map.dijkstra(source, destination = nil) if source.is_a?(Map) source.dijkstra(destination) elsif (room = Map[source]) room.dijkstra(destination) else echo "Map.dijkstra: error: invalid source room" nil end end |
.estimate_time(array) ⇒ Float
Estimates the time to travel through a series of rooms.
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 |
# File 'documented/common/map/map_dr.rb', line 774 def Map.estimate_time(array) Map.load unless @@loaded unless array.is_a?(Array) raise Exception.exception("MapError"), "Map.estimate_time was given something not an array!" end time = 0.to_f until array.length < 2 room = array.shift if (t = Map[room].timeto[array.first.to_s]) if t.is_a?(StringProc) time += t.call.to_f else time += t.to_f end else time += "0.2".to_f end end time end |
.findpath(source, destination) ⇒ Array<Integer>?
Finds a path from the source room to the destination.
917 918 919 920 921 922 923 924 925 926 |
# File 'documented/common/map/map_dr.rb', line 917 def Map.findpath(source, destination) if source.is_a?(Map) source.path_to(destination) elsif (room = Map[source]) room.path_to(destination) else echo "Map.findpath: error: invalid source room" nil end end |
.fuzzy_room_id ⇒ Object
89 |
# File 'documented/common/map/map_gs.rb', line 89 def Map.fuzzy_room_id; return @@fuzzy_room_id; end |
.get_free_id ⇒ Integer
Retrieves a free ID for a new map room.
67 68 69 70 |
# File 'documented/common/map/map_dr.rb', line 67 def Map.get_free_id Map.load unless @@loaded return @@list.compact.max_by { |r| r.id }.id + 1 end |
.get_location ⇒ String?
Retrieves the current location based on the game state.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'documented/common/map/map_gs.rb', line 124 def Map.get_location unless XMLData.room_count == @@current_location_count if (script = Script.current) save_want_downstream = script.want_downstream script.want_downstream = true waitrt? location_result = dothistimeout 'location', 15, /^You carefully survey your surroundings and guess that your current location is .*? or somewhere close to it\.$|^You can't do that while submerged under water\.$|^You can't do that\.$|^It would be rude not to give your full attention to the performance\.$|^You can't do that while hanging around up here!$|^You are too distracted by the difficulty of staying alive in these treacherous waters to do that\.$|^You carefully survey your surroundings but are unable to guess your current location\.$|^Not in pitch darkness you don't\.$|^That is too difficult to consider here\.$/ script.want_downstream = save_want_downstream @@current_location_count = XMLData.room_count if location_result =~ /^You can't do that while submerged under water\.$|^You can't do that\.$|^It would be rude not to give your full attention to the performance\.$|^You can't do that while hanging around up here!$|^You are too distracted by the difficulty of staying alive in these treacherous waters to do that\.$|^You carefully survey your surroundings but are unable to guess your current location\.$|^Not in pitch darkness you don't\.$|^That is too difficult to consider here\.$/ @@current_location = false else @@current_location = /^You carefully survey your surroundings and guess that your current location is (.*?) or somewhere close to it\.$/.match(location_result).captures.first end else return nil end end return @@current_location end |
.ids_from_uid(n) ⇒ Array<Integer>
Retrieves room IDs associated with a given UID.
351 352 353 |
# File 'documented/common/map/map_dr.rb', line 351 def Map.ids_from_uid(n) return (@@uids[n].nil? || n == 0 ? [] : @@uids[n]) end |
.images ⇒ Array<String>
Retrieves unique images from the map rooms.
470 471 472 473 474 |
# File 'documented/common/map/map_gs.rb', line 470 def Map.images Map.load unless @@loaded @@images = @@list.each_with_object({}) { |r, h| h[r.image] = nil if !h.key?(r.image) }.keys if @@images.empty?; return @@images.dup end |
.list ⇒ Array<Map>
Retrieves the list of all map rooms.
74 75 76 77 |
# File 'documented/common/map/map_dr.rb', line 74 def Map.list Map.load unless @@loaded @@list end |
.load(filename = nil) ⇒ Boolean
Loads map data from files.
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'documented/common/map/map_dr.rb', line 375 def Map.load(filename = nil) if filename.nil? file_list = Dir.entries("#{DATA_DIR}/#{XMLData.game}").find_all { |filename| filename =~ /^map\-[0-9]+\.(?:dat|xml|json)$/i }.collect { |filename| "#{DATA_DIR}/#{XMLData.game}/#{filename}" }.sort.reverse else file_list = [filename] end if file_list.empty? respond "--- Lich: error: no map database found" return false end while (filename = file_list.shift) if filename =~ /\.json$/i if Map.load_json(filename) return true end elsif filename =~ /\.xml$/ if Map.load_xml(filename) return true end else if Map.load_dat(filename) return true end end end return false end |
.load_dat(filename = nil) ⇒ Boolean
Loads map data from a DAT file.
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'documented/common/map/map_dr.rb', line 459 def Map.load_dat(filename = nil) @@load_mutex.synchronize { if @@loaded return true else if filename.nil? file_list = Dir.entries("#{DATA_DIR}/#{XMLData.game}").find_all { |filename| filename =~ /^map\-[0-9]+\.dat$/ }.collect { |filename| "#{DATA_DIR}/#{XMLData.game}/#{filename}" }.sort.reverse else file_list = [filename] respond "--- file_list = #{filename.inspect}" end if file_list.empty? respond "--- Lich: error: no map database found" return false end while (filename = file_list.shift) begin @@list = File.open(filename, 'rb') { |f| Marshal.load(f.read) } respond "--- Map loaded #{filename}" # if error @@loaded = true Map.load_uids return true rescue if file_list.empty? respond "--- Lich: error: failed to load #{filename}: #{$!}" else respond "--- warning: failed to load #{filename}: #{$!}" end end end return false end } end |
.load_json(filename = nil) ⇒ Boolean
Loads map data from a JSON file.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'documented/common/map/map_dr.rb', line 406 def Map.load_json(filename = nil) @@load_mutex.synchronize { if @@loaded return true else if filename file_list = [filename] # respond "--- loading #{filename}" #if error else file_list = Dir.entries("#{DATA_DIR}/#{XMLData.game}").find_all { |filename| filename =~ /^map\-[0-9]+\.json$/i }.collect { |filename| "#{DATA_DIR}/#{XMLData.game}/#{filename}" }.sort.reverse # respond "--- loading #{filename}" #if error end if file_list.empty? respond "--- Lich: error: no map database found" return false end while (filename = file_list.shift) if File.exist?(filename) File.open(filename) { |f| JSON.parse(f.read).each { |room| room['wayto'].keys.each { |k| if room['wayto'][k][0..2] == ';e ' room['wayto'][k] = StringProc.new(room['wayto'][k][3..-1]) end } room['timeto'].keys.each { |k| if (room['timeto'][k].is_a?(String)) and (room['timeto'][k][0..2] == ';e ') room['timeto'][k] = StringProc.new(room['timeto'][k][3..-1]) end } room['tags'] ||= [] room['uid'] ||= [] Map.new(room['id'], room['title'], room['description'], room['paths'], room['uid'], room['location'], room['climate'], room['terrain'], room['wayto'], room['timeto'], room['image'], room['image_coords'], room['tags'], room['check_location'], room['unique_loot']) } } @@tags.clear respond "--- Map loaded #{filename}" # if error @@loaded = true Map.load_uids return true end end end } end |
.load_uids ⇒ void
This method returns an undefined value.
Loads UIDs from the current map rooms into the UID mapping.
334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'documented/common/map/map_dr.rb', line 334 def Map.load_uids() Map.load unless @@loaded @@uids.clear @@list.each { |r| r.uid.each { |u| if @@uids[u].nil? @@uids[u] = [r.id] else @@uids[u] << r.id if !@@uids[u].include?(r.id) end } } end |
.load_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map.xml") ⇒ Boolean
Loads map data from an XML file.
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'documented/common/map/map_dr.rb', line 498 def Map.load_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map.xml") @@load_mutex.synchronize { if @@loaded return true else unless File.exist?(filename) raise Exception.exception("MapDatabaseError"), "Fatal error: file `#{filename}' does not exist!" end missing_end = false current_tag = nil current_attributes = nil room = nil buffer = String.new unescape = { 'lt' => '<', 'gt' => '>', 'quot' => '"', 'apos' => "'", 'amp' => '&' } tag_start = proc { |element, attributes| current_tag = element current_attributes = attributes if element == 'room' room = Hash.new room['id'] = attributes['id'].to_i room['location'] = attributes['location'] room['climate'] = attributes['climate'] room['terrain'] = attributes['terrain'] room['wayto'] = Hash.new room['timeto'] = Hash.new room['title'] = Array.new room['description'] = Array.new room['paths'] = Array.new room['tags'] = Array.new room['unique_loot'] = Array.new room['uid'] = Array.new room['room_objects'] = Array.new elsif element =~ /^(?:image|tsoran)$/ and attributes['name'] and attributes['x'] and attributes['y'] and attributes['size'] room['image'] = attributes['name'] room['image_coords'] = [(attributes['x'].to_i - (attributes['size'] / 2.0).round), (attributes['y'].to_i - (attributes['size'] / 2.0).round), (attributes['x'].to_i + (attributes['size'] / 2.0).round), (attributes['y'].to_i + (attributes['size'] / 2.0).round)] elsif (element == 'image') and attributes['name'] and attributes['coords'] and (attributes['coords'] =~ /[0-9]+,[0-9]+,[0-9]+,[0-9]+/) room['image'] = attributes['name'] room['image_coords'] = attributes['coords'].split(',').collect { |num| num.to_i } elsif element == 'map' missing_end = true end } text = proc { |text_string| if current_tag == 'tag' room['tags'].push(text_string) elsif current_tag =~ /^(?:title|description|paths|unique_loot|tag|room_objects)$/ room[current_tag].push(text_string) elsif current_tag =~ /^(?:uid)$/ room[current_tag].push(text_string.to_i) elsif current_tag == 'exit' and current_attributes['target'] if current_attributes['type'].downcase == 'string' room['wayto'][current_attributes['target']] = text_string end if current_attributes['cost'] =~ /^[0-9\.]+$/ room['timeto'][current_attributes['target']] = current_attributes['cost'].to_f elsif current_attributes['cost'].length > 0 room['timeto'][current_attributes['target']] = StringProc.new(current_attributes['cost']) else room['timeto'][current_attributes['target']] = 0.2 end end } tag_end = proc { |element| if element == 'room' room['unique_loot'] = nil if room['unique_loot'].empty? room['room_objects'] = nil if room['room_objects'].empty? Map.new(room['id'], room['title'], room['description'], room['paths'], room['uid'], room['location'], room['climate'], room['terrain'], room['wayto'], room['timeto'], room['image'], room['image_coords'], room['tags'], room['check_location'], room['unique_loot'], room['room_objects']) elsif element == 'map' missing_end = false end current_tag = nil } begin File.open(filename) { |file| while (line = file.gets) buffer.concat(line) # fixme: remove (?=<) ? while (str = buffer.slice!(/^<([^>]+)><\/\1>|^[^<]+(?=<)|^<[^<]+>/)) if str[0, 1] == '<' if str[1, 1] == '/' element = /^<\/([^\s>\/]+)/.match(str).captures.first tag_end.call(element) else if str =~ /^<([^>]+)><\/\1>/ element = $1 tag_start.call(element) text.call('') tag_end.call(element) else element = /^<([^\s>\/]+)/.match(str).captures.first attributes = Hash.new str.scan(/([A-z][A-z0-9_\-]*)=(["'])(.*?)\2/).each { |attr| attributes[attr[0]] = attr[2].gsub(/&(#{unescape.keys.join('|')});/) { unescape[$1] } } tag_start.call(element, attributes) tag_end.call(element) if str[-2, 1] == '/' end end else text.call(str.gsub(/&(#{unescape.keys.join('|')});/) { unescape[$1] }) end end end } if missing_end respond "--- Lich: error: failed to load #{filename}: unexpected end of file" return false end @@tags.clear Map.load_uids @@loaded = true return true rescue respond "--- Lich: error: failed to load #{filename}: #{$!}" return false end end } end |
.loaded ⇒ Boolean
Checks if the map has been loaded.
61 |
# File 'documented/common/map/map_gs.rb', line 61 def Map.loaded; return @@loaded; end |
.locations ⇒ Array<String>
Retrieves unique locations from the map rooms.
462 463 464 465 466 |
# File 'documented/common/map/map_gs.rb', line 462 def Map.locations Map.load unless @@loaded @@locations = @@list.each_with_object({}) { |r, h| h[r.location] = nil if !h.key?(r.location) }.keys if @@locations.empty?; return @@locations.dup end |
.match_current(script) ⇒ Integer
Matches the current room based on the game state.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'documented/common/map/map_dr.rb', line 147 def Map.match_current(_script) # returns id @@current_room_mutex.synchronize { Hash.new need_set_desc_off = false begin begin @@current_room_count = XMLData.room_count foggy_exits = (XMLData.room_exits_string =~ /^Obvious (?:exits|paths): obscured by a thick fog$/) if (room = @@list.find { |r| r.title.include?(XMLData.room_title) and r.description.include?(XMLData.room_description.strip) and (foggy_exits or r.paths.include?(XMLData.room_exits_string.strip)) }) redo unless @@current_room_count == XMLData.room_count if room.uid.any? unless room.uid.include?(XMLData.room_id) return nil else return room.id end else return room.id end else redo unless @@current_room_count == XMLData.room_count desc_regex = /#{Regexp.escape(XMLData.room_description.strip.sub(/\.+$/, '')).gsub(/\\\.(?:\\\.\\\.)?/, '|')}/ if (room = @@list.find { |r| r.title.include?(XMLData.room_title) and (foggy_exits or r.paths.include?(XMLData.room_exits_string.strip)) and (XMLData.room_window_disabled or r.description.any? { |desc| desc =~ desc_regex }) }) redo unless @@current_room_count == XMLData.room_count if room.uid.any? unless room.uid.include?(XMLData.room_id) return nil else return room.id end else return room.id end else redo unless @@current_room_count == XMLData.room_count return nil end end end ensure put 'set description off' if need_set_desc_off end } end |
.match_fuzzy ⇒ Integer?
Matches a room using fuzzy logic.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'documented/common/map/map_dr.rb', line 202 def Map.match_fuzzy() # returns id @@fuzzy_room_mutex.synchronize { @@fuzzy_room_count = XMLData.room_count begin foggy_exits = (XMLData.room_exits_string =~ /^Obvious (?:exits|paths): obscured by a thick fog$/) if (room = @@list.find { |r| r.title.include?(XMLData.room_title) and r.description.include?(XMLData.room_description.strip) and (foggy_exits or r.paths.include?(XMLData.room_exits_string.strip)) }) redo unless @@fuzzy_room_count == XMLData.room_count if room.uid.any? unless room.uid.include?(XMLData.room_id) return nil else return room.id end elsif room..any? { |tag| tag =~ /^(set desc on; )?peer [a-z]+ =~ \/.+\/$/ } return nil else return room.id end else redo unless @@fuzzy_room_count == XMLData.room_count desc_regex = /#{Regexp.escape(XMLData.room_description.strip.sub(/\.+$/, '')).gsub(/\\\.(?:\\\.\\\.)?/, '|')}/ if (room = @@list.find { |r| r.title.include?(XMLData.room_title) and (foggy_exits or r.paths.include?(XMLData.room_exits_string.strip)) and (XMLData.room_window_disabled or r.description.any? { |desc| desc =~ desc_regex }) }) redo unless @@fuzzy_room_count == XMLData.room_count if room.uid.any? unless room.uid.include?(XMLData.room_id) return nil else return room.id end elsif room..any? { |tag| tag =~ /^(set desc on; )?peer [a-z]+ =~ \/.+\/$/ } return nil else return room.id end else redo unless @@fuzzy_room_count == XMLData.room_count return nil end end end } end |
.match_multi_ids(ids) ⇒ Integer?
Matches multiple room IDs to find a valid one.
313 314 315 316 317 |
# File 'documented/common/map/map_dr.rb', line 313 def Map.match_multi_ids(ids) # returns id matches = ids.find_all { |s| @@list[@@current_room_id].wayto.keys.include?(s.to_s) } return matches[0] if matches.size == 1; return nil; end |
.match_no_uid ⇒ Map?
Matches a room without a UID.
127 128 129 130 131 132 133 |
# File 'documented/common/map/map_dr.rb', line 127 def Map.match_no_uid() # returns Map/Room if (script = Script.current) return Map.set_current(Map.match_current(script)) else return Map.set_fuzzy(Map.match_fuzzy()) end end |
.previous ⇒ Map?
Retrieves the previous map room.
98 99 100 |
# File 'documented/common/map/map_dr.rb', line 98 def Map.previous return @@list[@@previous_room_id] end |
.previous_room_id ⇒ Integer?
Retrieves the previous room ID.
64 |
# File 'documented/common/map/map_gs.rb', line 64 def Map.previous_room_id; return @@previous_room_id; end |
.previous_room_id=(id) ⇒ Integer
Sets the previous room ID.
68 |
# File 'documented/common/map/map_gs.rb', line 68 def Map.previous_room_id=(id); return @@previous_room_id = id; end |
.previous_uid ⇒ Integer?
Retrieves the previous room’s UID.
104 105 106 |
# File 'documented/common/map/map_dr.rb', line 104 def Map.previous_uid return XMLData.previous_nav_rm end |
.reload ⇒ Boolean
Reloads the map data from the source.
367 368 369 370 |
# File 'documented/common/map/map_dr.rb', line 367 def Map.reload Map.clear Map.load end |
.save(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.dat") ⇒ void
This method returns an undefined value.
Saves the current map data to a DAT file.
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'documented/common/map/map_dr.rb', line 619 def Map.save(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.dat") if File.exist?(filename) respond "--- Backing up map database" begin # fixme: does this work on all platforms? File.rename(filename, "#{filename}.bak") File.open(filename, 'rb') { |infile| File.open("#{filename}.bak", 'wb') { |outfile| outfile.write(infile.read) } } rescue respond "--- Lich: error: #{$!}" end end begin File.open(filename, 'wb') { |f| f.write(Marshal.dump(@@list)) } @@tags.clear respond "--- Map database saved" rescue respond "--- Lich: error: #{$!}" end end |
.save_json(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.json") ⇒ void
This method returns an undefined value.
Saves the current map data to a JSON file.
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'documented/common/map/map_dr.rb', line 677 def Map.save_json(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.json") if File.exist?(filename) respond "File exists! Backing it up before proceeding..." begin File.open(filename, 'rb') { |infile| File.open("#{filename}.bak", "wb:UTF-8") { |outfile| outfile.write(infile.read) } } rescue respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" end end File.open(filename, 'wb:UTF-8') { |file| file.write(Map.to_json) } respond "#{filename} saved" end |
.save_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.xml") ⇒ void
This method returns an undefined value.
Saves the current map data to an XML file.
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'documented/common/map/map_dr.rb', line 700 def Map.save_xml(filename = "#{DATA_DIR}/#{XMLData.game}/map-#{Time.now.to_i}.xml") if File.exist?(filename) respond "File exists! Backing it up before proceeding..." begin File.open(filename, 'rb') { |infile| File.open("#{filename}.bak", "wb") { |outfile| outfile.write(infile.read) } } rescue respond "--- Lich: error: #{$!}\n\t#{$!.backtrace[0..1].join("\n\t")}" Lich.log "error: #{$!}\n\t#{$!.backtrace.join("\n\t")}" end end begin escape = { '<' => '<', '>' => '>', '"' => '"', "'" => "'", '&' => '&' } File.open(filename, 'w') { |file| file.write "<map>\n" @@list.each { |room| next if room == nil if room.location location = " location=#{(room.location.gsub(/(<|>|"|'|&)/) { escape[$1] }).inspect}" else location = '' end if room.climate climate = " climate=#{(room.climate.gsub(/(<|>|"|'|&)/) { escape[$1] }).inspect}" else climate = '' end if room.terrain terrain = " terrain=#{(room.terrain.gsub(/(<|>|"|'|&)/) { escape[$1] }).inspect}" else terrain = '' end file.write " <room id=\"#{room.id}\"#{location}#{climate}#{terrain}>\n" room.title.each { |title| file.write " <title>#{title.gsub(/(<|>|"|'|&)/) { escape[$1] }}</title>\n" } room.description.each { |desc| file.write " <description>#{desc.gsub(/(<|>|"|'|&)/) { escape[$1] }}</description>\n" } room.paths.each { |paths| file.write " <paths>#{paths.gsub(/(<|>|"|'|&)/) { escape[$1] }}</paths>\n" } room..each { |tag| file.write " <tag>#{tag.gsub(/(<|>|"|'|&)/) { escape[$1] }}</tag>\n" } room.uid.each { |u| file.write " <uid>#{u}</uid>\n" } room.unique_loot.to_a.each { |loot| file.write " <unique_loot>#{loot.gsub(/(<|>|"|'|&)/) { escape[$1] }}</unique_loot>\n" } room.room_objects.to_a.each { |loot| file.write " <room_objects>#{loot.gsub(/(<|>|"|'|&)/) { escape[$1] }}</room_objects>\n" } file.write " <image name=\"#{room.image.gsub(/(<|>|"|'|&)/) { escape[$1] }}\" coords=\"#{room.image_coords.join(',')}\" />\n" if room.image and room.image_coords room.wayto.keys.each { |target| if room.timeto[target].is_a?(StringProc) cost = " cost=\"#{room.timeto[target]._dump.gsub(/(<|>|"|'|&)/) { escape[$1] }}\"" elsif room.timeto[target] cost = " cost=\"#{room.timeto[target]}\"" else cost = '' end if room.wayto[target].is_a?(StringProc) file.write " <exit target=\"#{target}\" type=\"Proc\"#{cost}>#{room.wayto[target]._dump.gsub(/(<|>|"|'|&)/) { escape[$1] }}</exit>\n" else file.write " <exit target=\"#{target}\" type=\"#{room.wayto[target].class}\"#{cost}>#{room.wayto[target].gsub(/(<|>|"|'|&)/) { escape[$1] }}</exit>\n" end } file.write " </room>\n" } file.write "</map>\n" } @@tags.clear respond "--- map database saved to: #{filename}" rescue respond $! end GC.start end |
.set_current(id) ⇒ Map?
Sets the current map room.
303 304 305 306 307 308 |
# File 'documented/common/map/map_dr.rb', line 303 def Map.set_current(id) # returns Map/Room @@previous_room_id = @@current_room_id if id != @@current_room_id; @@current_room_id = id return nil if id.nil? return @@list[id] end |
.set_fuzzy(id) ⇒ Map?
Sets a fuzzy current room ID.
138 139 140 141 142 143 |
# File 'documented/common/map/map_dr.rb', line 138 def Map.set_fuzzy(id) # returns Map/Room @@previous_room_id = @@current_room_id if !id.nil? and id != @@current_room_id; @@current_room_id = id return nil if id.nil? return @@list[id] end |
.tags ⇒ Array<String>
Retrieves unique tags from the map rooms.
321 322 323 324 325 326 327 328 329 330 331 |
# File 'documented/common/map/map_dr.rb', line 321 def Map. Map.load unless @@loaded if @@tags.empty? @@list.each { |r| r..each { |t| @@tags.push(t) unless @@tags.include?(t) } } end @@tags.dup end |
.to_json(*args) ⇒ String
Converts the map data to JSON format.
645 646 647 648 |
# File 'documented/common/map/map_dr.rb', line 645 def Map.to_json(*args) @@list.delete_if { |r| r.nil? } @@list.to_json(args) end |
.uids ⇒ Hash<Integer, Array<Integer>>
Retrieves the mapping of UIDs to room IDs.
486 |
# File 'documented/common/map/map_gs.rb', line 486 def Map.uids(); return @@uids; end |
.uids_add(uid, id) ⇒ Object
Adds a room ID to the list of IDs associated with a given UID.
292 293 294 295 296 297 298 |
# File 'documented/common/map/map_dr.rb', line 292 def Map.uids_add(uid, id) if !@@uids.key?(uid) @@uids[uid] = [id] else @@uids[uid] << id if !@@uids[uid].include?(id) end end |
Instance Method Details
#desc ⇒ String
Returns the description of the room.
1000 1001 1002 |
# File 'documented/common/map/map_dr.rb', line 1000 def desc @description end |
#dijkstra(destination = nil) ⇒ Array<Integer>, Array<Float>
Performs Dijkstra’s algorithm for the current room.
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'documented/common/map/map_dr.rb', line 813 def dijkstra(destination = nil) begin Map.load unless @@loaded source = @id visited = Array.new shortest_distances = Array.new previous = Array.new pq = [source] pq_push = proc { |val| for i in 0...pq.size if shortest_distances[val] <= shortest_distances[pq[i]] pq.insert(i, val) break end end pq.push(val) if i.nil? or (i == pq.size - 1) } visited[source] = true shortest_distances[source] = 0 if destination.nil? until pq.size == 0 v = pq.shift visited[v] = true @@list[v].wayto.keys.each { |adj_room| adj_room_i = adj_room.to_i unless visited[adj_room_i] if @@list[v].timeto[adj_room].is_a?(StringProc) nd = @@list[v].timeto[adj_room].call else nd = @@list[v].timeto[adj_room] end if nd nd += shortest_distances[v] if shortest_distances[adj_room_i].nil? or (shortest_distances[adj_room_i] > nd) shortest_distances[adj_room_i] = nd previous[adj_room_i] = v pq_push.call(adj_room_i) end end end } end elsif destination.is_a?(Integer) until pq.size == 0 v = pq.shift break if v == destination visited[v] = true @@list[v].wayto.keys.each { |adj_room| adj_room_i = adj_room.to_i unless visited[adj_room_i] if @@list[v].timeto[adj_room].is_a?(StringProc) nd = @@list[v].timeto[adj_room].call else nd = @@list[v].timeto[adj_room] end if nd nd += shortest_distances[v] if shortest_distances[adj_room_i].nil? or (shortest_distances[adj_room_i] > nd) shortest_distances[adj_room_i] = nd previous[adj_room_i] = v pq_push.call(adj_room_i) end end end } end elsif destination.is_a?(Array) dest_list = destination.collect { |dest| dest.to_i } until pq.size == 0 v = pq.shift break if dest_list.include?(v) and (shortest_distances[v] < 20) visited[v] = true @@list[v].wayto.keys.each { |adj_room| adj_room_i = adj_room.to_i unless visited[adj_room_i] if @@list[v].timeto[adj_room].is_a?(StringProc) nd = @@list[v].timeto[adj_room].call else nd = @@list[v].timeto[adj_room] end if nd nd += shortest_distances[v] if shortest_distances[adj_room_i].nil? or (shortest_distances[adj_room_i] > nd) shortest_distances[adj_room_i] = nd previous[adj_room_i] = v pq_push.call(adj_room_i) end end end } end end return previous, shortest_distances rescue echo "Map.dijkstra: error: #{$!}" respond $!.backtrace nil end end |
#find_all_nearest_by_tag(tag_name) ⇒ Array<Integer>
Finds all nearest rooms with a specific tag.
961 962 963 964 965 966 967 |
# File 'documented/common/map/map_dr.rb', line 961 def find_all_nearest_by_tag(tag_name) target_list = Array.new @@list.each { |room| target_list.push(room.id) if room..include?(tag_name) } _, shortest_distances = Map.dijkstra(@id) target_list.delete_if { |room_num| shortest_distances[room_num].nil? } target_list.sort { |a, b| shortest_distances[a] <=> shortest_distances[b] } end |
#find_nearest(target_list) ⇒ Integer
Finds the nearest room from a list of target rooms.
972 973 974 975 976 977 978 979 980 981 |
# File 'documented/common/map/map_dr.rb', line 972 def find_nearest(target_list) target_list = target_list.collect { |num| num.to_i } if target_list.include?(@id) @id else _previous, shortest_distances = Map.dijkstra(@id, target_list) valid_rooms = target_list.select { |room_num| shortest_distances[room_num].is_a?(Numeric) } return valid_rooms.min_by { |room_num| shortest_distances[room_num] } end end |
#find_nearest_by_tag(tag_name) ⇒ Integer
Finds the nearest room with a specific tag.
946 947 948 949 950 951 952 953 954 955 956 |
# File 'documented/common/map/map_dr.rb', line 946 def find_nearest_by_tag(tag_name) target_list = Array.new @@list.each { |room| target_list.push(room.id) if room..include?(tag_name) } _, shortest_distances = Map.dijkstra(@id, target_list) if target_list.include?(@id) @id else target_list.delete_if { |room_num| shortest_distances[room_num].nil? } target_list.sort { |a, b| shortest_distances[a] <=> shortest_distances[b] }.first end end |
#fuzzy_room_id ⇒ Object
69 |
# File 'documented/common/map/map_gs.rb', line 69 def fuzzy_room_id; return @@current_room_id; end |
#geo ⇒ nil
Returns geographical information for the room.
1042 1043 1044 |
# File 'documented/common/map/map_dr.rb', line 1042 def geo nil end |
#inspect ⇒ String
Inspects the map room, showing its instance variables.
61 62 63 |
# File 'documented/common/map/map_dr.rb', line 61 def inspect self.instance_variables.collect { |var| var.to_s + "=" + self.instance_variable_get(var).inspect }.join("\n") end |
#map_name ⇒ String
Returns the name of the map.
1006 1007 1008 |
# File 'documented/common/map/map_dr.rb', line 1006 def map_name @image end |
#map_roomsize ⇒ Integer?
Returns the size of the room based on image coordinates.
1032 1033 1034 1035 1036 1037 1038 |
# File 'documented/common/map/map_dr.rb', line 1032 def map_roomsize if @image_coords.nil? nil else image_coords[2] - image_coords[0] end end |
#map_x ⇒ Integer?
Returns the X coordinate of the map image.
1012 1013 1014 1015 1016 1017 1018 |
# File 'documented/common/map/map_dr.rb', line 1012 def map_x if @image_coords.nil? nil else ((image_coords[0] + image_coords[2]) / 2.0).round end end |
#map_y ⇒ Integer?
Returns the Y coordinate of the map image.
1022 1023 1024 1025 1026 1027 1028 |
# File 'documented/common/map/map_dr.rb', line 1022 def map_y if @image_coords.nil? nil else ((image_coords[1] + image_coords[3]) / 2.0).round end end |
#outside? ⇒ Boolean
Checks if the current room is outside.
72 |
# File 'documented/common/map/map_gs.rb', line 72 def outside?; return @paths.last =~ /^Obvious paths:/ ? true : false; end |
#path_to(destination) ⇒ Array<Integer>?
Finds a path to a specified destination.
931 932 933 934 935 936 937 938 939 940 941 |
# File 'documented/common/map/map_dr.rb', line 931 def path_to(destination) Map.load unless @@loaded destination = destination.to_i previous, _ = dijkstra(destination) return nil unless previous[destination] path = [destination] path.push(previous[path[-1]]) until previous[path[-1]] == @id path.reverse! path.pop return path end |
#to_i ⇒ Integer
Converts the map room to an integer ID.
49 50 51 |
# File 'documented/common/map/map_dr.rb', line 49 def to_i @id end |
#to_json(*_args) ⇒ String
Converts the room data to JSON format.
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'documented/common/map/map_dr.rb', line 653 def to_json(*_args) mapjson = ({ :id => @id, :title => @title, :description => @description, :paths => @paths, :location => @location, :climate => @climate, :terrain => @terrain, :wayto => @wayto, :timeto => @timeto, :image => @image, :image_coords => @image_coords, :tags => @tags, :check_location => @check_location, :unique_loot => @unique_loot, :uid => @uid, }).delete_if { |_a, b| b.nil? or (b.is_a?(Array) and b.empty?) }; JSON.pretty_generate(mapjson); end |
#to_s ⇒ String
Converts the map room to a string representation.
55 56 57 |
# File 'documented/common/map/map_dr.rb', line 55 def to_s "##{@id} (#{@uid[-1]}):\n#{@title[-1]}\n#{@description[-1]}\n#{@paths[-1]}" end |