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:
@@ -10,7 +10,8 @@ NoCode.config = {
|
|||||||
-- • sans wildcard -> nom exact d'UN dossier : "bladw_announcement"
|
-- • sans wildcard -> nom exact d'UN dossier : "bladw_announcement"
|
||||||
-- • avec wildcard -> glob, charge TOUS ceux qui matchent :
|
-- • avec wildcard -> glob, charge TOUS ceux qui matchent :
|
||||||
-- "bladw_*" (préfixe) / "*_menu" (suffixe) / "bladw_*_v2" (milieu)
|
-- "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),
|
-- Dossiers de bibliothèques : seulement envoyés au client (AddCSLuaFile),
|
||||||
-- jamais auto-inclus. Ils sont chargés à la demande via include("lib/...").
|
-- jamais auto-inclus. Ils sont chargés à la demande via include("lib/...").
|
||||||
libs = { "lib" },
|
libs = { "lib" },
|
||||||
@@ -261,42 +262,28 @@ local function FindRootFolders(pattern)
|
|||||||
return roots
|
return roots
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- ============================================================
|
||||||
|
-- Polices client (Poppins)
|
||||||
|
-- Créées quel que soit le root, donc hors du flux de chargement.
|
||||||
|
-- ============================================================
|
||||||
|
|
||||||
if CLIENT then
|
if CLIENT then
|
||||||
surface.CreateFont("bladw_text", {
|
local fonts = {
|
||||||
font = "Poppins-SemiBold",
|
{ "bladw_text", "Poppins-SemiBold", 25, 600 },
|
||||||
size = 25,
|
{ "bladw_text_Medium", "Poppins-SemiBold", 20, 800 },
|
||||||
weight = 600,
|
{ "bladw_text_Bold", "Poppins-Bold", 70, 700 },
|
||||||
antialias = true
|
{ "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
|
|
||||||
})
|
|
||||||
|
|
||||||
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
|
|
||||||
})
|
|
||||||
|
|
||||||
|
for _, f in ipairs(fonts) do
|
||||||
|
surface.CreateFont(f[1], {
|
||||||
|
font = f[2],
|
||||||
|
size = f[3],
|
||||||
|
weight = f[4],
|
||||||
|
antialias = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
@@ -307,7 +294,17 @@ Log(C.title, "")
|
|||||||
Log(C.title, " ╔══════════════════════════════════════╗")
|
Log(C.title, " ╔══════════════════════════════════════╗")
|
||||||
Log(C.title, " ║ NoCode — Autoloader ║")
|
Log(C.title, " ║ NoCode — Autoloader ║")
|
||||||
Log(C.title, " ╚══════════════════════════════════════╝")
|
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, "")
|
Log(C.dim, "")
|
||||||
|
|
||||||
-- 1) Expédie les bibliothèques partagées au client (rndx, etc.)
|
-- 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
|
end
|
||||||
|
|
||||||
-- 2) Charge chaque module racine correspondant au préfixe
|
-- 2) Charge chaque module racine correspondant au préfixe
|
||||||
local roots = FindRootFolders(NoCode.config.root)
|
local roots = FindRootFolders(rootPattern)
|
||||||
|
|
||||||
if #roots == 0 then
|
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
|
else
|
||||||
for _, root in ipairs(roots) do
|
for _, root in ipairs(roots) do
|
||||||
if NoCode.config.verbose then
|
if NoCode.config.verbose then
|
||||||
|
|||||||
Reference in New Issue
Block a user