Jump to content

The SaveGameIndex:GetOriginOfTravel function


Recommended Posts

Hi, so I'm trying to do a Hamlet caves mod, and one thing I'm trying to correct, is to make it hamlet seasons in the caves. I found out that I can use the SaveGameIndex:GetOriginOfTravel() == "porkland" to check whether the current cave is generated by a Hamlet world. But when I descend to the level of the ruins, the function returns simply "cave". Is there a way to determine the origin of the previous level, or would I have to save this data by a class post construct to the saveindex.lua or something?

Link to comment
Share on other sites

Okay so a really easy solution is to add a component to the player since the player's data is reloaded when you travel to a new world:

local WORLDS = {
	porkland = true, 
	shipwrecked = true, 
	forest = true, 
}

local World_Traveller = Class(function(self, inst)
	self.world = "forest"

	local prefab = GetWorld().prefab
	if WORLDS[prefab] then self.world = prefab end 
end)

function World_Traveller:OnSave()
	local data = {world = self.world}
	
	local aporkalypse = GetWorld().prefab == "porkland" and GetWorld().components.aporkalypse
	if aporkalypse then 
		print("saving aporkalypse data in the world traveller component")
		data.aporkalypse = aporkalypse:OnSave()
		for k, v in pairs(data.aporkalypse) do print(k, v) end 
	end 
	
	local manager = GetSeasonManager()
	if manager.seasonmode == "plateau" then 
		print("saving porkland season data in world traveller component")
		data.porkland_season = GetSeasonManager():OnSave() 
		for k, v in pairs(data.porkland_season) do print(k, v) end 
	end 
	
	return data
end 

function World_Traveller:OnLoad(data)
	local prefab = GetWorld().prefab
	
	if WORLDS[prefab] then -- in a main world
		self.world = prefab 
	elseif data and data.world then -- from a main world 
		self.world = data.world 
	end 
	
	if self.world ~= "porkland" or WORLDS[prefab] then return end -- specific porkland fixes: 
	
	local aporkalypse = GetWorld().components.aporkalypse
	if aporkalypse and data.aporkalypse then 
		print("loading aporkalypse data from the world traveller component")
		for k, v in pairs(data.aporkalypse) do print(k, v) end 
		aporkalypse:OnLoad(data.aporkalypse)
	end 
	
	local manager = GetSeasonManager()
	if data.porkland_season and manager.Plateau then 
		print("loading porkland season data from world traveller component")
		for k, v in pairs(data.porkland_season) do print(k, v) end 
		manager:Plateau()
		manager:OnLoad(data.porkland_season)	
		manager.OnLoad = function() end -- nullify this function after using it. 
	end 
end 

return World_Traveller

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...