savePartConfigFileStage2
Definition
-- @/lua/ge/extensions/core/vehicle/partmgmt.lua:402
-- TODO: remove this later
local function savePartConfigFileStage2_Format2(partsCondition, filename)
local playerVehicle = getPlayerVehicle(0)
local playerVehicleData = vehManager.getPlayerVehicleData()
if not playerVehicle or not playerVehicleData then
log('E', 'partmgmt', 'no active vehicle')
return
end
local data = deepcopy(playerVehicleData.config)
local prevPCFilename = data.partConfigFilename
data.partConfigFilename = nil
data.format = 2
data.model = playerVehicleData.model or playerVehicleData.vehicleDirectory:gsub("vehicles/", ""):gsub("/", "")
data.partsCondition = partsCondition
if not data.paints or data.colors then
data.paints = {}
local colorTable = playerVehicle:getColorFTable()
local colorTableSize = tableSize(colorTable)
for i = 1, colorTableSize do
local metallicPaintData = stringToTable(playerVehicle:getField('metallicPaintData', i - 1))
local paint = createVehiclePaint({x = colorTable[i].r, y = colorTable[i].g, z = colorTable[i].b, w = colorTable[i].a}, metallicPaintData)
validateVehiclePaint(paint)
table.insert(data.paints, paint)
end
if #data.paints > 0 then
data.colors = nil
end
end
data.licenseName = extensions.core_vehicles.makeVehicleLicenseText()
local legacySlotMap = {}
local legacySlotMapSimple = {}
-- we want to have a simple key: value structure for the parts
local function flattenPartsTreeRecursive(node)
if not node then return end
for slotId, child in pairs(node.children or {}) do
legacySlotMap[child.path] = {
slotId = child.id,
path = child.path,
chosenPartName = child.chosenPartName,
}
flattenPartsTreeRecursive(child)
end
end
flattenPartsTreeRecursive(data.partsTree)
data.partsTree = nil
-- now simplify it
for path, slotData in pairs(legacySlotMap) do
if not legacySlotMapSimple[slotData.slotId] then
legacySlotMapSimple[slotData.slotId] = slotData
else
-- we have a collision, so we need to save both slots with the full path
local tmp = legacySlotMapSimple[slotData.slotId]
if tmp ~= "COLLISION" then
legacySlotMapSimple[tmp.path] = tmp
legacySlotMapSimple[slotData.slotId] = "COLLISION"
end
legacySlotMapSimple[slotData.path] = slotData
end
end
-- now discard the complex data
for key, slotData in pairs(legacySlotMapSimple) do
if slotData ~= "COLLISION" then
legacySlotMapSimple[key] = slotData.chosenPartName
else
legacySlotMapSimple[key] = nil
end
end
-- save to the resulting data table
data.parts = legacySlotMapSimple
local res = jsonWriteFile(filename, data, true)
if res then
data.partConfigFilename = filename
guihooks.trigger("VehicleconfigSaved", {})
else
data.partConfigFilename = prevPCFilename
log('W', "vehicles.save", "unable to save config: "..filename)
end
guihooks.trigger('Message', {ttl = 15, msg = 'Configuration saved', icon = 'directions_car'})
-- notify the vehicle selector that the vehicle has been saved and clear the cache
local configWithoutFilename = string.sub(filename, #(playerVehicleData.vehicleDirectory or "") + 1)
configWithoutFilename = configWithoutFilename:gsub("%.pc$", "")
ui_vehicleSelector_general.trackRecentVehicle(data.model, configWithoutFilename)
ui_vehicleSelector_general.clearCache()
core_vehicles.clearCache()
end
Callers
@/lua/ge/extensions/core/vehicle/partmgmt.lua
local function savePartConfigFileStage2(partsCondition, filename)
local playerVehicle = getPlayerVehicle(0)