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

Module:ShipDropTable

From Kancolle Wiki
Revision as of 17:41, 31 October 2021 by Jigaraphale (talk | contribs)
Jump to navigation Jump to search

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

local dropList = require('Module:Data/Drop')

local p = {}

-- This disgusting module for shipdrops made by
-- Remi_Scarlet
-- Please at least give some mention of credit if you want to modify/reuse/whatever. I don't actually care but it'd be nice of you.
-- I fucking hate lua.

function p.formatShipDropTable(tableInfo)
    local order = {"1","2","3","4","5","6","7"}
    local worldOrder = {"World1", "World2", "World3", "World4", "World5", "World6","World7"}
    local html = ""
    html = html .. "<tr><td>[[" .. tableInfo["ShipName"] .. "]]</td>"
    local style = {["1"] = 'background-color:#8ac; color:#000',
                    ["2"] = 'background-color:#ace; color:#000',
                    ["3"] = 'background-color:#0ff; color:#000',
                    ["4"] = 'background-color:#bbb; color:#000',
                    ["5"] = 'background-color:#fc0; color:#000',
                    ["6"] = 'background-color:#ffaaff; color:#000',
                    ["7"] = 'background-color:#ff55ff; color:#000',
                    ["8"] = 'background-color:#aa00aa; color:#000'}
    local rarity = tableInfo["Rarity"]
    html = html .. "<td style=\"" .. style[rarity] .. ";\">" .. rarity .. "</td>"
    html = html .. "<td>" .. tableInfo["No."] .. "</td>"
    for i,world in pairs(worldOrder) do
        html = html .. "<td style='borders:none;background-color: #dddcb1'></td>"
        for ii,map in pairs(order) do
            local val = tableInfo[world][map]
            if val ~= nil then
                html = html .. "<td style=\"" .. val["style"] .. "\">" .. val["drop"] .. "</td>"
            end
        end
    end
    html = html .. "<td style='borders:none;background-color: #dddcb1'></td>"
    html = html .. "<td>" .. tableInfo["Remarks"] .. "</td>"
    html = html .. "</tr>"
    return html
end

function p.returnShipDrop(frame)
    -- Lazy. Will modify later to be more like Infobox module
    -- Please don't shoot me. I want to kill myself at how ugly this is, too. dw.
    local html = ""
    html = html .. '<div style="overflow-x: auto;">'
    html = html .. '<table class="wikitable sortable" style="text-align: center; width:100%; margin-bottom: 0;">'
    html = html .. '<tr><th colspan="1" rowspan="2" style="width:10%;"> Ship Name</th><th colspan="1" rowspan="2" style="width:2%;"> Rarity</th><th colspan="1" rowspan="2" style="width:3%;"> No.</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th>'
    html = html .. '<th colspan="6" rowspan="1" style="width:12.5%;"> [[World 1]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="5" rowspan="1" style="width:12.5%;"> [[World 2]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="5" rowspan="1" style="width:12.5%;"> [[World 3]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="5" rowspan="1" style="width:11%;"> [[World 4]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="5" rowspan="1" style="width:12.5%;"> [[World 5]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="5" rowspan="1" style="width:10%;"> [[World 6]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="3" rowspan="1" style="width:10%;"> [[World 7]]</th><th class="unsortable" colspan="1" rowspan="167" style="background-color: #dddcb1; width:.8%;"></th><th colspan="1" rowspan="2" style="width:14%;"> Remarks</th></tr>'
    html = html .. '<tr><th style="width:2.5%;"> [[1-1 | 1]]</th><th style="width:2.5%;"> [[1-2 | 2]]</th><th style="width:2.5%;"> [[1-3 | 3]]</th><th style="width:2.5%;"> [[1-4 | 4]]</th><th style="width:2.5%;"> [[1-5 | 5]]</th><th style="width:2.5%;"> [[1-6 | 6]]</th>'
    html = html .. '<th style="width:2.5%;"> [[2-1 | 1]]</th><th style="width:2.5%;"> [[2-2 | 2]]</th><th style="width:2.5%;"> [[2-3 | 3]]</th><th style="width:2.5%;"> [[2-4 | 4]]</th><th style="width:2.5%;"> [[2-5 | 5]]</th>'
    html = html .. '<th style="width:2.5%;"> [[3-3 | 1]]</th><th style="width:2.5%;"> [[3-2 | 2]]</th><th style="width:2.5%;"> [[3-3 | 3]]</th><th style="width:2.5%;"> [[3-4 | 4]]</th><th style="width:2.5%;"> [[3-5 | 5]]</th>'
    html = html .. '<th style="width:2.5%;"> [[4-1 | 1]]</th><th style="width:2.5%;"> [[4-2 | 2]]</th><th style="width:2.5%;"> [[4-3 | 3]]</th><th style="width:2.5%;"> [[4-4 | 4]]</th><th style="width:2.5%;"> [[4-5 | 5]]</th>'
    html = html .. '<th style="width:2.5%;"> [[5-1 | 1]]</th><th style="width:2.5%;"> [[5-2| 2]]</th><th style="width:2.5%;"> [[5-3 | 3]]</th><th style="width:2.5%;"> [[5-4 | 4]]</th><th style="width:2.5%;"> [[5-5 | 5]]</th>'
    html = html .. '<th style="width:2.5%;"> [[6-1 | 1]]</th><th style="width:2.5%;"> [[6-2 | 2]]</th><th style="width:2.5%;"> [[6-3 | 3]]</th><th style="width:2.5%;"> [[6-4 | 4]]</th><th style="width:2.5%;"> [[6-5 | 5]]</th>'
    html = html .. '<th style="width:2.5%;"> [[7-1 | 1]]</th><th style="width:2.5%;"> [[7-2 | 2]]</th><th style="width:2.5%;"> [[7-3 | 3]]</th></tr>'
    if frame.args[1] ~= "all" then
        for i,shipName in pairs(frame.args) do
            html = html .. p.formatShipDropTable(dropList[shipName])
        end
    end
    if frame.args[1] == "all" then
        local ordered_keys = {}
        for k in pairs(dropList) do
            table.insert(ordered_keys, k)
        end
        table.sort(ordered_keys)
        for i = 1, #ordered_keys do
            local shipName = ordered_keys[i]
            --return shipName
            html = html .. p.formatShipDropTable(dropList[shipName])
        end
    end
    html = html .. "</table>"
    html = html .. '</div>'
    return html
end

return p