Skip to content

Commit

Permalink
Save and load the current planned hyperjump in the save file
Browse files Browse the repository at this point in the history
  • Loading branch information
JonBooth78 committed Jan 21, 2024
1 parent 9999f36 commit 7bd2722
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions data/pigui/modules/hyperjump-planner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ local colors = ui.theme.colors
local icons = ui.theme.icons
local Vector2 = _G.Vector2

local Serializer = require 'Serializer'

local sectorView

local hyperJumpPlanner = {} -- for export
Expand All @@ -31,6 +33,8 @@ local current_fuel
local remove_first_if_current = true
local textIconSize = nil

local loaded_data = nil

local function textIcon(icon, tooltip)
ui.icon(icon, textIconSize, colors.font, tooltip)
end
Expand Down Expand Up @@ -352,6 +356,16 @@ end
function hyperJumpPlanner.onGameStart()
-- get notified when the player buys hydrogen
Game.player:GetComponent('CargoManager'):AddListener('hyperjump-planner', hyperJumpPlanner.onPlayerCargoChanged)

if loaded_data and loaded_data.jump_targets then
local targets = loaded_data.jump_targets
for _, target in pairs( loaded_data.jump_targets) do
sectorView:AddToRoute(target)
end
buildJumpRouteList()
loaded_data = nil
end

end

function hyperJumpPlanner.onGameEnd()
Expand All @@ -361,4 +375,26 @@ function hyperJumpPlanner.onGameEnd()
buildJumpRouteList()
end


local serialize = function ()

local data =
{
version = 1,
jump_targets = {}
}

for jumpIndex, jump_sys in pairs(sectorView:GetRoute()) do
table.insert( data.jump_targets, jump_sys )
end

return data
end

local unserialize = function (data)
loaded_data = data
end

Serializer:Register("HyperJumpPlanner", serialize, unserialize)

return hyperJumpPlanner

0 comments on commit 7bd2722

Please sign in to comment.