--[[
Script to change the mod title in the mod view

Author:		Ifko[nator]
Date:		11.05.2018
Version:	1.0

History:	V 1.0 @ 11.05.2018 - intial release

<changeModTitle modTitle="_modTitle_"/>
]]

ChangeModTitle = {};

ChangeModTitle.modDirectory = g_currentModDirectory;
ChangeModTitle.currentModName = g_currentModName;

addModEventListener(ChangeModTitle);

function ChangeModTitle:loadMap(name)
	local modDesc = loadXMLFile("modDesc", ChangeModTitle.modDirectory .. "modDesc.xml");
	local modTitle = Utils.getNoNil(getXMLString(modDesc, "modDesc.changeModTitle#modTitle"), "");
	
	if g_i18n:hasText(modTitle) then
		modTitle = g_i18n:getText(modTitle);
	end;
	
	if StoreItemsUtil ~= nil and StoreItemsUtil.storeItems ~= nil then
		for _, storeItem in pairs(StoreItemsUtil.storeItems) do
			if storeItem ~= nil and storeItem.isMod and storeItem.customEnvironment == ChangeModTitle.currentModName then
				--print("mod name = " .. storeItem.name .. ", is Mod = " .. tostring(storeItem.isMod) .. ", custom environment = " .. storeItem.customEnvironment .. ", g_currentModName = " .. ChangeModTitle.currentModName);
				storeItem.isMod = false;
				
				if modTitle ~= "" then
					storeItem.dlcTitle = modTitle;
				else
					for _, modList in pairs(ModsUtil.modList) do
						if modList.modName == ChangeModTitle.currentModName then
							storeItem.dlcTitle = modList.title;
						end;
					end;
				end;
			end;
		end;
	end;
	
	delete(modDesc);
end;

function ChangeModTitle:update(dt)end;
function ChangeModTitle:deleteMap()end;
function ChangeModTitle:mouseEvent(posX, posY, isDown, isUp, button)end;
function ChangeModTitle:keyEvent(unicode, sym, modifier, isDown)end;
function ChangeModTitle:draw()end;