getModelsData
Definition
-- @/lua/ge/extensions/core/vehicles.lua:464
local function getModelsData()
if not modelsDataCache then
local modelsData = {}
local _jbeamFilesCache = {}
local modelRegex = "^/vehicles/([%w|_|%-|%s]+)/info[_]?(.*)%.json"
local modelRegexPC = "^/vehicles/([%w|_|%-|%s]+)/(.*)%.pc"
local modelRegexDir = "^/vehicles/([%w|_|%-|%s]+)"
-- Get the models. They are the directories one level under vehicles folder
for _, path in ipairs(getFilesJson()) do
-- name of a file or directory can have alphanumerics, hyphens and underscores.
local model, configName = string.match(path, modelRegex)
if model then
if not modelsData[model] then modelsData[model] = { info = {}, configs = {}} end
modelsData[model]['info'][path] = configName
else
log("E", "", string.format("Cannot parse path %s with regex %s. Can be caused by uncommon characters, subfolders...", dumps(path), dumps(modelRegex)))
end
end
for _, path in ipairs(getFilesPC()) do
local model, configName = string.match(path, modelRegexPC)
if model then
if not modelsData[model] then
if showStandalonePcs then
local jbeamFilesCount = #getModelsJbeamFiles_cached(_jbeamFilesCache, model)
if jbeamFilesCount == 0 then
log('W', '', 'standalone pc file without any jbeam files ignored: ' .. tostring(path))
--- comment this out to see all standalone pc files
if not _showInvalidPcFiles then
goto continue_pc
end
end
modelsData[model] = { info = {}, configs = {}}
if jbeamFilesCount == 0 then
modelsData[model].missingJbeamFiles = true
end
else
log('W', '', 'standalone pc file without info file ignored: ' .. tostring(path))
if not _showInvalidPcFiles then
goto continue_pc
end
end
end
if modelsData[model] then
local addIt = true
if not showStandalonePcs then
local infoFilename = "/vehicles/" .. model .. "/info_" .. configName .. ".json"
if not modelsData[model]['info'][infoFilename] then
--log('W', '', 'Vehicle config does not have an info file: ' .. tostring(path) .. '. Ignoring the file.')
addIt = false
end
end
if addIt then
modelsData[model]['configs'][path] = configName
end
end
else
log("E", "", string.format("Cannot parse path %s with regex %s. Can be caused by uncommon characters, subfolders...", dumps(path), dumps(modelRegexPC)))
end
::continue_pc::
end
-- find any vehicles without configurations
local vehicleDirs = FS:directoryList('/vehicles/', false, true)
for _, path in ipairs(vehicleDirs) do
local model = string.match(path, modelRegexDir)
if not model then
log("E", "", string.format("Cannot parse path %s with regex %s. Can be caused by uncommon characters, subfolders...", dumps(path), dumps(modelRegexDir)))
goto continue
end
if model == "common" then
goto continue
end
if modelsData[model] then
goto continue
end
-- ok, we don't know about this vehicle, lets figure out if there are jbeam files in there
local jbeamFiles = getModelsJbeamFiles_cached(_jbeamFilesCache, model, path)
if #jbeamFiles == 0 then
log('W', '', 'Warning: vehicle folder does not contain any jbeam files: ' .. tostring(path) .. '. Ignored.')
goto continue
end
-- ok, look if the mainpart is somewhere in there ...
local mainPartFound = false
for _, fn in ipairs(jbeamFiles) do
local fileData = jsonReadFile(fn)
if fileData then
for partName, part in pairs(fileData) do
if part.slotType == 'main' then
mainPartFound = true
break
end
end
if mainPartFound then break end
end
end
if not mainPartFound then
log('W', '', 'Warning: vehicle folder does not contain a configuration or a valid main part: ' .. tostring(path))
goto continue
end
log('W', '', 'Warning: vehicle folder containing main part but no info or config: ' .. tostring(path))
-- adding the model anyways so the default configuration is spawn-able
modelsData[model] = { info = {}, configs = {}}
::continue::
end
modelsDataCache = modelsData
end
return modelsDataCache
end
Callers
@/lua/ge/extensions/ui/vehicleSelector/general.lua
p:add("displayData")
for modelName, _ in pairs(core_vehicles.getModelsData()) do
table.insert(modelList, core_vehicles.getModel(modelName).model)
@/lua/ge/extensions/editor/gen/exp_meshexplorer.lua
if true then
for modelName, _ in pairs(core_vehicles.getModelsData()) do
lo('?? for_model:'..modelName..':'..tostring(core_vehicles.getModel(modelName).model))
-- models list
for modelName, _ in pairs(core_vehicles.getModelsData()) do
amodel[#amodel+1] = modelName
-- models list
-- for modelName, _ in pairs(core_vehicles.getModelsData()) do
-- amodel[#amodel+1] = modelName
@/lua/ge/extensions/core/vehicles.lua
if type(key) ~= 'string' then return nil end
local vehFiles = getModelsData()[key]
if not vehFiles then
if type(key) ~= 'string' then return {} end
local modelsData = getModelsData()[key]
if not modelsData then
local models = {}
for modelName, _ in pairs(getModelsData()) do
local model = getModel(modelName)
local configList = {}
for modelName, _ in pairs(getModelsData()) do
local model = getModel(modelName)
local modelList, configList = {}, {}
for modelName, _ in pairs(getModelsData()) do
if p then p:add("model begin") end
@/lua/ge/extensions/editor/util/vehicleFilterUtil.lua
local modelList, configList = {}, {}
for modelName, _ in pairs(core_vehicles.getModelsData()) do
table.insert(modelList, core_vehicles.getModel(modelName).model)
local allModels = {}
for modelName, _ in pairs(core_vehicles.getModelsData()) do
local model = core_vehicles.getModel(modelName)