• 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:NodeInfoInvoke"

From Kancolle Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
local Utils = require('Module:Utils')
+
local U = require('Module:Utils')
local format = require('Module:StringInterpolation').format
 
 
local NodeInfo = require('Module:NodeInfo')
 
local NodeInfo = require('Module:NodeInfo')
  
local title_template_simple_event = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center;">${map} ${node}${name}</div>
+
local templates = {
]]
+
    title = [[<div id="${map} ${node}" style="width:700px;text-align:center">${map} ${node}${nameSuffix} ([https://db.kcwiki.moe/drop/map/${world_number}${map_number}/${node}-SAB.html PoiDB])</div>]],
 +
    title_simple = [[<div id="${map} ${node}" style="width:700px;text-align:center">${map} ${node}${nameSuffix}</div>]],
 +
    event_title = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center">${map} ${node}${nameSuffix} ([https://db.kcwiki.moe/drop/map/${world_number}${map_number}/${diff_number}/${node}-SAB.html PoiDB])</div>]],
 +
    event_title_simple = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center">${map} ${node}${nameSuffix}</div>]],
 +
}
  
local title_template_event = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center;">${map} ${node}${name} ([http://db.kcwiki.moe/drop/map/${event_number}${map_number}/${diff_number}/${node}-SAB.html PoiDB])</div>
+
local world_numbers = {
]]
 
 
 
local title_template_simple = [[<div id="${map} ${node}" style="width:700px;text-align:center;">${map} ${node}${name}</div>
 
]]
 
 
 
local title_template = [[<div id="${map} ${node}" style="width:700px;text-align:center;">${map} ${node}${name} ([http://db.kcwiki.moe/drop/map/${world_number}${map_number}/${node}-SAB.html PoiDB])</div>
 
]]
 
 
 
local event_numbers = {
 
 
     ["World 1"] = 1,
 
     ["World 1"] = 1,
 
     ["World 2"] = 2,
 
     ["World 2"] = 2,
Line 33: Line 27:
 
}
 
}
  
local diff_numbers = {
+
local diff_numbers_legacy = {
 
     ["Easy"] = 1,
 
     ["Easy"] = 1,
 
     ["Normal"] = 2,
 
     ["Normal"] = 2,
Line 40: Line 34:
 
}
 
}
  
local diff_numbers2 = {
+
local diff_numbers = {
 
     ["Casual"] = 1,
 
     ["Casual"] = 1,
 
     ["Easy"] = 2,
 
     ["Easy"] = 2,
Line 47: Line 41:
 
}
 
}
  
local node_types = {
+
local simple_node_types = { "Resource", "Storm", "Empty", "Select", "Defense" }
    ["Normal"] = false,
 
    ["Boss"] = false,
 
    ["Resource"] = true,
 
    ["Storm"] = true,
 
    ["Empty"] = true,
 
    ["Select"] = true,
 
    ["Night"] = false,
 
    ["Aerial"] = false,
 
    ["Defense"] = true,
 
    ["Raid"] = false,
 
    ["NightToDay"] = false,
 
}
 
  
 
function formatTitle(pagename, args)
 
function formatTitle(pagename, args)
  
     local event, map = string.match(pagename, "([^/]+)/([^/]+)")
+
     local world, map = string.match(pagename, "([^/]+)/([^/]+)")
     event = event or "?"
+
     world = world or "?"
     map = map or "E-?"
+
     map = map or "?"
  
     local event_number = event_numbers[event] or "?"
+
     local world_number = world_numbers[world] or "?"
   
+
     local map_number = string.match(map:sub(3, 4), "%d") or "?"
     local diffs = (event_number == "?" or event_number >= 41) and diff_numbers2 or diff_numbers
 
  
 
     local node = args[1] or "?"
 
     local node = args[1] or "?"
     local diff = diffs[args.diff] and args.diff
+
     local node_type = args[2] or "?"
     local name = args.name and ": " .. args.name or ""
+
     local is_simple_node_type = node_type == "?" or U.ifind(simple_node_types, node_type)
  
     local map_number = string.match(map:sub(3, 4), "%d") or "?"
+
     local diffs = (world_number == "?" or world_number >= 41) and diff_numbers or diff_numbers_legacy
     local diff_number = diffs[diff]
+
    local diff = diffs[args.diff] and args.diff or "?"
      
+
     local diff_number = diffs[diff] or "?"
     return diff and format{
+
 
         node_types[args[2]] == true and title_template_simple_event or title_template_event,
+
     local nameSuffix = args.name and ": " .. args.name or ""
 +
 
 +
     return U.format{
 +
         is_simple_node_type and
 +
            (diff and templates.event_title_simple or templates.title_simple) or
 +
            (diff and templates.event_title or templates.title),
 
         map = map,
 
         map = map,
 
         node = node,
 
         node = node,
 
         diff = diff,
 
         diff = diff,
         name = name,
+
         nameSuffix = nameSuffix,
         event_number = event_number,
+
         world_number = world_number,
 
         map_number = map_number,
 
         map_number = map_number,
 
         diff_number = diff_number,
 
         diff_number = diff_number,
    } or format{
 
        node_types[args[2]] == true and title_template_simple or title_template,
 
        map = map,
 
        node = node,
 
        name = name,
 
        world_number = event_number,
 
        map_number = map_number,
 
 
     }
 
     }
 
 
end
 
end
  
local NodeInfoInvoke = {}
+
return {
 
+
    Table = function(frame)
function NodeInfoInvoke.Table(frame)
+
        local args = U.getTemplateArgs(frame)
    local args = Utils.getTemplateArgs(frame)
+
        local table_string = NodeInfo:Table(args.explicit)
    local table_string = NodeInfo:Table(args.explicit)
+
        if args.explicit.diff or args.implicit.pagename and args.implicit.pagename:sub(1, 5) == "World" then
    if args.explicit.diff or args.implicit.pagename and args.implicit.pagename:sub(1, 5) == "World" then
+
            return formatTitle(args.implicit.pagename, args.explicit) .. table_string
        return formatTitle(args.implicit.pagename, args.explicit) .. table_string
+
        else
    else
+
            return table_string
        return table_string
+
        end
 
     end
 
     end
end
+
}
 
 
return NodeInfoInvoke
 

Revision as of 01:54, 10 April 2018

Documentation for this module may be created at Module:NodeInfoInvoke/doc

local U = require('Module:Utils')
local NodeInfo = require('Module:NodeInfo')

local templates = {
    title = [[<div id="${map} ${node}" style="width:700px;text-align:center">${map} ${node}${nameSuffix} ([https://db.kcwiki.moe/drop/map/${world_number}${map_number}/${node}-SAB.html PoiDB])</div>]],
    title_simple = [[<div id="${map} ${node}" style="width:700px;text-align:center">${map} ${node}${nameSuffix}</div>]],
    event_title = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center">${map} ${node}${nameSuffix} ([https://db.kcwiki.moe/drop/map/${world_number}${map_number}/${diff_number}/${node}-SAB.html PoiDB])</div>]],
    event_title_simple = [[<div id="${map} ${node} ${diff}" style="width:700px;text-align:center">${map} ${node}${nameSuffix}</div>]],
}

local world_numbers = {
    ["World 1"] = 1,
    ["World 2"] = 2,
    ["World 3"] = 3,
    ["World 4"] = 4,
    ["World 5"] = 5,
    ["World 6"] = 6,
    ["Winter 2016 Event"] = 33,
    ["Spring 2016 Event"] = 34,
    ["Summer 2016 Event"] = 35,
    ["Fall 2016 Event"] = 36,
    ["Winter 2017 Event"] = 37,
    ["Spring 2017 Event"] = 38,
    ["Summer 2017 Event"] = 39,
    ["Fall 2017 Event"] = 40,
    ["Winter 2018 Event"] = 41,
}

local diff_numbers_legacy = {
    ["Easy"] = 1,
    ["Normal"] = 2,
    ["Medium"] = 2,
    ["Hard"] = 3,
}

local diff_numbers = {
    ["Casual"] = 1,
    ["Easy"] = 2,
    ["Medium"] = 3,
    ["Hard"] = 4,
}

local simple_node_types = { "Resource", "Storm", "Empty", "Select", "Defense" }

function formatTitle(pagename, args)

    local world, map = string.match(pagename, "([^/]+)/([^/]+)")
    world = world or "?"
    map = map or "?"

    local world_number = world_numbers[world] or "?"
    local map_number = string.match(map:sub(3, 4), "%d") or "?"

    local node = args[1] or "?"
    local node_type = args[2] or "?"
    local is_simple_node_type = node_type == "?" or U.ifind(simple_node_types, node_type)

    local diffs = (world_number == "?" or world_number >= 41) and diff_numbers or diff_numbers_legacy
    local diff = diffs[args.diff] and args.diff or "?"
    local diff_number = diffs[diff] or "?"

    local nameSuffix = args.name and ": " .. args.name or ""

    return U.format{
        is_simple_node_type and
            (diff and templates.event_title_simple or templates.title_simple) or
            (diff and templates.event_title or templates.title),
        map = map,
        node = node,
        diff = diff,
        nameSuffix = nameSuffix,
        world_number = world_number,
        map_number = map_number,
        diff_number = diff_number,
    }
end

return {
    Table = function(frame)
        local args = U.getTemplateArgs(frame)
        local table_string = NodeInfo:Table(args.explicit)
        if args.explicit.diff or args.implicit.pagename and args.implicit.pagename:sub(1, 5) == "World" then
            return formatTitle(args.implicit.pagename, args.explicit) .. table_string
        else
            return table_string
        end
    end
}