From 36f98c991597b482287913215e02a89302f38c7a Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Wed, 31 Jul 2024 14:02:52 +0100 Subject: [PATCH] add name as folder --- newmodels_reborn/core/client.lua | 1 + newmodels_reborn/core/server.lua | 69 ++++++++++++------ newmodels_reborn/meta.xml | 13 ++-- .../models/vehicle/507/Schafter/-5.dff | Bin 0 -> 311296 bytes .../models/vehicle/507/Schafter/-5.txd | Bin 0 -> 8360 bytes newmodels_reborn/optional/c_testing.lua | 7 +- .../optional/compatibility/server/funcs.lua | 13 +--- .../optional/compatibility/shared/funcs.lua | 4 +- 8 files changed, 63 insertions(+), 44 deletions(-) create mode 100644 newmodels_reborn/models/vehicle/507/Schafter/-5.dff create mode 100644 newmodels_reborn/models/vehicle/507/Schafter/-5.txd diff --git a/newmodels_reborn/core/client.lua b/newmodels_reborn/core/client.lua index d4dc457..7657f50 100644 --- a/newmodels_reborn/core/client.lua +++ b/newmodels_reborn/core/client.lua @@ -107,6 +107,7 @@ local function loadCustomModel(customModel, elementToApply) loadedModels[customModel] = { id = allocatedModel, baseModel = customInfo.baseModel, + name = customInfo.name, elementTypes = elementTypes, freeAllocatedTimer = nil, elements = { txd = txd, dff = dff, col = col } diff --git a/newmodels_reborn/core/server.lua b/newmodels_reborn/core/server.lua index 9e9f885..3f03027 100644 --- a/newmodels_reborn/core/server.lua +++ b/newmodels_reborn/core/server.lua @@ -26,37 +26,60 @@ local function loadModels() if not filesAndFoldersInside then return false, "failed to list " .. fullPath .. " directory" end - local filesForCustomModel = {} - for _, fileInside in pairs(filesAndFoldersInside) do - local fullPathInside = fullPath .. "/" .. fileInside - if pathIsFile(fullPathInside) then - local fileType = string.sub(fileInside, -3) - if not (fileType == "dff" or fileType == "txd" or fileType == "col") then - return false, "invalid " .. modelType .. " file type: " .. fileType - end - local customModel = tonumber(string.sub(fileInside, 1, -5)) - if not customModel then - return false, "invalid " .. modelType .. " custom model: " .. fileInside - end - if isDefaultID(modelType, customModel) then - return false, "custom " .. modelType .. " model is a default ID: " .. customModel + local customModelInfo = {} + local function parseOneFile(thisFileName, thisFullPath, name) + local fileType = string.sub(thisFileName, -3) + if not (fileType == "dff" or fileType == "txd" or fileType == "col") then + return false, "invalid " .. modelType .. " file type: " .. fileType + end + local customModel = tonumber(string.sub(thisFileName, 1, -5)) + if not customModel then + return false, "invalid " .. modelType .. " custom model: " .. thisFileName + end + if isDefaultID(modelType, customModel) then + return false, "custom " .. modelType .. " model is a default ID: " .. customModel + end + if customModels[customModel] then + return false, "duplicate " .. modelType .. " custom model: " .. customModel + end + if not customModelInfo[customModel] then + customModelInfo[customModel] = {} + end + customModelInfo[customModel][fileType] = thisFullPath + if name then + customModelInfo[customModel].name = name + end + return true + end + for _, fileOrFolderInside in pairs(filesAndFoldersInside) do + local fullPathInside = fullPath .. "/" .. fileOrFolderInside + if pathIsDirectory(fullPathInside) then + local filesAndFoldersInsideThis = pathListDir(fullPathInside) + if not filesAndFoldersInsideThis then + return false, "failed to list " .. fullPathInside .. " directory" end - if customModels[customModel] then - return false, "duplicate " .. modelType .. " custom model: " .. customModel + for _, fileOrFolderInsideThis in pairs(filesAndFoldersInsideThis) do + local fullPathInsideThis = fullPathInside .. "/" .. fileOrFolderInsideThis + local parsed, failReason = parseOneFile(fileOrFolderInsideThis, fullPathInsideThis, fileOrFolderInside) + if not parsed then + return false, failReason + end end - if not filesForCustomModel[customModel] then - filesForCustomModel[customModel] = {} + elseif pathIsFile(fullPathInside) then + local parsed, failReason = parseOneFile(fileOrFolderInside, fullPathInside) + if not parsed then + return false, failReason end - filesForCustomModel[customModel][fileType] = fullPathInside end end - for customModel, files in pairs(filesForCustomModel) do + for customModel, info in pairs(customModelInfo) do customModels[customModel] = { type = modelType, baseModel = baseModel, - dff = files.dff, - txd = files.txd, - col = files.col + dff = info.dff, + txd = info.txd, + col = info.col, + name = info.name or getVehicleNameFromModel(baseModel) } end end diff --git a/newmodels_reborn/meta.xml b/newmodels_reborn/meta.xml index 52a570a..ec6ce57 100644 --- a/newmodels_reborn/meta.xml +++ b/newmodels_reborn/meta.xml @@ -21,6 +21,14 @@ + + + + + + + +