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

Changes

Jump to navigation Jump to search
m
54 revisions imported
Line 2: Line 2:     
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
 +
local ShipBattleCardKai = require('Module:ShipBattleCardKai')
 
local ShipCardKai = require('Module:ShipCardKai')
 
local ShipCardKai = require('Module:ShipCardKai')
 
local Equipment = require('Module:Equipment')
 
local Equipment = require('Module:Equipment')
    
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
local format = require('Module:StringInterpolation').format
+
local format = require('Module:Core').format
    
local Functions = require('Module:NanaminFunctions')
 
local Functions = require('Module:NanaminFunctions')
Line 14: Line 15:  
     _items = {},
 
     _items = {},
 
      
 
      
     _table_start = [[{|]],
+
     _collapse_button_template = [[<div class="mw-customtoggle-${id} wikia-menu-button">Click this button to view the fleet</div>]],
    _table_end = [[|}]],
+
     _collapse_div_start = [[<div id="mw-customcollapsible-${id}" class="mw-collapsible mw-collapsed">]],
    _row_starter = "|-",
+
     _collapse_div_end = [[</div>]],
    _added_cell_template = [[| colspan="6" style="background: ${bg_color}; text-align: center; font-weight: bold;" |${content}]],
  −
     _ship_template = [[| rowspan="4" style="background: ${bg_color};" |${ship_card}]],
  −
     _equip_template = [[| style="background-color: ${icon_bg_color}; width: 15px;" |${equip_icon}
  −
    | style="background-color: ${equip_bg_color}; width: 175px;text-align: center;" |${equip_link}]],
   
      
 
      
     _ship_card_bg = "transparent",
+
     _table_start = [[<table class="nanaminfleetkai">]],
     _equip_icon_bg = "#8DCDEE",
+
    _table_end = [[</table>]],
     _equip_bg = "#E4F3FB",
+
     _row_starter = [[</tr><tr>]],
 +
    _added_cell_template = [[<td colspan="6" style="background-color:${bg_color};">'''${content}'''</td>]],
 +
    _ship_template = [[<td rowspan="4">${ship_card}</td>]],
 +
    _equip_template = [[<td>${equip_icon}</td><td style="${style}">${equip_link}</td>]],
 +
    _blank_entry = [[<td style="display:none;"></td>]],
 +
      
 +
    _header_bg = "#98D2F0",
 
     _equip_locked_bg = "#CDDBE2",
 
     _equip_locked_bg = "#CDDBE2",
 
     _extra_cells_bg = "#98D2F0",
 
     _extra_cells_bg = "#98D2F0",
Line 31: Line 34:  
     _size = "120x165px",
 
     _size = "120x165px",
 
      
 
      
 +
    _id = "",
 
     _elos = 0,
 
     _elos = 0,
 
     _fighter_power = 0,
 
     _fighter_power = 0,
 
     _hq_lvl = 0,
 
     _hq_lvl = 0,
 
}
 
}
  −
function NanaminFleetKai:customize_colors()
  −
    self._ship_card_bg = self._args["ship_card_bg"] or self._ship_card_bg
  −
    self._equip_icon_bg = self._args["equip_icon_bg"] or self._equip_icon_bg
  −
    self._equip_bg = self._args["equip_bg"] or self._equip_bg
  −
    self._equip_locked_bg = self._args["equip_locked_bg"] or self._equip_locked_bg
  −
    self._extra_cells_bg = self._args["extra_cells_bg"] or self._extra_cells_bg
  −
end
      
function NanaminFleetKai:process_hq_level()
 
function NanaminFleetKai:process_hq_level()
Line 52: Line 48:  
         self._hq_lvl = self._hq_lvl + 5
 
         self._hq_lvl = self._hq_lvl + 5
 
     end
 
     end
 +
end
 +
 +
function NanaminFleetKai:generate_id()
 +
    math.randomseed(os.time())
 +
    math.random(); math.random(); math.random()
 +
    self._id = self._args["route"]:gsub("[^%w]", "") .. (self._args["hq"] or "0") .. tostring(math.random(1000000,9999999))
 
end
 
end
    
function NanaminFleetKai:process_los(entry)
 
function NanaminFleetKai:process_los(entry)
     local ship = Ship(entry[1], entry[2])
+
     local ship = Ship(entry[1], entry[2] ~= "/" and entry[2] or "")
 
     local los = ship:los() or 0
 
     local los = ship:los() or 0
 
     local los_max = ship:los_max() or los
 
     local los_max = ship:los_max() or los
 
     if self._args["use_los"] then
 
     if self._args["use_los"] then
         los = tonumber(entry[3])
+
         los = tonumber(entry[3]) or 0
 
     else
 
     else
 
         los = math.floor(los + ((los_max - los) * tonumber(entry[3]) / 99))
 
         los = math.floor(los + ((los_max - los) * tonumber(entry[3]) / 99))
Line 103: Line 105:  
function NanaminFleetKai:insert_ship_row(ship)
 
function NanaminFleetKai:insert_ship_row(ship)
 
     local ship_card
 
     local ship_card
     if ship and ship:name() then
+
     if self._args["text_only"] then
         ship_card = ShipCardKai:card{ship = ship, size = self._size, link = ship:link(), caption = ship:name()}
+
        ship_card = ship and ship:name() or "Invalid Ship Name"
 +
    elseif ship and ship:name() then
 +
         ship_card = ShipCardKai:get{ship = ship, size = self._size, link = ship:link(), caption = ship:name()}
 
     else
 
     else
 
         ship_card = Formatting:format_image{self._blank, size = self._size}
 
         ship_card = Formatting:format_image{self._blank, size = self._size}
 
     end
 
     end
     table.insert(self._rows, format{self._ship_template,
+
     table.insert(self._rows, format{self._ship_template, ship_card = ship_card})
        bg_color = self._ship_card_bg,
  −
        ship_card = ship_card,
  −
    })
   
end
 
end
    
function NanaminFleetKai:insert_equip_row(ship, entry, slot)
 
function NanaminFleetKai:insert_equip_row(ship, entry, slot)
 
     local slots = ship and ship:slots() or 0
 
     local slots = ship and ship:slots() or 0
     local equip_icon, equip_bg_color, equip_link
+
     local equip_icon, equip_link, style
 
     if slot > slots then
 
     if slot > slots then
        equip_icon = ""
  −
        equip_bg_color = self._equip_locked_bg
   
         equip_link = "- Locked -"
 
         equip_link = "- Locked -"
 +
        style = "background-color:" .. self._equip_locked_bg .. ";"
 
     elseif entry[slot + 3] == nil then
 
     elseif entry[slot + 3] == nil then
        equip_icon = ""
  −
        equip_bg_color = self._equip_locked_bg
   
         equip_link = "- Unequipped -"
 
         equip_link = "- Unequipped -"
 +
        style = "background-color:" .. self._equip_locked_bg .. ";"
 
     else
 
     else
         local equip = Equipment(entry[slot + 3])
+
         local equip = Equipment(Functions.process_legacy_name(entry[slot + 3]))
 
         self:process_equipment(equip, select(2, ship:slot(slot)))
 
         self:process_equipment(equip, select(2, ship:slot(slot)))
         equip_icon = Formatting:format_image{ Formatting:format_equipment_icon(equip:icon()), size = "22x22px" }
+
         if self._args["text_only"] then
        equip_bg_color = self._equip_bg
+
            equip_link = Functions.shorten_name("", equip:name())
        equip_link = Formatting:format_link(equip:link())
+
        else
 +
            equip_icon = Formatting:format_image{ Formatting:format_equipment_icon(equip:icon()), size = "22x22px", link = "" }
 +
            equip_link = Formatting:format_link(Functions.shorten_name(equip:link()))
 +
        end
 
     end
 
     end
 
     table.insert(self._rows, format{self._equip_template,
 
     table.insert(self._rows, format{self._equip_template,
        icon_bg_color = self._equip_icon_bg,
+
         equip_icon = equip_icon or "",
         equip_icon = equip_icon,
+
         style = style or "",
         equip_bg_color = equip_bg_color,
   
         equip_link = equip_link,
 
         equip_link = equip_link,
 
     })
 
     })
Line 142: Line 143:  
function NanaminFleetKai:add_header(content)
 
function NanaminFleetKai:add_header(content)
 
     table.insert(self._rows, self._row_starter)
 
     table.insert(self._rows, self._row_starter)
     table.insert(self._rows, format{self._added_cell_template, content = content, bg_color = self._extra_cells_bg })
+
     table.insert(self._rows, format{self._added_cell_template, content = content, bg_color = self._header_bg })
 
     table.insert(self._rows, self._row_starter)
 
     table.insert(self._rows, self._row_starter)
 
end
 
end
    
function NanaminFleetKai:build_table()
 
function NanaminFleetKai:build_table()
     for i = 1, #self._items, 2 do
+
     local i = 1
 +
    while i <= #self._items do
 
         if type(self._items[i]) == "string" then
 
         if type(self._items[i]) == "string" then
 
             self:add_header(self._items[i])
 
             self:add_header(self._items[i])
 
             i = i + 1
 
             i = i + 1
 
         end
 
         end
         local ship1 = Ship(self._items[i][1], self._items[i][2])
+
         local ship1 = Ship(self._items[i][1], self._items[i][2] ~= "/" and self._items[i][2] or "")
 
         self:insert_ship_row(ship1)
 
         self:insert_ship_row(ship1)
 
         self:insert_equip_row(ship1, self._items[i], 1)
 
         self:insert_equip_row(ship1, self._items[i], 1)
 
          
 
          
 
         if type(self._items[i + 1]) == "string" then
 
         if type(self._items[i + 1]) == "string" then
             self:add_header(self._items[i])
+
             --self:add_header(self._items[i])
 
             i = i + 1
 
             i = i + 1
 
         end
 
         end
 
         local ship2
 
         local ship2
 
         if self._items[i + 1] then
 
         if self._items[i + 1] then
 +
            if self._items[i + 1][2] then self._items[i + 1][2] = self._items[i + 1][2]:gsub('/', '') end
 
             ship2 = Ship(self._items[i + 1][1], self._items[i + 1][2])
 
             ship2 = Ship(self._items[i + 1][1], self._items[i + 1][2])
 
             self:insert_ship_row(ship2)
 
             self:insert_ship_row(ship2)
Line 172: Line 175:  
         for j = 2, 4 do
 
         for j = 2, 4 do
 
             table.insert(self._rows, self._row_starter)
 
             table.insert(self._rows, self._row_starter)
 +
            table.insert(self._rows, self._blank_entry)
 
             self:insert_equip_row(ship1, self._items[i], j)
 
             self:insert_equip_row(ship1, self._items[i], j)
 
             if self._items[i + 1] then
 
             if self._items[i + 1] then
 +
                table.insert(self._rows, self._blank_entry)
 
                 self:insert_equip_row(ship2, self._items[i + 1], j)
 
                 self:insert_equip_row(ship2, self._items[i + 1], j)
 
             else
 
             else
 +
                table.insert(self._rows, self._blank_entry)
 
                 self:insert_equip_row(nil, nil, 1)
 
                 self:insert_equip_row(nil, nil, 1)
 
             end
 
             end
 
         end
 
         end
 
         table.insert(self._rows, self._row_starter)
 
         table.insert(self._rows, self._row_starter)
 +
        i = i + 2
 
     end
 
     end
 
end
 
end
Line 190: Line 197:  
function NanaminFleetKai:add_extras()
 
function NanaminFleetKai:add_extras()
 
     local elos = string.format("%.2f", self._elos - (self._hq_lvl * 0.61))
 
     local elos = string.format("%.2f", self._elos - (self._hq_lvl * 0.61))
 +
    if not self._args["hq"] then elos = elos .. " #ERROR:MissingHQ" end
 
     local content = "Effective Line of Sight: " .. elos .. " // Fighter Power: " .. tostring(self._fighter_power)
 
     local content = "Effective Line of Sight: " .. elos .. " // Fighter Power: " .. tostring(self._fighter_power)
 
     self:insert_extra(content)
 
     self:insert_extra(content)
Line 205: Line 213:  
         for i = 1, #drops do
 
         for i = 1, #drops do
 
             local ship = Ship(drops[i], "")
 
             local ship = Ship(drops[i], "")
             local card = ShipCardKai:battle_card{ship = ship, link = ship:link(), caption = ship:name()}
+
             local card = ShipBattleCardKai:get{ship = ship, link = ship:link(), caption = ship:name()}
 +
            if self._args["text_only"] then
 +
                card = ship:name()
 +
                content = content .. "*"
 +
            end
 
             content = content .. card .. " "
 
             content = content .. card .. " "
             if i % 4 == 0 then
+
             if i % 3 == 0 then
 
                 content = mw.ustring.sub(content, 1, -2) .. "<br />"
 
                 content = mw.ustring.sub(content, 1, -2) .. "<br />"
 
             end
 
             end
Line 218: Line 230:  
     self._args = args
 
     self._args = args
 
      
 
      
    self:customize_colors()
   
     self:process_hq_level()
 
     self:process_hq_level()
 
     self:process_args(args)
 
     self:process_args(args)
 +
    self:generate_id()
 +
    table.insert(self._rows, format{self._collapse_button_template, id = self._id})
 +
    table.insert(self._rows, format{self._collapse_div_start, id = self._id})
 
     table.insert(self._rows, self._table_start)
 
     table.insert(self._rows, self._table_start)
 +
    table.insert(self._rows, "<tr>")
 
     self:build_table()
 
     self:build_table()
 
     self:add_extras()
 
     self:add_extras()
 +
    table.insert(self._rows, "</tr>")
 
     table.insert(self._rows, self._table_end)
 
     table.insert(self._rows, self._table_end)
 +
    table.insert(self._rows, self._collapse_div_end)
 
     return table.concat(self._rows, "\n")
 
     return table.concat(self._rows, "\n")
 
end
 
end
Bots, gkautomate
12,557

edits

Navigation menu