Line 1: |
Line 1: |
| + | -- [[Category:Todo]]: have Module:Logger to expose syntax warnings, similarly to Module:DropList (use it there as well). |
| + | |
| local getArgs = require("Module:GetArgs") | | local getArgs = require("Module:GetArgs") |
| local format = require("Module:StringOperations").format | | local format = require("Module:StringOperations").format |
Line 56: |
Line 58: |
| function make_id_from_title(title) | | function make_id_from_title(title) |
| return title:gsub("%s", ""):lower() | | return title:gsub("%s", ""):lower() |
− | end
| |
− |
| |
− | function MapBranchingTable:log(str)
| |
− | if not self._vars.log then
| |
− | self._vars.log = ""
| |
− | end
| |
− | self._vars.log = self._vars.log .. str .. "\n"
| |
| end | | end |
| | | |
Line 96: |
Line 91: |
| to_node, to_node_color1, to_node_color2 = self:parse_node(to_node) | | to_node, to_node_color1, to_node_color2 = self:parse_node(to_node) |
| if from_node and to_node then | | if from_node and to_node then |
− | if not Utils.find(branching.index, from_node) then | + | Utils.insertNew(branching.index, from_node) |
− | table.insert(branching.index, from_node)
| |
− | end
| |
| if not branching[from_node] then | | if not branching[from_node] then |
− | branching[from_node] = { color = from_node_color1, color2 = from_node_color2, index = {} } | + | branching[from_node] = { color = from_node_color1, color2 = from_node_color2, index = {}, indexes = { index = {}, groups = {} } } |
| end | | end |
| if not first_node then | | if not first_node then |
| first_node = to_node | | first_node = to_node |
| branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2, rules = rules, span = 1 } | | branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2, rules = rules, span = 1 } |
| + | if not branching[from_node].indexes.groups[first_node] then |
| + | table.insert(branching[from_node].indexes.index, first_node) |
| + | branching[from_node].indexes.groups[first_node] = { first_node } |
| + | end |
| else | | else |
| branching[from_node][first_node].span = branching[from_node][first_node].span + 1 | | branching[from_node][first_node].span = branching[from_node][first_node].span + 1 |
| branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2 } | | branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2 } |
− | end
| + | if branching[from_node].indexes.groups[first_node] then |
− | if not Utils.find(branching[from_node].index, to_node) then
| + | Utils.insertNew(branching[from_node].indexes.groups[first_node], to_node) |
− | table.insert(branching[from_node].index, to_node)
| + | end |
| end | | end |
| end | | end |
Line 136: |
Line 133: |
| table.sort(branching.index, sorting) | | table.sort(branching.index, sorting) |
| for _, from in ipairs(branching.index) do | | for _, from in ipairs(branching.index) do |
− | -- table.sort(branching[from].index, sorting) | + | table.sort(branching[from].indexes.index, sorting) |
| + | for _, first_node in ipairs(branching[from].indexes.index) do |
| + | for _, node in ipairs(branching[from].indexes.groups[first_node]) do |
| + | table.insert(branching[from].index, node) |
| + | end |
| + | end |
| end | | end |
| end | | end |
Line 197: |
Line 199: |
| end | | end |
| | | |
− | -- [[Category:Todo]]: make Module:Test maybe | + | --[[ |
− | function MapBranchingTable:tests()
| + | Utils.registerTableTests(MapBranchingTable, { |
− | return MapBranchingTable.Table(nil, { | + | { |
| ["0 -> 1"] = "Fixed route", | | ["0 -> 1"] = "Fixed route", |
− | ["1 -> A, B/battle, C/empty"] = "Random", | + | ["1 -> C/empty, D"] = "Random", |
| + | ["1 -> A, B/battle, X/empty"] = "Random", |
| ["C -> F, G/battle/empty"] = "...", | | ["C -> F, G/battle/empty"] = "...", |
| ["B -> D, E"] = "...", | | ["B -> D, E"] = "...", |
| ["title"] = "A Custom Title", | | ["title"] = "A Custom Title", |
− | ["order"] = "C, B", | + | ["order"] = "C, A, 1, B", |
| "?", | | "?", |
− | }) .. "\n" .. (self._vars.log or "") | + | } |
− | end
| + | }) |
− | -- print(p:tests()) | + | -- p.run_table_tests() |
| + | ]]-- |
| | | |
| return MapBranchingTable | | return MapBranchingTable |