feat(loader)!: implement glob pattern matching for module discovery
Replace simple prefix matching with full glob pattern support for discovering root folders. Changes: - Add EscapePattern() to escape Lua magic characters - Add GlobToPattern() to convert glob patterns (e.g., "bladw_*") to Lua regex patterns - Refactor FindRootFolders() to support: • Exact matches without wildcards (e.g., "bladw_announcement") • Glob patterns with * in prefix/suffix/middle positions - Update default config root from "bladw_*" to "bladw_announcement" - Improve documentation with usage examples - Add new announcement module with client, server, and shared files - Update rndx.lua library (formatting/whitespace changes) BREAKING CHANGE: The root config now expects exact folder names or glob patterns instead of simple prefixes. Existing configs using "bladw_*" will still work but the matching behavior changes from prefix-only to glob-based pattern matching.
This commit is contained in:
5 files changed
+752
-707
No files matched your search
@@ -6,8 +6,11 @@
|
|||||||
local MURA = {}
|
local MURA = {}
|
||||||
|
|
||||||
MURA.config = {
|
MURA.config = {
|
||||||
-- Préfixe des dossiers-modules à charger (le * final est un wildcard).
|
-- Dossier(s)-module(s) à charger.
|
||||||
root = "bladw_*",
|
-- • 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",
|
||||||
-- 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" },
|
||||||
@@ -220,20 +223,40 @@ local function SendFolder(dir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Découverte des dossiers-modules correspondant au préfixe
|
-- Découverte des dossiers-modules
|
||||||
-- (file.Find ne supporte le wildcard que sur le dernier segment,
|
-- (file.Find ne supporte le wildcard que sur le dernier segment,
|
||||||
-- donc on liste la racine lua/ puis on filtre par préfixe.)
|
-- donc on liste la racine lua/ puis on filtre nous-mêmes.)
|
||||||
|
-- • pattern sans "*" -> match exact (un seul dossier)
|
||||||
|
-- • pattern avec "*" -> glob converti en motif Lua (préfixe/suffixe/milieu)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
|
--- Échappe les caractères magiques d'un motif Lua.
|
||||||
|
local function EscapePattern(s)
|
||||||
|
return (s:gsub("([%(%)%.%%%+%-%*%?%[%]%^%$])", "%%%1"))
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Transforme un glob simple ("bladw_*") en motif Lua ancré ("^bladw_.*$").
|
||||||
|
local function GlobToPattern(glob)
|
||||||
|
return "^" .. EscapePattern(glob):gsub("%%%*", ".*") .. "$"
|
||||||
|
end
|
||||||
|
|
||||||
local function FindRootFolders(pattern)
|
local function FindRootFolders(pattern)
|
||||||
local prefix = pattern:gsub("%*+$", "") -- "bladw_*" -> "bladw_"
|
local roots = {}
|
||||||
local roots = {}
|
|
||||||
|
-- Construit la fonction de test selon la présence ou non d'un wildcard.
|
||||||
|
local matches
|
||||||
|
if pattern:find("*", 1, true) then
|
||||||
|
local lua_pat = GlobToPattern(pattern)
|
||||||
|
matches = function(d) return d:match(lua_pat) ~= nil end
|
||||||
|
else
|
||||||
|
matches = function(d) return d == pattern end
|
||||||
|
end
|
||||||
|
|
||||||
local _, dirs1 = file.Find("*", "LUA")
|
local _, dirs1 = file.Find("*", "LUA")
|
||||||
local _, dirs2 = file.Find("lua/*", "GAME")
|
local _, dirs2 = file.Find("lua/*", "GAME")
|
||||||
|
|
||||||
for _, d in ipairs(Merge(dirs1, dirs2)) do
|
for _, d in ipairs(Merge(dirs1, dirs2)) do
|
||||||
if StartsWith(d, prefix) and not IsExcluded(d) then
|
if matches(d) and not IsExcluded(d) then
|
||||||
table.insert(roots, d)
|
table.insert(roots, d)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
local rndx = include("lib/rndx.lua")
|
||||||
|
|
||||||
|
hook.Add("HUDPaint", "BladeWin:Announcement", function()
|
||||||
|
local ply = LocalPlayer()
|
||||||
|
|
||||||
|
if not IsValid(ply) then return end
|
||||||
|
|
||||||
|
rndx.Draw(100, 343, 133, 788, 38, Color(30, 30, 30))
|
||||||
|
|
||||||
|
end)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
print("sv_function.lua")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
print("sh_config.lua")
|
||||||
+710
-700
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user