refactor(loader): refactor font creation and add root pattern validation

- Refactor font creation into a loop-based approach to reduce code duplication
- Add validation for root pattern with support for "none" value to disable the loader
- Store root pattern in local variable for consistent usage throughout the module
- Add early return when loader is disabled to prevent unnecessary processing
- Improve code organization with clearer section comments
- Change default root from "bladw_announcement" to "none" (disabled state)
This commit is contained in:
2026-07-20 17:17:57 +02:00
parent cf747dd454
commit dc2835b11b
+34 -37
View File
@@ -10,7 +10,8 @@ NoCode.config = {
-- • sans wildcard -> nom exact d'UN dossier : "bladw_announcement"
-- • avec wildcard -> glob, charge TOUS ceux qui matchent :
-- "bladw_*" (préfixe) / "*_menu" (suffixe) / "bladw_*_v2" (milieu)
root = "bladw_announcement",
-- • "none" (ou vide/nil) -> loader désactivé, rien n'est chargé
root = "none",
-- Dossiers de bibliothèques : seulement envoyés au client (AddCSLuaFile),
-- jamais auto-inclus. Ils sont chargés à la demande via include("lib/...").
libs = { "lib" },
@@ -261,42 +262,28 @@ local function FindRootFolders(pattern)
return roots
end
-- ============================================================
-- Polices client (Poppins)
-- Créées quel que soit le root, donc hors du flux de chargement.
-- ============================================================
if CLIENT then
surface.CreateFont("bladw_text", {
font = "Poppins-SemiBold",
size = 25,
weight = 600,
antialias = true
})
local fonts = {
{ "bladw_text", "Poppins-SemiBold", 25, 600 },
{ "bladw_text_Medium", "Poppins-SemiBold", 20, 800 },
{ "bladw_text_Bold", "Poppins-Bold", 70, 700 },
{ "bladw_text_Regular", "Poppins-Regular", 35, 400 },
{ "bladw_text2", "Poppins-SemiBold", 21.5, 800 },
}
surface.CreateFont("bladw_text_Medium", {
font = "Poppins-SemiBold",
size = 20,
weight = 800,
antialias = true
for _, f in ipairs(fonts) do
surface.CreateFont(f[1], {
font = f[2],
size = f[3],
weight = f[4],
antialias = true,
})
surface.CreateFont("bladw_text_Bold", {
font = "Poppins-Bold",
size = 70,
weight = 700,
antialias = true
})
surface.CreateFont("bladw_text_Regular", {
font = "Poppins-Regular",
size = 35,
weight = 400,
antialias = true
})
surface.CreateFont("bladw_text2", {
font = "Poppins-SemiBold",
size = 21.5,
weight = 800,
antialias = true
})
end
end
-- ============================================================
@@ -307,7 +294,17 @@ Log(C.title, "")
Log(C.title, " ╔══════════════════════════════════════╗")
Log(C.title, " ║ NoCode — Autoloader ║")
Log(C.title, " ╚══════════════════════════════════════╝")
Log(C.info, " Dossier racine : lua/" .. NoCode.config.root)
local rootPattern = NoCode.config.root
-- root "none" (ou vide/nil) -> loader désactivé, on ne charge rien
if not rootPattern or rootPattern == "" or rootPattern:lower() == "none" then
Log(C.warn, " Root = none -> autoloader désactivé, rien n'est chargé.")
Log(C.dim, "")
return
end
Log(C.info, " Dossier racine : lua/" .. rootPattern)
Log(C.dim, "")
-- 1) Expédie les bibliothèques partagées au client (rndx, etc.)
@@ -316,10 +313,10 @@ for _, lib in ipairs(NoCode.config.libs or {}) do
end
-- 2) Charge chaque module racine correspondant au préfixe
local roots = FindRootFolders(NoCode.config.root)
local roots = FindRootFolders(rootPattern)
if #roots == 0 then
Log(C.warn, (" [!] Aucun module trouvé pour le préfixe : %s"):format(NoCode.config.root))
Log(C.warn, (" [!] Aucun module trouvé pour le préfixe : %s"):format(rootPattern))
else
for _, root in ipairs(roots) do
if NoCode.config.verbose then