Module:Build bracket/Config

local Config = {}

-- ====================================
-- 1) INIT & DEFENSIVE ACCESSORS
-- ====================================
function Config.init(frame, state, config, Helpers)
    -- Defend against nil inputs; don't mutate caller refs
    state   = state   or {}
    config  = config  or {}
    Helpers = Helpers or {}

    -- Pull args from frame/parent (both optional)
    local fargs  = (frame and frame.args) or {}
    local parent = (frame and frame.getParent and frame:getParent()) or nil
    local pargs  = (parent and parent.args) or {}

    -- Keep originals for debugging
    config._fargs, config._pargs = fargs, pargs

    -- Install arg accessors (use provided installer if present)
    if Helpers.installArgAccessors then
        Helpers.installArgAccessors(fargs, pargs)
    else
        Helpers.getFArg = function(k) return fargs[k] end
        Helpers.getPArg = function(k) return pargs[k] end
        Helpers.bargs   = function(k)
            local v = pargs[k]
            if v == nil or v == "" then v = fargs[k] end
            return v
        end
    end

    -- Short aliases
    local bargs   = Helpers.bargs
    local getFArg = Helpers.getFArg
    local getPArg = Helpers.getPArg

    -- ====================================
    -- 2) YES/NO FALLBACKS (robust parsing)
    -- ====================================
    local function yesish(s)
        s = (s or ""):lower()
        return s == "y" or s == "yes" or s == "true" or s == "1"
    end
    local function noish(s)
        s = (s or ""):lower()
        return s == "n" or s == "no" or s == "false" or s == "0"
    end

    -- Prefer Helpers.yes/no if provided; fall back to yesish/noish
    local YES = Helpers.yes or yesish
    local NO  = Helpers.no  or noish

    -- ====================================
    -- 3) CORE DIMENSIONS & CLAMPING
    -- ====================================
    -- Rows: keep '' sentinel when user didn’t set |rows=|
    config.r = tonumber(getFArg("rows")) or ""

    -- Rounds: {{#invoke:..|rounds=}} with optional parent override maxround(s)
    local rounds_f = tonumber(getFArg("rounds")) or 1
    local maxc     = tonumber(getPArg("maxrounds")) or tonumber(getPArg("maxround")) or nil

    config.c = (type(maxc) == "number") and maxc or rounds_f

    -- minround -> base (clamped)
    local minr = tonumber(getPArg("minround")) or 1
    if minr < 1 then minr = 1 end
    if minr > config.c then minr = config.c end
    config.minc   = minr
    config.base   = minr - 1
    config.c_total = config.c  -- persist original visible round count

    -- ====================================
    -- 4) LAYOUT/STYLE FLAGS
    -- ====================================
    config.autocol    = YES(getFArg("autocol"))
    config.colspacing = tonumber(getFArg("col-spacing")) or 6
    config.height     = bargs("height")

    -- nowrap can be supplied in parent or direct call
    local nowrapArg = getPArg("nowrap") or getFArg("nowrap")
    config.nowrap = not NO(nowrapArg)

    -- ====================================
    -- 5) BOLDWINNER MODE/POLICY
    -- ====================================
    local bw = (bargs("boldwinner") or ""):lower()
    config.boldwinner           = bw
    config.boldwinner_mode      = "off"   -- 'high' | 'low' | 'off'
    config.boldwinner_aggonly   = false   -- only bold aggregate cell/row

    if bw == "low" then
        config.boldwinner_mode = "low"
    elseif bw == "high" or YES(bw) then
        config.boldwinner_mode = "high"
    elseif bw == "aggregate" or bw == "agg" or bw == "aggregate-high" or bw == "agg-high" then
        config.boldwinner_mode    = "high"
        config.boldwinner_aggonly = true
    elseif bw == "aggregate-low" or bw == "agg-low" then
        config.boldwinner_mode    = "low"
        config.boldwinner_aggonly = true
    end

    if YES(bargs("boldwinner-aggregate-only")) then
        config.boldwinner_aggonly = true
    end

    -- ====================================
    -- 6) SEEDS & AGGREGATE SETTINGS
    -- ====================================
    -- forceseeds: explicit truthy; seeds: true unless explicitly "no"
    local seedsArg       = bargs("seeds")
    config.forceseeds    = YES(seedsArg)
    config.seeds         = not NO(seedsArg)

    -- aggregate mode
    do
        local aval = (bargs("aggregate") or ""):lower()
        if aval == "sets" or aval == "legs" then
            config.aggregate_mode = "sets"
        elseif aval == "score" then
            config.aggregate_mode = "score"
        elseif YES(aval) then
            config.aggregate_mode = "manual"
        else
            config.aggregate_mode = "off"
        end
        config.aggregate = (config.aggregate_mode ~= "off")
    end

    -- show-bye-paths (default true; only explicit "no" disables)
    do
        local v = (bargs("show-bye-paths") or ""):lower()
        config.show_bye_paths = (v == "") and true or (not NO(v))
    end

    -- autolegs (explicit truthy)
    config.autolegs = YES(bargs("autolegs"))

    -- ====================================
    -- 7) PARAMSTYLE INFERENCE
    -- ====================================
    local styleArg = (bargs("paramstyle") or ""):lower()
    local function hasNumberedArgs()
        -- Scan a reasonable window of positional args from both parent/frame via bargs
        for n = 1, 48 do
            local v = bargs(tostring(n))
            if v ~= nil and v ~= "" then return true end
        end
        return false
    end

    if styleArg == "numbered" then
        config.paramstyle = "numbered"
    elseif styleArg == "indexed" then
        config.paramstyle = "indexed"
    else
        config.paramstyle = hasNumberedArgs() and "numbered" or "indexed"
    end

    -- ====================================
    -- 8) THEME CONSTANTS (DEFAULTS)
    -- ====================================
    config.COLORS = config.COLORS or {
        cell_bg_light   = "var(--background-color-neutral-subtle,#f8f9fa)",
        cell_bg_dark    = "var(--background-color-neutral,#eaecf0)",
        text_color      = "var(--color-base,#202122)",
        path_line_color = "gray",
        cell_border     = "var(--border-color-base,#a2a9b1)"
    }

    return state, config, Helpers
end

return Config

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.