--
-- Specialization K700AConfig
--
-- @author  	Aluha74rus
-- @version 	v1.0
-- @date  		20/03/20

K700AConfig = {};

function K700AConfig.prerequisitesPresent(specializations)
    return true
end;

function K700AConfig.registerEventListeners(vehicleType)	
	SpecializationUtil.registerEventListener(vehicleType, "onLoad", K700AConfig);
end

function K700AConfig.initSpecialization()
   g_configurationManager:addConfigurationType("lightbar", g_i18n:getText("configuration_lightbar"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
   g_configurationManager:addConfigurationType("modification", g_i18n:getText("configuration_modification"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
   g_configurationManager:addConfigurationType("tuning", g_i18n:getText("configuration_tuning"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
end

function K700AConfig:onLoad(savegame) 
	
    local configurations = Utils.getNoNil(self.configurations["lightbar"], 1, i)
    local configurations = Utils.getNoNil(self.configurations["modification"], 1, i)
    local configurations = Utils.getNoNil(self.configurations["tuning"], 1, i)
	
    local keyLightbar = string.format("vehicle.lightbarConfigurations.lightbarConfiguration(%d)", self.configurations["lightbar"]-1)
    ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.lightbarConfigurations.lightbarConfiguration", self.configurations["lightbar"], self.components, self)
    if not hasXMLProperty(self.xmlFile, keyLightbar) then
        keyLightbar = "vehicle.lightbarConfigurations"
    end
	
    local keyModification = string.format("vehicle.modificationConfigurations.modificationConfiguration(%d)", self.configurations["modification"]-1)
    ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.modificationConfigurations.modificationConfiguration", self.configurations["modification"], self.components, self)
    if not hasXMLProperty(self.xmlFile, keyModification) then
        keyModification = "vehicle.modificationConfigurations"
    end
	
    local key = string.format("vehicle.tuningConfigurations.tuningConfiguration(%d)", self.configurations["tuning"]-1)
    ObjectChangeUtil.updateObjectChanges(self.xmlFile, "vehicle.tuningConfigurations.tuningConfiguration", self.configurations["tuning"], self.components, self)
    if not hasXMLProperty(self.xmlFile, key) then
        key = "vehicle.tuningConfigurations"
    end
    -- self.tuningI3d = {}
    -- local i = 1
    -- while true do
        -- local key = string.format("vehicle.tuningConfigurations.tuningConfiguration(%d)", self.configurations["tuning"]-i)
        -- if not hasXMLProperty(self.xmlFile, key) then
            -- break
        -- end
        -- local node = I3DUtil.indexToObject(self.components, getXMLString(self.xmlFile, key .. ".tuning#node"), self.i3dMappings)
        -- if node ~= nil then
            -- local tuningXmlFilename = getXMLString(self.xmlFile, key .. ".tuning#filename")
            -- if tuningXmlFilename ~= nil then
                -- tuningXmlFilename = Utils.getFilename(tuningXmlFilename, self.baseDirectory)
                -- local tuningXmlFile = loadXMLFile("tuningI3dXML", tuningXmlFilename)
                -- if tuningXmlFile ~= nil and tuningXmlFile ~= 0 then
                    -- local i3dFilename = getXMLString(tuningXmlFile, "I3dDetal.filename")
                    -- if i3dFilename ~= nil then
                        -- local i3dNode = g_i3DManager:loadSharedI3DFile(i3dFilename, self.baseDirectory, false, false, false)
                        -- if i3dNode ~= nil and i3dNode ~= 0 then
                            -- local rootNode = I3DUtil.indexToObject(i3dNode, getXMLString(tuningXmlFile, "I3dDetal.Detal#node"))
                            -- if rootNode ~= nil then
                                -- link(node, rootNode)
                                -- setTranslation(rootNode, 0,0,0)
                                -- local tuning = {}
                                -- tuning.filename = i3dFilename
                                -- tuning.rootNode = rootNode
                                -- table.insert(self.tuningI3d, tuning)
                            -- end
                            -- delete(i3dNode)
                        -- end
                    -- end
                    -- delete(tuningXmlFile)
                -- end
            -- end
        -- end
        -- i = i + 1
    -- end
end;