-- @Class RDM_Fixer
-- =====================================================================================
-- CityStart / LoadGame
function OnMsg.RDM_FixerThrowFixes(Fixer, moment) 
	-- Fixer:FixIconBuildMenuPath()
	-- if RDM_IsLoadGame(moment) then 
		-- Fixer:ShowNewTechsInSavegame()
		-- Fixer:UpdateTechfield()
	-- end
end

DefineClass.RDM_Fixer = {
	path = false,
}

function RDM_Fixer:Init() 
	self.path = GetModPath_Core()
	Msg("RDM_FixerLoaded")
end

-- [DEPRECIATED] Since v4.x
function RDM_Fixer:FixIconBuildMenuPath()
	return
end

-- [DEPRECIATED] Since v4.x -> Use: RDM_Fixer:IconUpgrade(building_id, index)
function RDM_Fixer:FixIconUpgradePath(building_id, upgrade_number)
	local bt = ClassTemplates.Building[building_id]
	local icon_path = ""

	if bt then
		for i = 1, upgrade_number do
			icon_path = bt["upgrade".. i .. "_icon"]
			local icon_file = icon_path:match("([^/]-([^.]+))$")
			bt["upgrade".. i .. "_icon"] = ""
			bt["upgrade".. i .. "_icon"] = "UI/Icons/Upgrades/" .. icon_file
		end
	else
		ModLog(RDM_ModLog:GetError().."FixIconUpgradePath() : " .. building_id .. "doesn't exist.")
	end
end

function RDM_Fixer:IconUpgrade(building_id, index)
	local bt = ClassTemplates.Building[building_id] or false
	local icon_path = ""
	
	if bt then
		icon_path = bt["upgrade".. index .. "_icon"]
		bt["upgrade".. index .. "_icon"] = ""
		bt["upgrade".. index .. "_icon"] = "UI/Icons/Upgrades/" .. icon_file
	end
end

function RDM_Fixer:FixSponsorGoalPicturePath(Mod)
	local path = Mod.ModDir .. "/UI/Messages/Goals/"
	
	for k, sponsor_id in ipairs(Mod.sponsors) do
		local sponsor = Presets.MissionSponsorPreset.Default[sponsor_id]
		
		for i = 1, 5 do
			sponsor['goal_image_' .. i] = path .. Mod.sponsor_goals_images[k][i]
		end
	end
	
	ModLog(RDM_ModLog:GetFixed().. "Sponsor goal images paths")
end

-- [DEPRECIATED]  Since v4.x (A executer dans LoadGame)
function RDM_Fixer:ShowNewTechsInSavegame()
	return
end

-- [DEPRECIATED] Since v4.x 
function RDM_Fixer:FixIconTechPath()
	return
end

-- [DEPRECIATED] Since v4.x (Update SILVATECH pour les sauvegardes si les valeurs changent.)
function RDM_Fixer:UpdateTechfield()
	return
	-- local UICity = UICity
	-- local tech_ids = UICity.tech_field['RDM_SilvaTech'] -- Liste des techs présents
	
	-- local count = 0
	
	-- for _, tech_id in ipairs(tech_ids) do
		
		-- if not UICity.tech_status[tech_id] then ModLog(RDM_ModLog:GetWarning() .. "this tech id " .. tech_id .. " doesn't exist" ) end
		
		-- if UICity.tech_status[tech_id].cost ~= RDM_TechDef[tech_id][1] then
			-- UICity.tech_status[tech_id].cost = RDM_TechDef[tech_id][1]
			-- count = count + 1
		-- end
	-- end
	
	-- if count > 0 then
		-- ModLog(RDM_ModLog:GetPatched() .. count .. " technologies have been patched")
	-- end
end