From 8cafa6f6a62d47f1deb07ef7cea1d5ce28ba2beb Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 11:55:15 -0500 Subject: [PATCH 1/7] [route2.lic] v0.4 add go2 custom target support --- scripts/route2.lic | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 7a1fd18a7..2f7ffa4c4 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -9,9 +9,12 @@ 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 + version 0.3 (2024-09-03) * Change output to use terminal-table @@ -33,8 +36,24 @@ def find_room(what, src = nil) echo "Room ##{what} does not exist." exit end - src ||= Room.current + + unless defined?(DB_Store) + if (custom_targets = DB_Store.read("GSF", '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 (destination = Map[destination_id]) + echo "error: custom target (#{destination_id}) was not found in the map database" + end + echo "nearest room for custom target: #{target} is #{destination_id} #{Map[destination_id].title.first}" + end + end + rm = src.find_nearest_by_tag(what) if rm rm = Room[rm] From 93741f5777571e12e2b15326580cd08a0505986b Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 11:57:53 -0500 Subject: [PATCH 2/7] rubocop fix --- scripts/route2.lic | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 2f7ffa4c4..3f52a06bb 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -38,7 +38,7 @@ def find_room(what, src = nil) end src ||= Room.current - unless defined?(DB_Store) + if defined?(DB_Store) if (custom_targets = DB_Store.read("GSF", '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)}") @@ -47,11 +47,10 @@ def find_room(what, src = nil) echo("Custom targets is an array: #{custom_targets[target].kind_of?(Array)}") destination_id = Room.current.find_nearest(custom_targets[target].uniq) end - unless (destination = Map[destination_id]) + unless Map[destination_id] echo "error: custom target (#{destination_id}) was not found in the map database" end - echo "nearest room for custom target: #{target} is #{destination_id} #{Map[destination_id].title.first}" - end + end end rm = src.find_nearest_by_tag(what) From a34baa6796b579be604b9ffc3650ae48432031cc Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 11:58:45 -0500 Subject: [PATCH 3/7] correction for XMLData.game instead of GSF hardcoded --- scripts/route2.lic | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 3f52a06bb..5d348820f 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -39,7 +39,7 @@ def find_room(what, src = nil) src ||= Room.current if defined?(DB_Store) - if (custom_targets = DB_Store.read("GSF", 'go2')["custom targets"]) && ((target = custom_targets.keys.find { |key| key =~ /^#{what}$/i }) or (target = custom_targets.keys.find { |key| key =~ /^#{what}/i })) + 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] From f6732c4ecf15cdf6f4553ec4e29415cf6178c872 Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:07:58 -0500 Subject: [PATCH 4/7] Remove location column if not GS4 --- scripts/route2.lic | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 5d348820f..e890c65f1 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -14,6 +14,7 @@ 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 @@ -114,10 +115,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], src.location]) +end path.each do |id| id = id.to_s "##{id}".rjust(7) @@ -158,7 +166,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, location]) + end end table = Terminal::Table.new( headings: headers, From 6af9a8f1844fedb30d6e6cf4480c5c0d08353b0b Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:08:45 -0500 Subject: [PATCH 5/7] bugfix --- scripts/route2.lic | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index e890c65f1..5e24d6ac2 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -124,7 +124,7 @@ table_rows = [] 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], src.location]) + table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0]]) end path.each do |id| id = id.to_s @@ -169,7 +169,7 @@ path.each do |id| if XMLData.game =~ /^GS/ table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) else - table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) + table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title]) end end table = Terminal::Table.new( From fc16f4b15581d8a441c25287a96d39ee3317b31d Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:22:33 -0500 Subject: [PATCH 6/7] logic corrections --- scripts/route2.lic | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 5e24d6ac2..66ce6897b 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -50,6 +50,9 @@ def find_room(what, src = nil) 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 @@ -124,7 +127,7 @@ table_rows = [] 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]]) + table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0], src.location]) end path.each do |id| id = id.to_s @@ -169,7 +172,7 @@ path.each do |id| if XMLData.game =~ /^GS/ table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) else - table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title]) + table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) end end table = Terminal::Table.new( From 70d787aa5e101d697a05510e5a0a7b4b4461e8f1 Mon Sep 17 00:00:00 2001 From: "Ryan P. McKinnon" <15917743+mrhoribu@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:24:17 -0500 Subject: [PATCH 7/7] re-remove location column, added back in error --- scripts/route2.lic | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/route2.lic b/scripts/route2.lic index 66ce6897b..7a335c191 100644 --- a/scripts/route2.lic +++ b/scripts/route2.lic @@ -127,7 +127,7 @@ table_rows = [] 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], src.location]) + table_rows.push(["#{0.to_s.rjust(4)}:", '', '', '', src.id, src.title[0]]) end path.each do |id| id = id.to_s @@ -172,7 +172,7 @@ path.each do |id| if XMLData.game =~ /^GS/ table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) else - table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title, location]) + table_rows.push(["#{sstep}:", sttime, stime, wayto, id, title]) end end table = Terminal::Table.new(