Line 11: |
Line 11: |
| split = "^%s*(.+)%s*->%s*(.+)%s*$", | | split = "^%s*(.+)%s*->%s*(.+)%s*$", |
| comma_list = "[^,]+", | | comma_list = "[^,]+", |
− | node_and_color = "^%s*(%a)%s*/%s*(%S+)%s*$", | + | node_and_colors = "^%s*([%a%d]+)%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 42: |
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="${class}" style="background:${color};">${label}</div></div>]], | + | _node_template = [[<div class="kcRoute" style="vertical-align:middle"><div class="${class}" style="${style}">${label}</div></div>]], |
| + | |
| + | _node_color1 = [[background: ${color};]], |
| | | |
− | _node_color2 = [[linear-gradient(90deg, ${color1} 50%, ${color2} 50%)]], | + | _node_color2 = [[background: linear-gradient(90deg, ${color1} 50%, ${color2} 50%)]], |
| + | |
| + | _node_color3 = [[background: linear-gradient(-30deg, transparent 60%, ${color1} 60%) 0% 100%, linear-gradient(30deg, transparent 60%, ${color2} 60%) 100% 100%, linear-gradient(${color3}, ${color3}) 0% 100%, linear-gradient(${color3}, ${color3}) 100% 100%, linear-gradient(${color1}, ${color1}) 0% 0%, linear-gradient(${color2}, ${color2}) 100% 0%; background-repeat: no-repeat; background-size: 50% 50%;]], |
| + | |
| + | _node_color4 = [[background: linear-gradient(${color1}, ${color1}) 0% 0%, linear-gradient(${color2}, ${color2}) 100% 0%, linear-gradient(${color3}, ${color3}) 100% 100%, linear-gradient(${color4}, ${color4}) 0% 100%; background-size: 50% 50%; background-repeat: no-repeat;]], |
| | | |
| _node_colors = { | | _node_colors = { |
Line 52: |
Line 57: |
| storm = "#EA80FC", -- Purple A100 | | storm = "#EA80FC", -- Purple A100 |
| empty = "#40C4FF", -- Light Blue A200 | | empty = "#40C4FF", -- Light Blue A200 |
| + | night = "#7E57C2", -- Deep Purple 400 |
| + | nightday_night = { "battle", "night", "night", "night" }, |
| + | night_battle_empty = { "night", "battle", "empty" }, |
| }, | | }, |
| | | |
Line 61: |
Line 69: |
| | | |
| function MapBranchingTable:parse_node(node_string) | | function MapBranchingTable:parse_node(node_string) |
− | local node, color1, color2 = node_string:match(self._grammar.node_and_color2) | + | local node, colors = node_string:match(self._grammar.node_and_colors) |
− | if not node then
| |
− | node, color1 = node_string:match(self._grammar.node_and_color)
| |
− | end
| |
| if not node then | | if not node then |
| node = node_string:match(self._grammar.node) | | node = node_string:match(self._grammar.node) |
| + | else |
| + | colors = mw.text.split(colors, "%s*/%s*") |
| end | | end |
− | return node, color1, color2 | + | return node, colors |
| end | | end |
| | | |
Line 84: |
Line 91: |
| 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_color1, from_node_color2 | + | local from_node_colors |
− | from_node, from_node_color1, from_node_color2 = self:parse_node(from_node) | + | from_node, from_node_colors = 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_color1, to_node_colo2 | + | local to_node_colors |
− | to_node, to_node_color1, to_node_color2 = self:parse_node(to_node) | + | to_node, to_node_colors = self:parse_node(to_node) |
| if from_node and to_node then | | if from_node and to_node then |
| Utils.insertNew(branching.index, from_node) | | Utils.insertNew(branching.index, from_node) |
| if not branching[from_node] then | | if not branching[from_node] then |
− | branching[from_node] = { color = from_node_color1, color2 = from_node_color2, index = {}, indexes = { index = {}, groups = {} } } | + | branching[from_node] = { |
| + | colors = from_node_colors, |
| + | 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] = { |
| + | colors = to_node_colors, |
| + | rules = rules, |
| + | span = 1 |
| + | } |
| if not branching[from_node].indexes.groups[first_node] then | | if not branching[from_node].indexes.groups[first_node] then |
| table.insert(branching[from_node].indexes.index, first_node) | | table.insert(branching[from_node].indexes.index, first_node) |
Line 104: |
Line 119: |
| 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] = { colors = to_node_colors } |
| if branching[from_node].indexes.groups[first_node] then | | if branching[from_node].indexes.groups[first_node] then |
| Utils.insertNew(branching[from_node].indexes.groups[first_node], to_node) | | Utils.insertNew(branching[from_node].indexes.groups[first_node], to_node) |
Line 142: |
Line 157: |
| end | | end |
| | | |
− | function MapBranchingTable:format_node(label, color, color2) | + | function MapBranchingTable:format_color(color) |
| + | return self._node_colors[color] or color or self._node_colors.battle |
| + | end |
| + | |
| + | function MapBranchingTable:format_node(label, colors) |
| + | local style |
| + | if label:match(self._grammar.digit_node) then |
| + | style = format{self._node_color1, color = self._node_colors.grey} |
| + | elseif not colors or #colors == 0 then |
| + | style = format{self._node_color1, color = self._node_colors.battle} |
| + | elseif #colors == 1 then |
| + | if type(self._node_colors[colors[1]]) == "table" then |
| + | return self:format_node(label, self._node_colors[colors[1]]) |
| + | end |
| + | style = format{self._node_color1, color = self:format_color(colors[1])} |
| + | elseif #colors == 2 then |
| + | style = format{ |
| + | self._node_color2, |
| + | color1 = self:format_color(colors[1]), |
| + | color2 = self:format_color(colors[2]), |
| + | } |
| + | elseif #colors == 3 then |
| + | style = format{ |
| + | self._node_color3, |
| + | color1 = self:format_color(colors[1]), |
| + | color2 = self:format_color(colors[2]), |
| + | color3 = self:format_color(colors[3]), |
| + | } |
| + | elseif #colors >= 4 then |
| + | style = format{ |
| + | self._node_color4, |
| + | color1 = self:format_color(colors[1]), |
| + | color2 = self:format_color(colors[2]), |
| + | color3 = self:format_color(colors[3]), |
| + | color4 = self:format_color(colors[4]), |
| + | } |
| + | end |
| return label == "0" and self._start or format{ | | return label == "0" and self._start or format{ |
| self._node_template, | | self._node_template, |
| label = label, | | label = label, |
| class = #label > 1 and "kcRouteNodeWide" or "kcRouteNode", | | class = #label > 1 and "kcRouteNodeWide" or "kcRouteNode", |
− | color = label:match(self._grammar.digit_node) | + | style = style |
− | 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 color
| |
− | or self._node_colors.battle
| |
| } | | } |
| end | | end |
Line 168: |
Line 209: |
| 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, branching[from_node].color2), | + | from = self:format_node(from_node, branching[from_node].colors), |
| id = self._vars.id, | | id = self._vars.id, |
| }) | | }) |
Line 176: |
Line 217: |
| 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, branching[from_node][to_node].color2), | + | to = self:format_node(to_node, branching[from_node][to_node].colors), |
| rules = branching[from_node][to_node].rules and format{ | | rules = branching[from_node][to_node].rules and format{ |
| self._rules, | | self._rules, |
Line 206: |
Line 247: |
| ["1 -> A, B/battle, X/empty"] = "Random", | | ["1 -> A, B/battle, X/empty"] = "Random", |
| ["C -> F, G/battle/empty"] = "...", | | ["C -> F, G/battle/empty"] = "...", |
− | ["B -> D, E"] = "...", | + | ["B -> D/red/green/blue, E/red/green/blue/yellow"] = "...", |
| + | ["X -> Y/nightday_night, Z/night_battle_empty"] = "...", |
| + | ["Z1 -> Z2, Z3"] = "...", |
| + | ["ZZ1 -> ZZ2, ZZ3"] = "...", |
| ["title"] = "A Custom Title", | | ["title"] = "A Custom Title", |
| ["order"] = "C, A, 1, B", | | ["order"] = "C, A, 1, B", |