Skip to content

Commit

Permalink
add name as folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Jul 31, 2024
1 parent 2a14c6f commit 36f98c9
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 44 deletions.
1 change: 1 addition & 0 deletions newmodels_reborn/core/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
69 changes: 46 additions & 23 deletions newmodels_reborn/core/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions newmodels_reborn/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<export function="getElementModel" type="shared"/>
<export function="getLoadedModels" type="client"/>

<!-- Files -->
<file src="models/**/*.col"/>
<file src="models/**/*.txd"/>
<file src="models/**/*.dff"/>

<!-- ............................................................................... -->
<!-- OPTIONAL THINGS: .............................................................. -->

<!-- Testing -->
<script src="optional/c_testing.lua" type="client"/>
<script src="optional/s_testing.lua" type="server"/>
Expand Down Expand Up @@ -53,9 +61,4 @@
<!-- <export type="client" function="forceFreeAllocated"/> -->
<!-- <export type="client" function="forceDownloadMod"/> -->
<!-- <export type="client" function="isBusyDownloading"/> -->

<!-- Files -->
<file src="models/**/*.col"/>
<file src="models/**/*.txd"/>
<file src="models/**/*.dff"/>
</meta>
Binary file not shown.
Binary file not shown.
7 changes: 5 additions & 2 deletions newmodels_reborn/optional/c_testing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ end
local function updateDebugStr()
local loadedModelsStr = ""
for customModel, v in pairsByKeys(loadedModels) do
local str
if v.name then str = ("%d \"%s\" (%d)"):format(customModel, v.name, v.baseModel)
else str = ("%d (%d)"):format(customModel, v.baseModel) end
if loadedModelsStr == "" then
loadedModelsStr = ("%d (%d)"):format(customModel, v.baseModel)
loadedModelsStr = str
else
loadedModelsStr = loadedModelsStr .. (", %d (%d)"):format(customModel, v.baseModel)
loadedModelsStr = loadedModelsStr .. ", " .. str
end
end
drawStr = getElementChidrenStr(resourceRoot, 0)
Expand Down
13 changes: 1 addition & 12 deletions newmodels_reborn/optional/compatibility/server/funcs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local function sendModListAllPlayers()
col = paths.col or nil,
txd = paths.txd or nil,
dff = paths.dff or nil,
name = mod.name,
srcResourceName = mod.srcResourceName,
}
table.remove(modList[elementType],i)
Expand All @@ -58,18 +59,6 @@ local function getActualModPaths(folder, id)
}
end

function table.copy(tab, recursive)
local ret = {}
for key, value in pairs(tab) do
if (type(value) == "table") and recursive then
ret[key] = table.copy(value)
else
ret[key] = value
end
end
return ret
end

local function fixModList()
for elementType, mods in pairs(modList) do
for k, mod in pairs(mods) do
Expand Down
4 changes: 2 additions & 2 deletions newmodels_reborn/optional/compatibility/shared/funcs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ end

local function convertCustomModelInfoToOldFormat(customModel, customModelInfo)
local baseModel = customModelInfo.baseModel
local colPath, txdPath, dffPath = customModelInfo.col, customModelInfo.txd, customModelInfo.dff
local colPath, txdPath, dffPath, name = customModelInfo.col, customModelInfo.txd, customModelInfo.dff, customModelInfo.name
local mod = {
id = customModel,
base_id = baseModel,
name = "",
name = name,
path = { col = colPath, txd = txdPath, dff = dffPath },
}
mod.paths = mod.path
Expand Down

0 comments on commit 36f98c9

Please sign in to comment.