buildConfigFromString
Definition
-- @/lua/ge/extensions/core/vehicle/partmgmt.lua:104
local function buildConfigFromString(vehicleDir, configData, onlyReturnChosenConfig)
local function preprocessPartConfig(configData)
-- If the config data format is 4, then we need to preprocess it
-- Replace references to part config files with the actual part config data
if configData.format == 4 then
for _, vehData in ipairs(configData.vehicles) do
if vehData.linkedPCFile then
local data, isChosenConfigReturned = buildConfigFromString(vehData.linkedPCFile, nil, true)
if isChosenConfigReturned then
tableMerge(vehData, data)
else
return false, nil
end
end
end
else
return true, configData
end
end
local dataType = type(configData)
local fileData
local isChosenConfigReturned = false
if dataType == 'table' then
local res, newConfigData = preprocessPartConfig(configData)
if res then
isChosenConfigReturned = true
return newConfigData, isChosenConfigReturned
end
elseif dataType == 'string' and configData:sub(1, 1) == '{' then
local res, newConfigData = preprocessPartConfig(deserialize(configData))
if res then
isChosenConfigReturned = true
return newConfigData, isChosenConfigReturned
end
elseif configData ~= nil and configData ~= "" then
fileData = jsonReadFile(configData)
if fileData then
local res, newConfigData = preprocessPartConfig(fileData)
if res then
isChosenConfigReturned = true
fileData = newConfigData
else
fileData = nil
end
else
log("W", "", "Unable to read json contents for configData file path: "..dumps(configData))
end
end
if onlyReturnChosenConfig and not isChosenConfigReturned then
return nil, false
end
-- Default to default config if config not found
if not fileData then
log("W", "", "Problems reading requested configuration: "..dumps(configData))
configData = getDefaultConfigFileFromDir(vehicleDir, configData)
if configData then
fileData = jsonReadFile(configData)
end
end
local res = {}
res.partConfigFilename = configData
if fileData and fileData.format == 2 then
fileData.format = nil
tableMerge(res, fileData)
else
res.parts = fileData or {}
end
return res, isChosenConfigReturned
end
Callers
@/lua/ge/extensions/editor/vehicleEditor/staticEditor/veJBeamVariablesChecker.lua
for _, pcFilePath in ipairs(pcFilePaths) do
local vehConfig = extensions.core_vehicle_partmgmt.buildConfigFromString(vehDir, pcFilePath)
@/lua/ge/extensions/core/vehicle/partmgmt.lua
if vehData.linkedPCFile then
local data, isChosenConfigReturned = buildConfigFromString(vehData.linkedPCFile, nil, true)
if isChosenConfigReturned then
if pcFilename then
local data = buildConfigFromString(vehData.vehicleDirectory, pcFilename)
if data ~= nil then
if pcFilename then
local data = buildConfigFromString(playerVehicle.vehicleDirectory, pcFilename)
if data ~= nil then
if pcFilename then
local data = buildConfigFromString(playerVehicle.vehicleDirectory, pcFilename)
if data ~= nil then
@/lua/ge/extensions/core/vehicle/manager.lua
log('D', 'vehicleLoader', 'partConfigData [' .. type(configDataIn) .. '] = ' .. dumps(configDataIn))
local vehicleConfig = extensions.core_vehicle_partmgmt.buildConfigFromString(vehicleDir, configDataIn)