• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
no edit summary
Line 7: Line 7:     
     _grammar = {
 
     _grammar = {
         nodes = "^(%S+)%s*->%s*(%S+)$",
+
         split = "^%s*(.+)%s*->%s*(.+)%s*$",
         node_and_color = "^(%S+)/(%S+)$",
+
        comma_list = "[^,]+",
         digit_node = "^%d$",
+
         node_and_color = "^%s*(%a)%s*/%s*(%S+)%s*$",
 +
        node = "^%s*([%a%d])%s*$",
 +
         digit_node = "^%s*%d%s*$",
 
     },
 
     },
   Line 32: Line 34:  
]],
 
]],
   −
     _row_template = [[${separator}|class="mw-collapsible mw-collapsed" id="mw-customcollapsible-${id}" style="text-align:center;width:10%;"|${to}
+
     _row_template = [[${separator}|class="mw-collapsible mw-collapsed" id="mw-customcollapsible-${id}" style="text-align:center;width:10%;"|${to}${rules}]],
|
+
 
${rules}]],
+
    _rules = "\n|rowspan=\"${span}\"|\n${rules}",
    
     -- .kcRoute is defined in MediaWiki:Common.css
 
     -- .kcRoute is defined in MediaWiki:Common.css
Line 51: Line 53:  
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 63: Line 72:  
     for route, rules in pairs(args) do
 
     for route, rules in pairs(args) do
 
         if type(route) ~= "number" then
 
         if type(route) ~= "number" then
             local from, to = route:match(self._grammar.nodes)
+
             local from_node, to_nodes = route:match(self._grammar.split)
             if from and to then
+
             if from_node and to_nodes then
                 local from_, from_color = from:match(self._grammar.node_and_color)
+
                 local from_node_, from_node_color = from_node:match(self._grammar.node_and_color)
                 local to_, to_color = to:match(self._grammar.node_and_color)
+
                from_node = from_node_color and from_node_ or from_node:match(self._grammar.node)
                from = from_color and from_ or from
+
                 local first_node = nil
                to = to_color and to_ or to
+
                for to_node in string.gmatch(to_nodes, self._grammar.comma_list) do
                if not find(branching.index, from) then
+
                    local to_node_, to_node_color = to_node:match(self._grammar.node_and_color)
                    table.insert(branching.index, from)
+
                    to_node = to_node_color and to_node_ or to_node:match(self._grammar.node)
                end
+
                    if from_node and to_node then
                if not branching[from] then
+
                        if not find(branching.index, from_node) then
                    branching[from] = { color = from_color, index = {} }
+
                            table.insert(branching.index, from_node)
                end
+
                        end
                branching[from][to] = { color = to_color, rules = rules }
+
                        if not branching[from_node] then
                if not find(branching[from].index, to) then
+
                            branching[from_node] = { color = from_node_color, index = {} }
                    table.insert(branching[from].index, to)
+
                        end
 +
                        if not first_node then
 +
                        first_node = to_node
 +
                        branching[from_node][to_node] = { color = to_node_color, rules = rules, span = 1 }
 +
                        else
 +
                        branching[from_node][first_node].span = branching[from_node][first_node].span + 1
 +
                        branching[from_node][to_node] = { color = to_node_color }
 +
                        end
 +
                        if not find(branching[from_node].index, to_node) then
 +
                            table.insert(branching[from_node].index, to_node)
 +
                        end
 +
                    end
 
                 end
 
                 end
 
             end
 
             end
Line 100: Line 120:  
end
 
end
   −
function MapBranchingTable:prepare_rows()
+
function MapBranchingTable:format_rows()
 
     local branching = self._vars.branching
 
     local branching = self._vars.branching
 
     local rows = {}
 
     local rows = {}
     for _, from in ipairs(branching.index) do
+
     for _, from_node in ipairs(branching.index) do
 
         table.insert(rows, format{
 
         table.insert(rows, format{
 
             self._row_start_template,
 
             self._row_start_template,
             rowspan = #branching[from].index,
+
             rowspan = #branching[from_node].index,
             from = self:format_node(from, branching[from].color),
+
             from = self:format_node(from_node, branching[from_node].color),
 
             id = self._vars.id,
 
             id = self._vars.id,
 
         })
 
         })
 
         local first = true
 
         local first = true
         for _, to in ipairs(branching[from].index) do
+
         for _, to_node in ipairs(branching[from_node].index) do
 
             table.insert(rows, format{
 
             table.insert(rows, format{
 
                 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, branching[from][to].color),
+
                 to = self:format_node(to_node, branching[from_node][to_node].color),
                 rules = branching[from][to].rules,
+
                 rules = branching[from_node][to_node].rules and format{
 +
                    self._rules,
 +
                    rules = branching[from_node][to_node].rules,
 +
                    span = branching[from_node][to_node].span,
 +
                } or "",
 
                 id = self._vars.id,
 
                 id = self._vars.id,
 
             })
 
             })
Line 127: Line 151:  
function MapBranchingTable:format(args)
 
function MapBranchingTable:format(args)
 
     self:parse(args)
 
     self:parse(args)
     self:prepare_rows()
+
     self:format_rows()
 
     return format(self._template, self._vars)
 
     return format(self._template, self._vars)
 
end
 
end
Line 135: Line 159:  
end
 
end
   −
-- MapBranchingTable.t = MapBranchingTable.Table(nil, { ["0 -> 1"] = "Fixed route", ["1 -> B/green"] = "Random", ["1 -> C"] = "Random", ["title"] = "A Custom Title", "?" })
+
--[[
 +
MapBranchingTable.t = MapBranchingTable.Table(nil, {
 +
    ["0 -> 1"] = "Fixed route",
 +
    ["1 -> A, B/battle, C/empty"] = "Random",
 +
    ["title"] = "A Custom Title",
 +
    "?",
 +
})
 +
--print(p.t)
 +
--print(p._vars.log)
 +
]]--
    
return MapBranchingTable
 
return MapBranchingTable
cssedit, gkautomate
6,940

edits

Navigation menu