Jump to content

Module:Build bracket/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pbrks (talk | contribs) at 04:16, 13 August 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Module:Build Bracket/Main
local p = {}

-- Shared state & config for the whole render
local state = {
  -- tables many passes will fill:
  entries     = {},   -- per-column, per-row entry objects
  rlegs       = {},   -- default legs per round
  maxlegs     = {},   -- computed max legs per round
  matchgroup  = {},   -- team index -> match group
  pathCell    = {},   -- path drawing matrix
  crossCell   = {},   -- cross-path metadata
  skipPath    = {},   -- rows to skip when rendering path cells
  hascross    = {},   -- whether a col pair has cross paths
  headerindex = {},   -- running header counters per round
  byes        = {},   -- byes flags per header
  hide        = {},   -- hidden-header flags per header
  teamsPerMatch = {}, -- optional override per round (default 2)
}

local config = {
  -- global switches are set in Config.init(...)
  -- e.g. autocol, c (round count), r (row count), aggregate_mode, boldwinner_mode, etc.
}

-- Submodules
local Config      = require('Module:build Bracket/Config')
local Helpers     = require('Module:build Bracket/Helpers')
local StateChecks = require('Module:build Bracket/StateChecks')
local Params      = require('Module:build Bracket/Params')
local Logic       = require('Module:build Bracket/Logic')
local Paths       = require('Module:build Bracket/Paths')
local Render      = require('Module:build Bracket/Render')

-- Optional: a single public entrypoint. Rename to p.bracket if you prefer.
function p.main(frame)
  ---------------------------------------------------------------------------
  -- 1) Parse args, populate config, and prepare helper closures (bargs, etc)
  ---------------------------------------------------------------------------
  -- Config.init should:
  --   - capture frame.args / frame:getParent().args into config._fargs/_pargs
  --   - define Helpers.bargs = function(k) return config._pargs[k] or config._fargs[k] end
  --   - set switches like config.c, config.r, config.autocol, aggregate/boldwinner modes, etc.
  Config.init(frame, state, config, Helpers)

  ----------------------------------------------------------------------------
  -- 2) Discover structure (header indexing, byes, hides) before assigning data
  ----------------------------------------------------------------------------
  -- This should walk the prebuilt state.entries “shape” (however you build it)
  -- and fill state.headerindex[j], state.byes[j][k], state.hide[j][k], etc.
  Params.scanStructure(state, config, Helpers, StateChecks)

  ------------------------------------------------------------
  -- 3) Resolve/assign all parameters into state.entries cells
  ------------------------------------------------------------
  -- This should run paramNames/indexedParams and then assign* functions to
  -- populate seeds/team/score/header/text/group/etc. per entry.
  Params.assign(state, config, Helpers, StateChecks)

  ------------------------------------------------
  -- 4) Core logic passes: sizes, groups, outcomes
  ------------------------------------------------
  Logic.updateMaxLegs(state, config, Helpers)
  Logic.matchGroups(state, config)                 -- compute match groups
  Logic.computeAggregate(state, config, Helpers)   -- sets/score aggregates
  Logic.boldWinner(state, config)                  -- bold leg/agg/team winners

  -----------------------------------------
  -- 5) Build path matrices (no rendering)
  -----------------------------------------
  Paths.build(state, config, Helpers, StateChecks) -- fills pathCell/crossCell/skipPath

  -------------------------
  -- 6) Render final table
  -------------------------
  -- Render.buildTable should loop rows/cols and call insertEntry/insertPath.
  return Render.buildTable(state, config, Helpers, StateChecks)
end

return p