--
-- Specialization Configuration
--
-- @author  	Aluha74rus
-- @version 	v1.2
-- @date  		11/09/19

Configuration = {};

local Configuration_directory = g_currentModDirectory;

function Configuration.prerequisitesPresent(specializations)
    return true
end;

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

function Configuration.initSpecialization()
   g_configurationManager:addConfigurationType("modification", g_i18n:getText("configuration_modification"), nil, nil, nil, nil, ConfigurationUtil.SELECTOR_MULTIOPTION)
   g_configurationManager:addConfigurationType("lightbar", g_i18n:getText("configuration_lightbar"), 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 Configuration:onLoad(savegame) 
	
    local configurations = Utils.getNoNil(self.configurations["modification"], 1, i)
    local configurations = Utils.getNoNil(self.configurations["lightbar"], 1, i)
    local configurations = Utils.getNoNil(self.configurations["tuning"], 1, i)
	
    local key = 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, key) then
        key = "vehicle.modificationConfigurations"
    end
	
    local newkey = 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, key) then
        key = "vehicle.lightbarConfigurations"
    end
	
    local keynew = 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
end;