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

From Kancolle Wiki
Jump to navigation Jump to search
Line 76: Line 76:
 
end
 
end
  
return View(render, {"Nagato", "Yamato"})
+
return { returnShipDrop = render } -- View(render, {"Nagato", "Yamato"})

Revision as of 12:41, 1 November 2021

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

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 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}
}

local rarityStyles = {
  [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:#faf;color:#000",
  [7] = "background-color:#f5f;color:#000",
  [8] = "background-color:#a0a;color:#000"
}

local function formatShip(shipName)
  local ship = Ship(shipName)
  local shipDropData = dropData[shipName] or {}
  local result = {
    string.format(
      [=[<tr><td>[[%s]]</td><td style="%s">%s</td><td>[[%s]]</td><td>%s</td>]=],
      shipName,
      rarityStyles[ship:back()] or "",
      Formatting:format_ship_rarity(ship:back()),
      Formatting:format_ship_code(ship:type()),
      U.pad(ship:id() or "???", 3, "0")
    )
  }
  for _, e in ipairs(worlds) do
    for map = 1, e.maps do
      local drop = shipDropData[string.format("%d-%d", e.world, map)]
      table.insert(result, string.format("<td%s>%s</td>", drop and ' style="background-color:#c8e6c9"' or "", drop and Formatting:tooltip2("✓", drop, "; ") or ""))
    end
  end
  local remark =
    ship:buildable() and (ship:buildable_lsc() and "Buildable" or "Buildable (no LSC)") or (ship:buildable_lsc() and "LSC only" or "Unbuildable")
  table.insert(result, string.format("<td>%s</td></tr>", remark))
  return table.concat(result)
end

local function render(args)
  local result = {[[<div style="overflow-x:auto"><table class="wikitable sortable" style="text-align:center;width:100%">]]}
  table.insert(result, "<tr>")
  for _, cell in ipairs({"Ship", "Rarity", "Type", "No."}) do
    table.insert(result, string.format([[<th rowspan="2">%s</th>]], cell))
  end
  for _, e in ipairs(worlds) do
    table.insert(result, string.format([=[<th colspan="%s">[[World %s]]</th>]=], e.maps, e.world))
  end
  table.insert(result, [[<th rowspan="2">Remarks</th>]])
  table.insert(result, "</tr>")
  table.insert(result, "<tr>")
  for _, e in ipairs(worlds) do
    for map = 1, e.maps do
      table.insert(result, string.format([=[<th>[[%s-%s|%s]]</th>]=], e.world, map, map))
    end
  end
  table.insert(result, "</tr>")
  for _, shipName in ipairs(args[1] == "all" and U.sort(U.keys(dropData)) or args) do
    table.insert(result, formatShip(shipName))
  end
  table.insert(result, [[</table></div>]])
  return table.concat(result)
end

return { returnShipDrop = render } -- View(render, {"Nagato", "Yamato"})