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 05:08, 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')

local VERSION = 'Build Bracket split v1'

function p.main(frame)
  -- Shared mutable state
  local state = {
    headerindex    = {},
    rlegs          = {},
    maxlegs        = {},
    hascross       = {},
    crossCell      = {},
    pathCell       = {},
    skipPath       = {},
    hide           = {},
    byes           = {},
    teamsPerMatch  = {},
    matchgroup     = {},
    maxtpm         = 0,
  }

  -- Config must exist
  local config = {
    -- deprecations = { paramstyle = { indexed = true }, ['*-byes'] = { y = true, yes = true }, }
  }

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

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

  -- 2) Build structure skeleton from args
  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 (between rounds) + attach derived group cells
  Paths.build(state, config, Helpers, StateChecks)                      -- builds pathCell/crossCell/skipPath
  Paths.attachGroups(state, config, Helpers, StateChecks)               -- injects group ctype cells if needed

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

  -- 8) Deprecation categories (optional)
  local cats = ''
  -- if Deprecations and Deprecations.emit then
  --   cats = Deprecations.emit(state, config, Helpers) or ''
  -- end

  return tostring(html) .. cats
end

p._main = p.main

function p._version()
  return VERSION
end

return p