Changes

m
46 revisions imported
Line 3: Line 3:  
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
local format = require('Module:StringInterpolation').format
+
local format = require('Module:Core').format
    
local NanaminShipInfo = {
 
local NanaminShipInfo = {
Line 31: Line 31:  
     local entry = {}
 
     local entry = {}
 
     for _, item in ipairs(args) do
 
     for _, item in ipairs(args) do
         if item == "-" then
+
         if item == "-" and #entry > 2 then
 
             local ship = Ship(entry[1], entry[2])
 
             local ship = Ship(entry[1], entry[2])
 
             local types = {
 
             local types = {
Line 61: Line 61:  
             while mw.ustring.find(item, '/') do
 
             while mw.ustring.find(item, '/') do
 
                 local split = mw.ustring.find(item, '/')
 
                 local split = mw.ustring.find(item, '/')
                 table.insert(entry, mw.ustring.sub(item, 1, split - 1))
+
                 local new_entry = mw.ustring.sub(item, 1, split - 1)
 +
                if new_entry == "-" then new_entry = "" end
 +
                table.insert(entry, new_entry)
 
                 item = mw.ustring.sub(item, split + 1)
 
                 item = mw.ustring.sub(item, split + 1)
 
             end
 
             end
 +
            if item == "-" then item = "" end
 
             table.insert(entry, item)
 
             table.insert(entry, item)
 
         end
 
         end
Line 70: Line 73:     
function NanaminShipInfo:embed_table(entry)
 
function NanaminShipInfo:embed_table(entry)
if entry[3] == "" then
+
if entry[3] == "" then entry[3] = "N/A" end
    entry[3] = "N/A"
+
local name = entry[1]:nick() and entry[1]:nick() or entry[1]:name()
end
   
table.insert(self._rows, self._embedded_start)
 
table.insert(self._rows, self._embedded_start)
 
table.insert(self._rows, format{self._embedded_table,
 
table.insert(self._rows, format{self._embedded_table,
     name = entry[1]:name():gsub(" ", ""),
+
     name = name:gsub(" ", ""),
 
     class = entry[1]:class():name(),
 
     class = entry[1]:class():name(),
 
     extra_levels = entry[3] or "N/A",
 
     extra_levels = entry[3] or "N/A",
Line 83: Line 85:     
function NanaminShipInfo:build_table(class, remove_headers)
 
function NanaminShipInfo:build_table(class, remove_headers)
     if self._sorted_entries[class] ~= nil then
+
     if self._sorted_entries[class] ~= nil or class == "All" then
 
         if not remove_headers then
 
         if not remove_headers then
             table.insert(self._rows, "===" .. class .. "s===")
+
            table.insert(self._rows, [[<div style="text-align: center;">]])
 +
             table.insert(self._rows, "=" .. class .. "s=")
 +
            table.insert(self._rows, [[</div>]])
 
         end
 
         end
 
         table.insert(self._rows, self._table_start)
 
         table.insert(self._rows, self._table_start)
 
          
 
          
         local entries = self._sorted_entries[class]
+
         local entries = {}
 +
        if class == "All" then
 +
            for ship_type, entry_table in pairs(self._sorted_entries) do
 +
                for _, entry in pairs(entry_table) do
 +
                    table.insert(entries, entry)
 +
                end
 +
            end
 +
        else
 +
            entries = self._sorted_entries[class]
 +
        end
 
         table.sort(entries, function(a, b) return a[2] < b[2] end)
 
         table.sort(entries, function(a, b) return a[2] < b[2] end)
 
         local count = 0
 
         local count = 0
Line 95: Line 108:  
             count = count + 1
 
             count = count + 1
 
              
 
              
 +
            local name = entries[a][1]:nick() and entries[a][1]:nick() or entries[a][1]:name()
 +
            local image = string.gsub(entries[a][1]:battle_card(), "FastBB", "BC")
 
             table.insert(self._rows, format{self._ship_card_template,
 
             table.insert(self._rows, format{self._ship_card_template,
                 class = entries[a][1]:name():gsub(" ", ""),
+
                 class = name:gsub(" ", ""),
                 ship_card = Formatting:format_image{entries[a][1]:battle_card(), align = "left", valign = "center"},
+
                 ship_card = Formatting:format_image{image, align = "left", valign = "center"},
 
             })
 
             })
 
             table.insert(self._rows, format{self._level_template,
 
             table.insert(self._rows, format{self._level_template,
Line 120: Line 135:  
function NanaminShipInfo:build_one(class, remove_headers)
 
function NanaminShipInfo:build_one(class, remove_headers)
 
     self:build_table(class, remove_headers)
 
     self:build_table(class, remove_headers)
 +
    return table.concat(self._rows, "\n")
 +
end
 +
 +
function NanaminShipInfo:build_all()
 +
    self:build_table("All", true)
 
     return table.concat(self._rows, "\n")
 
     return table.concat(self._rows, "\n")
 
end
 
end
Line 128: Line 148:  
     table.insert(self._rows, "__NOTOC__")
 
     table.insert(self._rows, "__NOTOC__")
 
     if args["class"] then return self:build_one(args["class"], args["remove_headers"]) end
 
     if args["class"] then return self:build_one(args["class"], args["remove_headers"]) end
 +
    if args["all"] then return self:build_all() end
 
     self:build_table("Battleship")
 
     self:build_table("Battleship")
 
     self:build_table("Carrier")
 
     self:build_table("Carrier")
 
     self:build_table("Heavy Cruiser")
 
     self:build_table("Heavy Cruiser")
 
     self:build_table("Light Cruiser")
 
     self:build_table("Light Cruiser")
 +
    self:build_table("Destroyer")
 
     self:build_table("Submarine")
 
     self:build_table("Submarine")
 +
    self:build_table("Other")
 
     return table.concat(self._rows, "\n")
 
     return table.concat(self._rows, "\n")
 
end
 
end
Bots, gkautomate
13,304

edits