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:41, 13 August 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

-- Submodules
local Helpers       = require('Module:Build bracket/Helpers')
local Config        = require('Module:Build bracket/Config')
local Params        = require('Module:Build bracket/Params')
local StateChecks   = require('Module:Build bracket/StateChecks')
local Logic         = require('Module:Build bracket/Logic')
local Paths         = require('Module:Build bracket/Paths')
local Render        = require('Module:Build bracket/Render')
--local Deprecations  = require('Module:Build bracket/Deprecations')

-- Optional: version tag for debugging
local VERSION = 'Build Bracket split v1'

-- Entry
function p.main(frame)
  -- Mutable containers shared across passes
  local state  = {
    headerindex    = {},
    rlegs          = {},
    maxlegs        = {},
    hascross       = {},
    crossCell      = {},
    pathCell       = {},
    skipPath       = {},
    hide           = {},
    byes           = {},
    teamsPerMatch  = {},
    matchgroup     = {},
--    deprecated_hits = {},
    maxtpm         = 0,
  }
--  local config = {
--    -- you can override defaults here if desired
--    deprecations = {
--      -- examples (safe to remove/extend):
--      paramstyle = { indexed = true },
--      ['*-byes'] = { y = true, yes = true },
--    }
--  }

  -- 0) Initialize config + arg accessors
  Config.init(frame, state, config, Helpers)

  -- 1) Deprecations: scan early
--  if Deprecations and Deprecations.check then
--    Deprecations.check(state, config, Helpers)
--  end

  -- 2) Build structure from params (headers/teams/lines/text/groups skeleton)
  Params.buildSkeleton(state, config, Helpers, StateChecks)

  -- 3) Index structure: alt indices, byes/hide flags
  Params.scanStructure(state, config, Helpers, StateChecks)

  -- 4) Assign per-entry params (seed/team/score/header/text/group/etc.)
  Params.assign(state, config, Helpers, StateChecks)

  -- 5) Logic passes
  Logic.updateMaxLegs(state, config, Helpers)
  Logic.matchGroups(state, config)                                      -- uses teamsPerMatch/indexing
  Logic.computeAggregate(state, config, Helpers, StateChecks)           -- fills score.agg if needed
  Logic.boldWinner(state, config, Helpers, StateChecks)                 -- bold per leg/team

  -- 6) Paths (wiring between rounds) + groups derived from paths
  Paths.build(state, config, Helpers, StateChecks)                      -- builds pathCell/crossCell/skipPath
  Paths.attachGroups(state, config, Helpers, StateChecks)               -- injects group cells where needed

  -- 7) Render
  local html = Render.buildTable(state, config, Helpers, StateChecks)

  -- 8) Append deprecation categories (mainspace only, unless nocat)
--  local cats = ''
--  if Deprecations and Deprecations.emit then
--    cats = Deprecations.emit(state, config, Helpers) or ''
--  end

  -- Return string (mw.html or string)
  return tostring(html) .. cats
end

-- Convenience alias so {{#invoke:Build Bracket|}} works without naming main
p._main = p.main

-- Debug helper (optional)
function p._version()
  return VERSION
end

return p