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

From Kancolle Wiki
Jump to navigation Jump to search
com>Kenji135
m
com>Kenji135
Line 69: Line 69:
 
         and F:format_link(link or name, text or name)
 
         and F:format_link(link or name, text or name)
 
         or (icon
 
         or (icon
             and
+
             and F:format_link(link or name, text or name)
            F:format_link(link or name, text or name)
 
 
             or "")
 
             or "")
 +
        or (image
 +
            and ""
 +
            or F:format_link(link or name, text or name))
 
          
 
          
  

Revision as of 11:28, 30 December 2017

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

local getArgs = require("Module:GetArgs")
local U = require("Module:Utils")
local F = require("Module:Formatting")
local Equipment = require("Module:Equipment")
local EquipmentCardKai = require("Module:EquipmentCardKai")

local EquipmentLink = {}

function EquipmentLink.format(frame, args)

    args = args or getArgs{ frame = frame:getParent() }

    local name = args[1] or "??"
    local text = args.text
    local link = args.link
    local image = args.image
    local icon = args.icon

    local cards = {}
    for _, arg in ipairs(args) do
        table.insert(cards, arg == "-" and "<br />" or EquipmentCardKai:Asset({ arg, size = args.size }))
    end

    local formatted_link
        = image
        and EquipmentCardKai:Asset({ name, size = image, link = link or name })
        or F:format_link(link or name, text or name)

    local formatted_icon
        = icon
        -- [[Category:Todo]] again, would be nice to share Equipment object with EquipmentCardKai
        and F:format_image{ F:format_equipment_icon(Equipment(name):icon()) }
        or ""

    local tooltip_content = F:class_div("tooltip-contents", nil, #cards > 0 and table.concat(cards, "") or "??")

    return F:class_span("advanced-tooltip", nil, formatted_icon .. formatted_link .. tooltip_content)

end

function EquipmentLink.test(frame)

    local args = getArgs{ frame = frame:getParent() }
    
    local name = args[1] or "??"
    local text = args.text
    local link = args.link
    local image = args.image
    local icon = args.icon

    local cards = {}
    for _, arg in ipairs(args) do
        table.insert(cards, arg == "-" and "<br />" or EquipmentCardKai:Asset({ arg, size = args.size }))
    end

    local formatted_image
        = image
        and EquipmentCardKai:Asset({ name, size = image, link = link or name })
        or ""

    local formatted_icon
        = icon
        -- [[Category:Todo]] again, would be nice to share Equipment object with EquipmentCardKai
        and F:format_image{ F:format_equipment_icon(Equipment(name):icon()) }
        or ""
        
    local formatted_text
        = text
        and F:format_link(link or name, text or name)
        or (icon
            and F:format_link(link or name, text or name)
            or "")
        or (image
            and ""
            or F:format_link(link or name, text or name))
        

    local tooltip_content = F:class_div("tooltip-contents", nil, #cards > 0 and table.concat(cards, "") or "??")

    return F:class_span("advanced-tooltip", nil, formatted_icon .. formatted_image .. formatted_text .. tooltip_content)

end

--[[
U.registerFormatTests(EquipmentLink, {
    { "Prototype 51cm Twin Gun Mount" },
    { "Type 4 Passive Sonar", link = "Sonar" },
    { "Prototype 51cm Twin Gun Mount", "P51cm" },
    { "Prototype 51cm Twin Gun Mount", image = "50px" },
    { "Prototype 51cm Twin Gun Mount", icon = "x" },
    { },
    { icon = "x" },
})
-- p.run_format_tests()
]]--

return EquipmentLink