

addshopcategorie = {}; 
local modDirectory = g_currentModDirectory or ""
local modName = g_currentModName or "unknown"

function addshopcategorie:owncategory()
	
    self.modDirectory = modDirectory
    self.modName = modName

	local categoryXMLFile = XMLFile.load("storeCategoriesXML", Utils.getFilename("storeCategories.xml", self.modDirectory))

	categoryXMLFile:iterate("categories.category", function (_, key)
		self:loadCategoryFromXML(categoryXMLFile, key, "")
	end)
	categoryXMLFile:delete()
end; 

function addshopcategorie:loadCategoryFromXML(xmlFile, key, baseDir)
	local name = xmlFile:getString(key .. "#name")
	local title = xmlFile:getString(key .. "#title")
	local imageFilename = xmlFile:getString(key .. "#image")
	local type = xmlFile:getString(key .. "#type")
	local orderId = xmlFile:getInt(key .. "#orderId")

	if title ~= nil and title:sub(1, 6) == "$l10n_" then
		title = g_i18n:getText(title:sub(7))
	end

	g_storeManager:addCategory(name, title,imageFilename , type, addshopcategorie:getFullImagePath(imageFilename, self.modName), orderId)
end

addModEventListener(addshopcategorie);

function addshopcategorie:getFullImagePath(imagePath, modName)
	if imagePath:sub(0, 1) == "$" then
		return "";
	else
		return self.modDirectory .. "";
	end; 
end;

function loadMapData(xmlFile, missionInfo, baseDirectory)
addshopcategorie:owncategory()
end

StoreManager.loadMapData = Utils.appendedFunction(StoreManager.loadMapData, loadMapData)


