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

Difference between revisions of "Module:MapBranching"

From Kancolle Wiki
Jump to navigation Jump to search
(Created page with "local p = {} -- Module for map branching written by -- Remi_Scarlet -- I fucking hate lua. local remiLib = require("Module:RemiLib") function p.renderBranchingTable(graph)...")
 
(Undo revision 311448 by Totaku (talk))
 
(5 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
-- Remi_Scarlet
 
-- Remi_Scarlet
 
-- I fucking hate lua.
 
-- I fucking hate lua.
 +
 +
-- 10/24/15 Added colorful blue button thing
 +
-- 5/5/16 Added multiple start location support
  
 
local remiLib = require("Module:RemiLib")
 
local remiLib = require("Module:RemiLib")
  
function p.renderBranchingTable(graph)
+
function p.renderBranchingTable(graph, collapsed)
 +
 +
    local uniqueID = remiLib.timeHash(graph)
 +
    local classString = "mw-customtoggle-" .. tostring(uniqueID)
 +
    local idString = "mw-customcollapsible-" .. tostring(uniqueID)
 +
   
 +
    local button = mw.html.create('div')
 +
    button
 +
    :addClass(classString)
 +
    :addClass("globalbutton")
 +
    :wikitext("Show/Hide Branching Rules")
 +
 
 
     local body = mw.html.create("table")
 
     local body = mw.html.create("table")
     body:addClass("wikitable")
+
     body
 +
        :addClass("mw-collapsible")
 +
        :addClass("wikitable")
 +
        :addClass("mw-collapsed")
 +
        :attr("id",idString)
 +
        :css("width","300px")
 +
       
 
     local titleRow = mw.html.create("tr")
 
     local titleRow = mw.html.create("tr")
 
     local th = mw.html.create("th")
 
     local th = mw.html.create("th")
 
     th
 
     th
 
         :attr("colspan",3) -- "from" node, "to" node, requirement text
 
         :attr("colspan",3) -- "from" node, "to" node, requirement text
         :wikitext("Branching Rules for Maps")
+
         :wikitext("Branching Rules")
 
         :css("font-weight","bold")
 
         :css("font-weight","bold")
 
         :css("text-align","center")
 
         :css("text-align","center")
Line 50: Line 70:
 
     -- toTable is a table of all the to's
 
     -- toTable is a table of all the to's
 
     --
 
     --
     local possibleStarts = remiLib.mergeArrays({"START"},remiLib.uppercase)
+
     local possibleNodes = remiLib.mergeArrays({"START", "START-1", "START-2",
     for _,from in pairs(possibleStarts) do
+
        "START-3", "START-4", "START-5"}
 +
      ,remiLib.uppercase)
 +
    -- 5/5/16
 +
    -- Since multiple start paths are possible (Eg, starting from two different places)
 +
    -- adding the ability to specify multiple start points. Assuming no more than 5 start points ever lol.
 +
    -- Yeah yeah I get that it's bad code design. Shut up, I don't care enough to put more than 5 minutes of thought into this.
 +
     for _,from in pairs(possibleNodes) do
 
         if graph[from] ~= nil then
 
         if graph[from] ~= nil then
 
             local toTable = graph[from]
 
             local toTable = graph[from]
Line 65: Line 91:
 
             -- instance of the "to" node connecting to a "from" node
 
             -- instance of the "to" node connecting to a "from" node
 
             local isFirstTo = true
 
             local isFirstTo = true
             for _,toNode in pairs(remiLib.uppercase) do
+
             for _,toNode in pairs(possibleNodes) do
 
                 if toTable[toNode] ~= nil then
 
                 if toTable[toNode] ~= nil then
 
                     if not isFirstTo then
 
                     if not isFirstTo then
Line 87: Line 113:
 
         end
 
         end
 
     end
 
     end
     return tostring(body)
+
     return tostring(button) .. "\n" .. tostring(body)
 
end  
 
end  
  
Line 93: Line 119:
 
     -- implementing graph as an adjacency list
 
     -- implementing graph as an adjacency list
 
     local mapGraph = {}
 
     local mapGraph = {}
 +
    local collapsed = true
 +
    if frame.args["collapsed"] ~= nil and string.lower(frame.args["collapsed"]) == "false" then
 +
        collapsed = false
 +
    end
  
 
     for param,value in pairs(frame.args) do
 
     for param,value in pairs(frame.args) do
Line 99: Line 129:
 
         -- second val in split is "to" as above
 
         -- second val in split is "to" as above
 
         -- first and third should be length 1 cuz they should be singular letters
 
         -- first and third should be length 1 cuz they should be singular letters
         if #split == 3 and string.lower(split[2]) == "to" and (#split[1] == 1 or string.lower(split[1]) == "start") and #split[3] == 1 then
+
         if #split == 3 and  
 +
          string.lower(split[2]) == "to" and  
 +
          (#split[1] == 1 or (string.find(string.lower(split[1]),"start") ~= nil)) and  
 +
          (#split[3] == 1 or (string.find(string.lower(split[3]),"start") ~= nil))then
 
             local from = string.upper(split[1])
 
             local from = string.upper(split[1])
 
             local to = string.upper(split[3])
 
             local to = string.upper(split[3])
             if (remiLib.valid(from,remiLib.letters) or string.lower(from) == "start")and remiLib.valid(to,remiLib.letters) then
+
             if (remiLib.valid(from,remiLib.letters) or (string.find(string.lower(split[1]),"start") ~= nil)) and  
 +
              (remiLib.valid(to,remiLib.letters) or (string.find(string.lower(split[3]),"start") ~= nil))then
 
                 if mapGraph[from] == nil then
 
                 if mapGraph[from] == nil then
 
                     mapGraph[from] = {}
 
                     mapGraph[from] = {}
Line 110: Line 144:
 
         end
 
         end
 
     end
 
     end
     local html = p.renderBranchingTable(mapGraph)
+
    --local html = remiLib.dictConcat(table.getKeys(mapGraph["START-4"]),"|")
 +
     local html = p.renderBranchingTable(mapGraph,collapsed)
  
 
     return html
 
     return html

Latest revision as of 20:49, 2 February 2017

Parameter Naming

Module invocation is done via passing parameters and arguments. These parameter names and argument values are all done in the following format

  • <"From" Node>_to_<"To" Node> = <argument value>

except for assigning node labels which is shown below.

All parameters still need a pipe character, "|", before the parameter call. Eg, (replace '{' with '{{')

  • {#invoke:MapBranching | branchingTemplate

|start_to_A = This is the branching info from the start node to node A
|start_to_start-1 = This is branching info for starting at the first start node. Eg, when CTF/STF determines your starting node |A_to_B = This is branching info from node A to node B
|A_to_C = This is branching info from node A to node C
}

All parameters passed to the MapBranching module are named under a simple scheme as described in each subsequent section.
You may add span and css tags as you wish as they will be pasted in directly to the page. Examples are below.

Everything is Case-Insensitive'

Node Names

There are only two types of nodes that can be used in either the "From" node or "To" node

  • Start => This indicates the starting node when you first load into a map. This is the starting node that comes before even node A.
  • Start-# => Where # is 1 through 5 (because when are we really going to have more than 5 start points). This will simply indicate which start position. Refer to the Spring 2016 event page for examples.
  • Any alphabet => These respectively reflect the node names.

Example Invocation

{{#invoke:MapBranching|branchingTemplate
|B_to_C = Active Branching
|B_to_D = Active Branching
|C_to_E = Change of E with 4 or more CL?<br>Failure on LoS check to H
|C_to_H = LoS check <br> Failure sends to E
|F_to_H = LoS check for H. <br>Failure sends to G
|F_to_G = 5 or more CL}}

Results in

Show/Hide Branching Rules
Branching Rules
NodeSplitCondition
BCActive Branching
DActive Branching
CEChange of E with 4 or more CL?
Failure on LoS check to H
HLoS check
Failure sends to E
FG5 or more CL
HLoS check for H.
Failure sends to G

Credit

Module written by Remi_Scarlet


local p = {}

-- Module for map branching written by
-- Remi_Scarlet
-- I fucking hate lua.

-- 10/24/15 Added colorful blue button thing
-- 5/5/16 Added multiple start location support

local remiLib = require("Module:RemiLib")

function p.renderBranchingTable(graph, collapsed)
	
    local uniqueID = remiLib.timeHash(graph)
    local classString = "mw-customtoggle-" .. tostring(uniqueID)
    local idString = "mw-customcollapsible-" .. tostring(uniqueID)
    
    local button = mw.html.create('div')
    button
    	:addClass(classString)
    	:addClass("globalbutton")
    	:wikitext("Show/Hide Branching Rules")

    local body = mw.html.create("table")
    body
        :addClass("mw-collapsible")
        :addClass("wikitable")
        :addClass("mw-collapsed")
        :attr("id",idString)
        :css("width","300px")
        
    local titleRow = mw.html.create("tr")
    local th = mw.html.create("th")
    th
        :attr("colspan",3) -- "from" node, "to" node, requirement text
        :wikitext("Branching Rules")
        :css("font-weight","bold")
        :css("text-align","center")
    titleRow:node(th)
    body:node(titleRow)
    local headerRow = mw.html.create("tr")
    th = mw.html.create("th")
    th
        :wikitext("Node")
        :css("font-size","15px")
        :css("text-align","center")
    headerRow:node(th)
    th = mw.html.create("th")
    th
        :wikitext("Split")
        :css("font-size","15px")
        :css("text-align","center")
    headerRow:node(th)
    th = mw.html.create("th")
    th
        :wikitext("Condition")
        :css("font-size","15px")
        :css("text-align","center")
    headerRow:node(th)
    body:node(headerRow)
    --
    -- graph should be something like
    -- graph = { ["A"] = {
    --                      ["B"] = "This is branching information from node A to node B",
    --                      ["C"] = "And this from A to C",}
    --           ["B"] = {
    --                      ["D"] = "This one from B to D"}
    --         }
    --
    -- toTable is a table of all the to's
    --
    local possibleNodes = remiLib.mergeArrays({"START", "START-1", "START-2", 
    										    "START-3", "START-4", "START-5"}
    										   ,remiLib.uppercase)
    -- 5/5/16
    -- Since multiple start paths are possible (Eg, starting from two different places)
    -- adding the ability to specify multiple start points. Assuming no more than 5 start points ever lol.
    -- Yeah yeah I get that it's bad code design. Shut up, I don't care enough to put more than 5 minutes of thought into this.
    for _,from in pairs(possibleNodes) do
        if graph[from] ~= nil then
            local toTable = graph[from]
            local tableRow = mw.html.create("tr")
            local col = mw.html.create("td")
            local rowHeight = remiLib.getTableSize(toTable)
            col
                :attr("rowspan",rowHeight)
                :wikitext(from)
                :css("text-align","center")
            tableRow:node(col)
            -- isFirstTo checks if we're on the first alphabetically sorted
            -- instance of the "to" node connecting to a "from" node
            local isFirstTo = true
            for _,toNode in pairs(possibleNodes) do
                if toTable[toNode] ~= nil then
                    if not isFirstTo then
                        tableRow = mw.html.create("tr")
                    end
                    col = mw.html.create("td")

                    col
                        :wikitext(toNode)
                        :css("text-align","center")
                    tableRow:node(col)
                    col = mw.html.create("td")
                    col
                        :wikitext(toTable[toNode])
                        :css("text-align","center")
                    tableRow:node(col)
                    body:node(tableRow)
                    isFirstTo = false
                end
            end
        end
    end
    return tostring(button) .. "\n" .. tostring(body)
end 

function p.branchingTemplate(frame)
    -- implementing graph as an adjacency list
    local mapGraph = {}
    local collapsed = true
    if frame.args["collapsed"] ~= nil and string.lower(frame.args["collapsed"]) == "false" then
        collapsed = false
    end

    for param,value in pairs(frame.args) do
        local split = mw.text.split(param,"_")
        -- length is 3, eg A_to_B or B_to_C
        -- second val in split is "to" as above
        -- first and third should be length 1 cuz they should be singular letters
        if #split == 3 and 
           string.lower(split[2]) == "to" and 
           (#split[1] == 1 or (string.find(string.lower(split[1]),"start") ~= nil)) and 
           (#split[3] == 1 or (string.find(string.lower(split[3]),"start") ~= nil))then
            local from = string.upper(split[1])
            local to = string.upper(split[3])
            if (remiLib.valid(from,remiLib.letters) or (string.find(string.lower(split[1]),"start") ~= nil)) and 
               (remiLib.valid(to,remiLib.letters) or (string.find(string.lower(split[3]),"start") ~= nil))then
                if mapGraph[from] == nil then
                    mapGraph[from] = {}
                end
                mapGraph[from][to] = value
            end
        end
    end
    --local html = remiLib.dictConcat(table.getKeys(mapGraph["START-4"]),"|")
    local html = p.renderBranchingTable(mapGraph,collapsed)

    return html

end

return p