Line 1: |
Line 1: |
− | local dropList = require('Module:Data/Drop') | + | local U = require("Module:Core") |
| + | local View = require("Module:View") |
| + | local Ship = require("Module:Ship") |
| + | local Formatting = require("Module:Formatting") |
| + | local dropData = require("Module:Data/ShipDrop") |
| | | |
− | local p = {} | + | local worlds = { |
| + | {world = 1, maps = 6}, |
| + | {world = 2, maps = 5}, |
| + | {world = 3, maps = 5}, |
| + | {world = 4, maps = 5}, |
| + | {world = 5, maps = 5}, |
| + | {world = 6, maps = 5}, |
| + | {world = 7, maps = 3} |
| + | } |
| | | |
− | -- This disgusting module for shipdrops made by | + | local rarityStyles = { |
− | -- Remi_Scarlet | + | [1] = "background-color:#8ac;color:#000", |
− | -- 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. | + | [2] = "background-color:#ace;color:#000", |
− | -- I fucking hate lua. | + | [3] = "background-color:#0ff;color:#000", |
| + | [4] = "background-color:#bbb;color:#000", |
| + | [5] = "background-color:#fc0;color:#000", |
| + | [6] = "background-color:#faf;color:#000", |
| + | [7] = "background-color:#f5f;color:#000", |
| + | [8] = "background-color:#a0a;color:#000" |
| + | } |
| | | |
− | function p.formatShipDropTable(tableInfo) | + | local function formatShip(shipName) |
− | local order = {"1","2","3","4","5","6","7"}
| + | local ship = Ship(shipName) |
− | local worldOrder = {"World1", "World2", "World3", "World4", "World5", "World6","World7"}
| + | local shipDropData = dropData[shipName] or {} |
− | local html = ""
| + | local result = { |
− | html = html .. "<tr><td>[[" .. tableInfo["ShipName"] .. "]]</td>" | + | string.format( |
− | local style = {["1"] = 'background-color:#8ac; color:#000',
| + | [=[<tr><td>[[%s]]</td><td style="%s">%s</td><td>[[%s]]</td><td>%s</td>]=], |
− | ["2"] = 'background-color:#ace; color:#000',
| + | shipName, |
− | ["3"] = 'background-color:#0ff; color:#000',
| + | rarityStyles[ship:back()] or "", |
− | ["4"] = 'background-color:#bbb; color:#000',
| + | Formatting:format_ship_rarity(ship:back()), |
− | ["5"] = 'background-color:#fc0; color:#000',
| + | Formatting:format_ship_code(ship:type()), |
− | ["6"] = 'background-color:#ffaaff; color:#000',
| + | U.pad(ship:id() or "???", 3, "0") |
− | ["7"] = 'background-color:#ff55ff; color:#000',
| + | ) |
− | ["8"] = 'background-color:#aa00aa; color:#000'}
| + | } |
− | local rarity = tableInfo["Rarity"]
| + | for _, e in ipairs(worlds) do |
− | html = html .. "<td style=\"" .. style[rarity] .. ";\">" .. rarity .. "</td>" | + | for map = 1, e.maps do |
− | html = html .. "<td>" .. tableInfo["No."] .. "</td>"
| + | local drop = shipDropData[string.format("%d-%d", e.world, map)] |
− | for i,world in pairs(worldOrder) do
| + | table.insert(result, string.format("<td%s>%s</td>", drop and ' style="background-color:#c8e6c9"' or "", drop and Formatting:tooltip2("✓", drop, "; ") or "")) |
− | 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 | | end |
− | html = html .. "<td style='borders:none;background-color: #dddcb1'></td>" | + | end |
− | html = html .. "<td>" .. tableInfo["Remarks"] .. "</td>"
| + | local remark = |
− | html = html .. "</tr>"
| + | ship:buildable() and (ship:buildable_lsc() and "Buildable" or "Buildable (no LSC)") or (ship:buildable_lsc() and "LSC only" or "Unbuildable") |
− | return html
| + | table.insert(result, string.format("<td>%s</td></tr>", remark)) |
| + | return table.concat(result) |
| end | | end |
| | | |
− | function p.returnShipDrop(frame) | + | local function render(args) |
− | -- Lazy. Will modify later to be more like Infobox module
| + | local result = {[[<div style="overflow-x:auto"><table class="wikitable sortable" style="text-align:center;width:100%">]]} |
− | -- Please don't shoot me. I want to kill myself at how ugly this is, too. dw.
| + | table.insert(result, "<tr>") |
− | local html = ""
| + | for _, cell in ipairs({"Ship", "Rarity", "Type", "No."}) do |
− | html = html .. '<div style="overflow-x: auto;">'
| + | table.insert(result, string.format([[<th rowspan="2">%s</th>]], cell)) |
− | html = html .. '<table class="wikitable sortable" style="text-align: center; width:100%; margin-bottom: 0;">'
| + | end |
− | 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>'
| + | for _, e in ipairs(worlds) do |
− | 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>' | + | table.insert(result, string.format([=[<th colspan="%s">[[World %s]]</th>]=], e.maps, e.world)) |
− | 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>'
| + | end |
− | 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>'
| + | table.insert(result, [[<th rowspan="2">Remarks</th>]]) |
− | html = html .. '<th style="width:2.5%;"> [[3-1 | 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>'
| + | table.insert(result, "</tr>") |
− | 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>'
| + | table.insert(result, "<tr>") |
− | 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>' | + | for _, e in ipairs(worlds) do |
− | 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>'
| + | for map = 1, e.maps do |
− | 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>'
| + | table.insert(result, string.format([=[<th>[[%s-%s|%s]]</th>]=], e.world, map, map)) |
− | if frame.args[1] ~= "all" then
| |
− | for i,shipName in pairs(frame.args) do
| |
− | html = html .. p.formatShipDropTable(dropList[shipName])
| |
− | end
| |
| end | | end |
− | if frame.args[1] == "all" then
| + | end |
− | local ordered_keys = {}
| + | table.insert(result, "</tr>") |
− | for k in pairs(dropList) do
| + | for _, shipName in ipairs(args[1] == "all" and U.sort(U.keys(dropData)) or args) do |
− | table.insert(ordered_keys, k)
| + | table.insert(result, formatShip(shipName)) |
− | end
| + | end |
− | table.sort(ordered_keys)
| + | table.insert(result, [[</table></div>]]) |
− | for i = 1, #ordered_keys do
| + | return table.concat(result) |
− | local shipName = ordered_keys[i]
| |
− | --return shipName
| |
− | html = html .. p.formatShipDropTable(dropList[shipName])
| |
− | end
| |
− | end
| |
− | html = html .. "</table>"
| |
− | html = html .. '</div>'
| |
− | return html
| |
| end | | end |
| | | |
− | return p | + | return View(render, {"Nagato", "Yamato"}) |