-- Allows using the extra FS22-era material color configuration slots this mod
-- still defines, without calling FS25-removed configuration APIs.

MoreDesignConfigs = {
  prerequisitesPresent = function()
    return true
  end
}

function MoreDesignConfigs.initSpecialization()
  -- Increase max configuration options to 256
  ConfigurationUtil.SEND_NUM_BITS = 8

  for j = 4, 8 do
    local configName = string.format("designMaterial%d", j)
    if g_vehicleConfigurationManager:getConfigurationDescByName(configName) == nil then
      g_vehicleConfigurationManager:addConfigurationType(configName, g_i18n:getText("configuration_designColor"), nil, VehicleConfigurationItemColor)
    end
  end
end

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

function MoreDesignConfigs:onLoad(savegame)
  for j = 4, 8 do
    local name = string.format("designMaterial%d", j)

    if self.configurations[name] ~= nil and self.applyBaseMaterialConfiguration ~= nil then
      self:applyBaseMaterialConfiguration(self.xmlFile, string.format("designMaterial%d", j), self.configurations[name])
    end
  end
end
