- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Module:MapBranchingTable
Jump to navigation
Jump to search
Documentation for this module may be created at Module:MapBranchingTable/doc
local getArgs = require("Module:GetArgs")
local format = require("Module:StringInterpolation").format
local templates = {
table_header = [[{| class="wikitable mw-collapsible mw-collapsed typography-xl-optout" style="width:100%;"
|-
!colspan="3"|<span style="float:left;padding-left:10px;">Branching Rules</span>
|-
!colspan="2"|Nodes||Rules
|-
]],
table_footer = "\n|}",
table_row_start = [[|rowspan="${rowspan}" style="text-align:center;vertical-align:middle;width:10%"|${from}]],
table_row = [[${separator}|style="text-align:center;"|${to}||${rules}]],
}
function formatTable(args)
local branching = {}
for route, rules in pairs(args) do
local from, to = route:match("(%S+)%s*->%s*(%S+)")
if branching[from] then
branching[from][to] = rules
else
branching[from] = {}
branching[from][to] = rules
end
end
local rows = {}
for from, tos in pairs(branching) do
table.insert(rows, format{
templates.table_row_start,
rowspan = 3,
from = from,
})
local first = true
for to, rules in pairs(tos) do
table.insert(rows, format{
templates.table_row,
separator = first and "|-\n" or "",
to = to,
rules = rules,
})
first = false
end
end
return templates.table_header .. table.concat(rows, "\n") .. templates.table_footer
end
local MapBranchingTable = {}
function MapBranchingTable.format(frame, args_)
local args = args_ or getArgs{frame = frame:getParent()}
return formatTable(args)
end
-- MapBranchingTable.t = MapBranchingTable.format(nil, { ["1 -> 2"] = "..." })
return MapBranchingTable