refact: manual priority of folder / file

This commit is contained in:
Linventif 2025-04-17 17:32:44 +00:00
parent d0880366e4
commit 0eb8109ac2

View File

@ -3,7 +3,7 @@ gmInte = gmInte || {}
gmInte.version = "0.5.0" gmInte.version = "0.5.0"
gmInte.config = {} gmInte.config = {}
gmInte.materials = {} gmInte.materials = {}
local function loadServerConfig() local function loadConfig()
RunConsoleCommand("sv_hibernate_think", "1") RunConsoleCommand("sv_hibernate_think", "1")
if !file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA") then if !file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA") then
file.CreateDir("gm_integration") file.CreateDir("gm_integration")
@ -12,7 +12,6 @@ local function loadServerConfig()
if gmInte.config.id && gmInte.config.id != "" then return end if gmInte.config.id && gmInte.config.id != "" then return end
local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA"))
if !oldConfig.version || (oldConfig.version < gmInte.version) then if !oldConfig.version || (oldConfig.version < gmInte.version) then
print(" | Merging Config | gmod_integration/sv_config.lua")
table.Merge(gmInte.config, oldConfig) table.Merge(gmInte.config, oldConfig)
gmInte.config.version = gmInte.version gmInte.config.version = gmInte.version
file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
@ -22,32 +21,36 @@ local function loadServerConfig()
end end
end end
local function loadAllFiles(folder) local loadedFiles = {}
local files, folders = file.Find(folder .. "/*", "LUA") local function loadFile(folder, fileName)
for k, fileName in SortedPairs(files) do local path = folder .. "/" .. fileName
local path = folder .. "/" .. fileName if loadedFiles[path] then return end
print(" | Loading File | " .. path) loadedFiles[path] = true
if string.StartWith(fileName, "cl_") then print(" | Loading File | " .. path)
if SERVER then if string.StartWith(fileName, "cl_") then
AddCSLuaFile(path) if SERVER then
else AddCSLuaFile(path)
include(path) else
end
elseif string.StartWith(fileName, "sv_") then
if SERVER then include(path) end
elseif string.StartWith(fileName, "sh_") then
if SERVER then AddCSLuaFile(path) end
include(path) include(path)
end end
elseif string.StartWith(fileName, "sv_") then
if fileName == "sv_config.lua" then if SERVER then include(path) end
loadServerConfig() elseif string.StartWith(fileName, "sh_") then
continue if SERVER then AddCSLuaFile(path) end
end include(path)
end end
for k, v in SortedPairs(folders, true) do if fileName == "sv_config.lua" then loadConfig() end
loadAllFiles(folder .. "/" .. v, name) end
local function loadFolder(folder)
local files, folders = file.Find(folder .. "/*", "LUA")
for k, fileName in SortedPairs(files) do
loadFile(folder, fileName)
end
for k, subFolder in SortedPairs(folders) do
loadFolder(folder .. "/" .. subFolder)
end end
end end
@ -65,5 +68,9 @@ print(" - https://gmod-integration.com/discord - ")
print(" - - ") print(" - - ")
print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ") print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
print(" ") print(" ")
loadAllFiles("gmod_integration") loadFile("gmod_integration", "sv_config.lua")
loadFolder("gmod_integration/languages")
loadFolder("gmod_integration/core")
loadFolder("gmod_integration/modules")
loadFolder("gmod_integration")
print(" ") print(" ")