diff --git a/scripts/route2.lic b/scripts/route2.lic index 7a1fd18a7..7a335c191 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -9,9 +9,13 @@ tags: utility required: Lich >= 5.6.2 - version: 0.3 + version: 0.4 changelog: + version 0.4 (2025-01-19) + * Add support for route2 a custom go2 target + * Remove location column if not GS4 + version 0.3 (2024-09-03) * Change output to use terminal-table @@ -33,8 +37,26 @@ def find_room(what, src = nil) echo "Room ##{what} does not exist." exit end - src ||= Room.current + + if defined?(DB_Store) + if (custom_targets = DB_Store.read("#{XMLData.game}", 'go2')["custom targets"]) && ((target = custom_targets.keys.find { |key| key =~ /^#{what}$/i }) or (target = custom_targets.keys.find { |key| key =~ /^#{what}/i })) + unless custom_targets[target].kind_of?(Array) + echo("Custom targets is an integer: #{custom_targets[target].kind_of?(Integer)}") + destination_id = custom_targets[target] + else + echo("Custom targets is an array: #{custom_targets[target].kind_of?(Array)}") + destination_id = Room.current.find_nearest(custom_targets[target].uniq) + end + unless Map[destination_id] + echo "error: custom target (#{destination_id}) was not found in the map database" + else + echo "First closest matching custom target '#{what}' is room ##{destination_id}" + return Map[destination_id] + end + end + end + rm = src.find_nearest_by_tag(what) if rm rm = Room[rm] @@ -96,10 +118,17 @@ step = 0 time_mod = 0 rm = src -headers = %i[STEP TRIP TIME MOVE ROOM NAME LOCATION] +if XMLData.game =~ /^GS/ + headers = %i[STEP TRIP TIME MOVE ROOM NAME LOCATION] +else + headers = %i[STEP TRIP TIME MOVE ROOM NAME] +end table_rows = [] -table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0], src.location]) - +if XMLData.game =~ /^GS/ + table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0], src.location]) +else + table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0]]) +end path.each do |id| id = id.to_s "##{id}".rjust(7) @@ -140,7 +169,11 @@ path.each do |id| else sttime += " " end - table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) + if XMLData.game =~ /^GS/ + table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) + else + table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title]) + end end table = Terminal::Table.new( headings: headers,