Line 10: |
Line 10: |
| comma_list = "[^,]+", | | comma_list = "[^,]+", |
| node_and_color = "^%s*(%a)%s*/%s*(%S+)%s*$", | | node_and_color = "^%s*(%a)%s*/%s*(%S+)%s*$", |
| + | node_and_color2 = "^%s*(%a)%s*/%s*(%S+)%s*/%s*(%S+)%s*$", |
| node = "^%s*([%a%d])%s*$", | | node = "^%s*([%a%d])%s*$", |
| digit_node = "^%s*%d%s*$", | | digit_node = "^%s*%d%s*$", |
Line 40: |
Line 41: |
| -- .kcRoute is defined in MediaWiki:Common.css | | -- .kcRoute is defined in MediaWiki:Common.css |
| _node_template = [[<div class="kcRoute" style="vertical-align:middle"><div class="kcRouteNode" style="background:${color};">${label}</div></div>]], | | _node_template = [[<div class="kcRoute" style="vertical-align:middle"><div class="kcRouteNode" style="background:${color};">${label}</div></div>]], |
| + | |
| + | _node_color2 = [[linear-gradient(90deg, ${color1} 50%, ${color2} 50%)]], |
| | | |
| _node_colors = { | | _node_colors = { |
Line 60: |
Line 63: |
| end | | end |
| self._vars.log = self._vars.log .. str .. "\n" | | self._vars.log = self._vars.log .. str .. "\n" |
| + | end |
| + | |
| + | function MapBranchingTable:parse_node(node_string) |
| + | local node, color1, color2 = node_string:match(self._grammar.node_and_color2) |
| + | if not node then |
| + | node, color1 = node_string:match(self._grammar.node_and_color) |
| + | end |
| + | if not node then |
| + | node = node_string:match(self._grammar.node) |
| + | end |
| + | return node, color1, color2 |
| end | | end |
| | | |
Line 75: |
Line 89: |
| local from_node, to_nodes = route:match(self._grammar.split) | | local from_node, to_nodes = route:match(self._grammar.split) |
| if from_node and to_nodes then | | if from_node and to_nodes then |
− | local from_node_, from_node_color = from_node:match(self._grammar.node_and_color) | + | local from_node_color1, from_node_color2 |
− | from_node = from_node_color and from_node_ or from_node:match(self._grammar.node) | + | from_node, from_node_color1, from_node_color2 = self:parse_node(from_node) |
| local first_node = nil | | local first_node = nil |
| for to_node in string.gmatch(to_nodes, self._grammar.comma_list) do | | for to_node in string.gmatch(to_nodes, self._grammar.comma_list) do |
− | local to_node_, to_node_color = to_node:match(self._grammar.node_and_color) | + | local to_node_color1, to_node_colo2 |
− | to_node = to_node_color and to_node_ or to_node:match(self._grammar.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 | | if not Utils.find(branching.index, from_node) then |
Line 86: |
Line 100: |
| end | | end |
| if not branching[from_node] then | | if not branching[from_node] then |
− | branching[from_node] = { color = from_node_color, index = {} } | + | branching[from_node] = { color = from_node_color1, color2 = from_node_color2, index = {} } |
| 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_color, rules = rules, span = 1 } | + | branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2, rules = rules, span = 1 } |
| 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_color } | + | branching[from_node][to_node] = { color = to_node_color1, color2 = to_node_color2 } |
| end | | end |
| if not Utils.find(branching[from_node].index, to_node) then | | if not Utils.find(branching[from_node].index, to_node) then |
Line 126: |
Line 140: |
| end | | end |
| | | |
− | function MapBranchingTable:format_node(label, color) | + | function MapBranchingTable:format_node(label, color, color2) |
| return label == "0" and self._start or format{ | | return label == "0" and self._start or format{ |
| self._node_template, | | self._node_template, |
Line 132: |
Line 146: |
| color = label:match(self._grammar.digit_node) | | color = label:match(self._grammar.digit_node) |
| and self._node_colors.grey | | and self._node_colors.grey |
| + | or color2 |
| + | and (format { |
| + | self._node_color2, |
| + | color1 = self._node_colors[color] or color or self._node_colors.battle, |
| + | color2 = self._node_colors[color2] or color2 or self._node_colors.battle, |
| + | }) |
| or self._node_colors[color] | | or self._node_colors[color] |
| or color | | or color |
Line 145: |
Line 165: |
| self._row_start_template, | | self._row_start_template, |
| rowspan = #branching[from_node].index, | | rowspan = #branching[from_node].index, |
− | from = self:format_node(from_node, branching[from_node].color), | + | from = self:format_node(from_node, branching[from_node].color, branching[from_node].color2), |
| id = self._vars.id, | | id = self._vars.id, |
| }) | | }) |
Line 153: |
Line 173: |
| self._row_template, | | self._row_template, |
| separator = first and "" or format{self._row_separator_template, id = self._vars.id}, | | separator = first and "" or format{self._row_separator_template, id = self._vars.id}, |
− | to = self:format_node(to_node, branching[from_node][to_node].color), | + | to = self:format_node(to_node, branching[from_node][to_node].color, branching[from_node][to_node].color2), |
| rules = branching[from_node][to_node].rules and format{ | | rules = branching[from_node][to_node].rules and format{ |
| self._rules, | | self._rules, |
Line 177: |
Line 197: |
| end | | end |
| | | |
− | --[[ | + | -- [[Category:Todo]]: make Module:Test maybe |
− | MapBranchingTable.t = MapBranchingTable.Table(nil, { | + | function MapBranchingTable:tests() |
− | ["0 -> 1"] = "Fixed route",
| + | return MapBranchingTable.Table(nil, { |
− | ["1 -> A, B/battle, C/empty"] = "Random",
| + | ["0 -> 1"] = "Fixed route", |
− | ["C -> F, G"] = "...",
| + | ["1 -> A, B/battle, C/empty"] = "Random", |
− | ["B -> D, E"] = "...",
| + | ["C -> F, G/battle/empty"] = "...", |
− | ["title"] = "A Custom Title",
| + | ["B -> D, E"] = "...", |
− | ["order"] = "C, B",
| + | ["title"] = "A Custom Title", |
− | "?",
| + | ["order"] = "C, B", |
− | }) | + | "?", |
− | --print(p.t)
| + | }) .. "\n" .. (self._vars.log or "") |
− | --print(p._vars.log) | + | end |
− | ]]--
| + | -- print(p:tests()) |
| | | |
| return MapBranchingTable | | return MapBranchingTable |