Skip to content

Commit

Permalink
fix: HyperSpace target system not always updated
Browse files Browse the repository at this point in the history
This bug manifested itself in the edge-case of loading a game with an
active hyperspace route, and jumping to the next system in the route
without entering the Sector View first. On arrival in the new system,
the Hyperspace Target was not updated to the next system in the route.

The bug was caused by the implementation of the hyperJumpPlanner LUA
module tracking the size of the route in a local variable "route_jumps".
This variable was not initialized until the Sector View was opened, but
it crucial for correctly updating the HyperSpace target system after a
jump.


2 ways were identified to fix this bug:

  1. update the variable in the "buildJumpRouteList" function
  2. remove the variable and read the size of the "hyperjump_route"
     table directly wherever it is needed.

The second option was chosen for this fix as it removes an unnecessary
local variable at the expense of slightly more verbose code. This is
deemed to be more robust as future refactoring or feature additions will
not introduce similar issues where the variable and the table size get
out of sync.
mwerle authored and impaktor committed Oct 2, 2024
1 parent 35c6de8 commit db340e5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions data/pigui/modules/hyperjump-planner.lua
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ local hyperJumpPlanner = {} -- for export

-- hyperjump route stuff
local hyperjump_route = {}
local route_jumps = 0
local current_system
local current_path
local map_selected_path
@@ -66,8 +65,8 @@ local function showInfo()

textIcon(icons.route_destination, lui.FINAL_TARGET)

if route_jumps > 0 then
local final_path = hyperjump_route[route_jumps].path
if #hyperjump_route > 0 then
local final_path = hyperjump_route[#hyperjump_route].path
ui.sameLine()
if ui.selectable(ui.Format.SystemPath(final_path), false, {}) then
sectorView:SwitchToPath(final_path)
@@ -314,7 +313,6 @@ function hyperJumpPlanner.display()
current_path = Game.system and current_system.path -- will be nil during the hyperjump
current_fuel = Game.player:GetComponent('CargoManager'):CountCommodity(fuel_type)
map_selected_path = sectorView:GetSelectedSystemPath()
route_jumps = sectorView:GetRouteSize()
showHyperJumpPlannerWindow()
end -- hyperJumpPlanner.display

@@ -342,7 +340,7 @@ function hyperJumpPlanner.onEnterSystem(ship)
-- this should be the case if you are following a route and want the route to be
-- updated as you make multiple jumps
if ship:IsPlayer() and remove_first_if_current then
if route_jumps > 0 and hyperjump_route[1] and hyperjump_route[1].path:IsSameSystem(Game.system.path) then
if #hyperjump_route > 0 and hyperjump_route[1] and hyperjump_route[1].path:IsSameSystem(Game.system.path) then
sectorView:RemoveRouteItem(1)
end
end

0 comments on commit db340e5

Please sign in to comment.