feat(bladWinRpMenu_loader): add support for pattern groups with alternatives syntax
Implement pattern group expansion allowing alternatives separated by '+' within parentheses. Examples: - "bladw_(ann*+warn)" expands to ["bladw_ann*", "bladw_warn"] - Supports multiple groups with recursive Cartesian product expansion - Refactor matching logic into separate Matcher() function for clarity - Update root pattern in config from "bladw_announcement*" to "bladw_(ann*+warn)"
This commit is contained in:
@@ -10,8 +10,10 @@ 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)
|
||||||
|
-- • groupes "(a+b)" -> alternatives séparées par + :
|
||||||
|
-- "bladw_(ann*+warn)" = bladw_ann* OU bladw_warn (les alt peuvent avoir des *)
|
||||||
-- • "none" (ou vide/nil) -> loader désactivé, rien n'est chargé
|
-- • "none" (ou vide/nil) -> loader désactivé, rien n'est chargé
|
||||||
root = "bladw_announcement*",
|
root = "bladw_(ann*+warn)",
|
||||||
-- 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" },
|
||||||
@@ -237,16 +239,52 @@ local function GlobToPattern(glob)
|
|||||||
return "^" .. EscapePattern(glob):gsub("%%%*", ".*") .. "$"
|
return "^" .. EscapePattern(glob):gsub("%%%*", ".*") .. "$"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Étend les groupes "(a+b)" en plusieurs motifs plats.
|
||||||
|
-- "bladw_(ann*+warn)" -> { "bladw_ann*", "bladw_warn" }
|
||||||
|
-- Gère plusieurs groupes (produit cartésien) via récursion sur le suffixe.
|
||||||
|
local function ExpandPattern(pattern)
|
||||||
|
local open = pattern:find("(", 1, true)
|
||||||
|
if not open then return { pattern } end
|
||||||
|
|
||||||
|
local close = pattern:find(")", open + 1, true)
|
||||||
|
if not close then return { pattern } end -- parenthèse non fermée -> littéral
|
||||||
|
|
||||||
|
local prefix = pattern:sub(1, open - 1)
|
||||||
|
local group = pattern:sub(open + 1, close - 1)
|
||||||
|
local suffix = pattern:sub(close + 1)
|
||||||
|
|
||||||
|
local out = {}
|
||||||
|
for _, alt in ipairs(string.Explode("+", group)) do
|
||||||
|
for _, exp in ipairs(ExpandPattern(prefix .. alt .. suffix)) do
|
||||||
|
out[#out + 1] = exp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Construit un testeur (dossier -> bool) pour un motif plat (avec ou sans "*").
|
||||||
|
local function Matcher(p)
|
||||||
|
if p:find("*", 1, true) then
|
||||||
|
local lua_pat = GlobToPattern(p)
|
||||||
|
return function(d) return d:match(lua_pat) ~= nil end
|
||||||
|
end
|
||||||
|
return function(d) return d == p end
|
||||||
|
end
|
||||||
|
|
||||||
local function FindRootFolders(pattern)
|
local function FindRootFolders(pattern)
|
||||||
local roots = {}
|
local roots = {}
|
||||||
|
|
||||||
-- Construit la fonction de test selon la présence ou non d'un wildcard.
|
-- On étend les groupes puis on teste chaque motif : un dossier matche si l'un d'eux matche.
|
||||||
local matches
|
local matchers = {}
|
||||||
if pattern:find("*", 1, true) then
|
for _, p in ipairs(ExpandPattern(pattern)) do
|
||||||
local lua_pat = GlobToPattern(pattern)
|
matchers[#matchers + 1] = Matcher(p)
|
||||||
matches = function(d) return d:match(lua_pat) ~= nil end
|
end
|
||||||
else
|
|
||||||
matches = function(d) return d == pattern end
|
local function matches(d)
|
||||||
|
for _, m in ipairs(matchers) do
|
||||||
|
if m(d) then return true end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, dirs1 = file.Find("*", "LUA")
|
local _, dirs1 = file.Find("*", "LUA")
|
||||||
|
|||||||
Reference in New Issue
Block a user