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