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

From Kancolle Wiki
Jump to navigation Jump to search
m
m
Line 1: Line 1:
 +
local BaseTable = require('Module:BaseTable')
 
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
 +
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:StringInterpolation').format
  
local NanaminFleet = {
+
local NanaminFleet = BaseTable{
     _template = [[{| class="wikitable"
+
     _item_class = Ship,
     | style="background: lightskyblue;" |Ship
+
    _equip_class = Equipment,
     | style="background: lightskyblue;" |Equipment
+
    _equip_bg = "whitesmoke",
     | style="background: lightskyblue;" |Ship
+
     _header_template = [[! style="background-color: lightskyblue;" |Ship
     | style="background: lightskyblue;" |Equipment
+
     ! style="background-color: lightskyblue;" |Equipment
     |-
+
     ! style="background-color: lightskyblue;" |Ship
     | rowspan="4" style="background: whitesmoke;" |${ship_card1}
+
     ! style="background-color: lightskyblue;" |Equipment]],
    ${ship_equips1}
+
     --[=[
    | rowspan="4" style="background: whitesmoke;" |${ship_card4}
+
     _column_cell_templates = {
    ${ship_equips4}
+
        ship = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
    |-
+
        equips = [[| style="background: whitesmoke;" |${values.equips}]]
    | rowspan="4" style="background: whitesmoke;" |${ship_card2}
+
     },
     ${ship_equips2}
+
     --]=]
     | rowspan="4" style="background: whitesmoke;" |${ship_card5}
+
     _columns = {
     ${ship_equips5}
+
        "ship",
    |-
+
        "equips",
    | rowspan="4" style="background: whitesmoke;" |${ship_card3}
+
        "ship2",
    ${ship_equips3}
+
        "equips2"
    | rowspan="4" style="background: whitesmoke;" |${ship_card6}
+
     },
     ${ship_equips6}
+
     _blank = "blank.png",
    |}]],
+
     _default_size = ShipCardKai._card_size
     _slot_template = [[|-
 
    | style="background: whitesmoke;" |${icon} ${equip}
 
     | style="background: whitesmoke;" |${plane_count}]]
 
 
}
 
}
  
function NanaminFleet:ship_card(ship)
+
function NanaminFleet:create_table_prep()
     if not ship then
+
    self._size = self._args.image_size or self._default_size
         return Formatting:format_image{"Catbomb.png"}
+
end
 +
 
 +
function NanaminFleet:ship(row)
 +
     if ship == false then
 +
         value = Formatting:format_image{self._blank, size = self._size}
 +
    else
 +
        value = ShipCardKai:card{ship = ship, size = self._size, link = ship:link(), caption = ship:name()}
 +
    end
 +
    return {values = {ship_card = value}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 
 +
function NanaminFleet:ship2(row)
 +
    return self:ship(row)
 +
end
 +
 
 +
function NanaminFleet:equips(row)
 +
    value = "|-|Lol|-|Lol2|-|Lol3|-|Lol4"
 +
    return {values = {equips = value}, bg_color = self._equip_bg, text_align = self._center_align}
 +
end
 +
 
 +
function NanaminFleet:equips2(row)
 +
    return self:equips(row)
 +
end
 +
 
 +
function NanaminFleet:start_rows()
 +
    self._rows = {}
 +
end
 +
 
 +
function NanaminFleet:finish_rows()
 +
    return
 +
end
 +
 
 +
function NanaminFleet:process_item_key(item_key)
 +
    local split = mw.ustring.find(item_key, '/')
 +
    if split == nil then
 +
        return item_key
 +
    else
 +
        ship_name = mw.ustring.sub(item_key, 1, split - 1)
 +
        ship_suffix = mw.ustring.sub(item_key, split + 1, -1)
 +
        if ship_suffix == "Regular" then
 +
            ship_suffix = nil
 +
        end
 +
        return ship_name, ship_suffix
 
     end
 
     end
    return Formatting:format_image{ship:card()}
 
 
end
 
end
  
function NanaminFleet:slot_equipment(ship)
+
function NanaminFleet:create_items()
     local slots = {}
+
     local count = 0
     local ship_slot_count = ship.card ~= "function" and 0 or ship:slots()
+
    local row = {}
   
+
     for index, item_key in ipairs(self._args) do
    for i = 1, 4 do
+
        count = count + 1
         local equip, plane_count, icon, equip_type
+
         local item
         if ship.card == "function" or i > ship_slot_count then
+
         if item_key == "-" then
             equip, plane_count, icon, equip_type = "- Locked -", "-", 0, false
+
             item = false
 
         else
 
         else
             equip, plane_count = ship:slot(i)
+
             if mw.ustring.find(item_key, '/') then
            equip = Equipment:create(ship.equip[i].name)
+
                 item = self._item_class(self:process_item_key(item_key))
            if equip then
 
                 icon = equip:icon()
 
                equip_type = false
 
                equip = Formatting:format_link(equip:link())
 
 
             else
 
             else
                 icon = false
+
                 item = self._equip_class(self:process_item_key(item_key))
                equip_type = false
 
                equip = "- Unequipped -"
 
                plane_count = 0
 
 
             end
 
             end
            icon = Formatting:format_image{Formatting:format_equipment_icon(icon), caption = Formatting:format_equipment_type(equip_type)}
 
 
         end
 
         end
         table.insert(slots, format{self._slot_template,
+
         if count % 5 == 0 then
             icon = icon,
+
            table.insert(self._items, row)
            equip = equip,
+
             row = {}
            plane_count = plane_count
+
         end
         })
 
 
     end
 
     end
    return table.concat(slots)
 
 
end
 
end
  
function NanaminFleet:create_table(args)
+
function NanaminFleet:create_data_rows()
     local ships = {}
+
     for _, item in ipairs(self._items) do
    local vars = {}
+
        local row_values = {}
    for i = 1, 6 do
+
        for _, column in ipairs(self._columns) do
        ships[i] = {}
+
            row_values[column] = self[column](self, item)
        ships[i].object = Ship("Haruna", "Kai Ni")
+
            row_values[column].rowspan = item.class ~= nil and 4 or 1
       
+
             row_values[column].colspan = 1
        --Get the equips categorized under each ship specifically so the ship number doesn't have to be passed.
 
        ships[i].equip = {}
 
        for a = 1, 4 do
 
             ships[i].equip[a] = { name = "35.6cm Twin Gun Mount" }
 
 
         end
 
         end
       
 
        vars["ship_card" .. i] = self:ship_card(ships[i].object)
 
        vars["ship_equips" .. i] = self:slot_equipment(ships[i].object)
 
 
     end
 
     end
 
    return format(self._template, vars)
 
 
end
 
end
  
 
return NanaminFleet
 
return NanaminFleet

Revision as of 10:03, 8 April 2015

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

local BaseTable = require('Module:BaseTable')
local Ship = require('Module:Ship')
local ShipCardKai = require('Module:ShipCardKai')
local Equipment = require('Module:Equipment')
local Formatting = require('Module:Formatting')
local format = require('Module:StringInterpolation').format

local NanaminFleet = BaseTable{
    _item_class = Ship,
    _equip_class = Equipment,
    _equip_bg = "whitesmoke",
    _header_template = [[! style="background-color: lightskyblue;" |Ship
    ! style="background-color: lightskyblue;" |Equipment
    ! style="background-color: lightskyblue;" |Ship
    ! style="background-color: lightskyblue;" |Equipment]],
    --[=[
    _column_cell_templates = {
        ship = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
        equips = [[| style="background: whitesmoke;" |${values.equips}]]
    },
    --]=]
    _columns = {
        "ship",
        "equips",
        "ship2",
        "equips2"
    },
    _blank = "blank.png",
    _default_size = ShipCardKai._card_size
}

function NanaminFleet:create_table_prep()
    self._size = self._args.image_size or self._default_size
end

function NanaminFleet:ship(row)
    if ship == false then
        value = Formatting:format_image{self._blank, size = self._size}
    else
        value = ShipCardKai:card{ship = ship, size = self._size, link = ship:link(), caption = ship:name()}
    end
    return {values = {ship_card = value}, bg_color = self._transparent, text_align = self._center_align}
end

function NanaminFleet:ship2(row)
    return self:ship(row)
end

function NanaminFleet:equips(row)
    value = "|-|Lol|-|Lol2|-|Lol3|-|Lol4"
    return {values = {equips = value}, bg_color = self._equip_bg, text_align = self._center_align}
end

function NanaminFleet:equips2(row)
    return self:equips(row)
end

function NanaminFleet:start_rows()
    self._rows = {}
end

function NanaminFleet:finish_rows()
    return
end

function NanaminFleet:process_item_key(item_key)
    local split = mw.ustring.find(item_key, '/')
    if split == nil then
        return item_key
    else
        ship_name = mw.ustring.sub(item_key, 1, split - 1)
        ship_suffix = mw.ustring.sub(item_key, split + 1, -1)
        if ship_suffix == "Regular" then
            ship_suffix = nil
        end
        return ship_name, ship_suffix
    end
end

function NanaminFleet:create_items()
    local count = 0
    local row = {}
    for index, item_key in ipairs(self._args) do
        count = count + 1
        local item
        if item_key == "-" then
            item = false
        else
            if mw.ustring.find(item_key, '/') then
                item = self._item_class(self:process_item_key(item_key))
            else
                item = self._equip_class(self:process_item_key(item_key))
            end
        end
        if count % 5 == 0 then
            table.insert(self._items, row)
            row = {}
        end
    end
end

function NanaminFleet:create_data_rows()
    for _, item in ipairs(self._items) do
        local row_values = {}
        for _, column in ipairs(self._columns) do
            row_values[column] = self[column](self, item)
            row_values[column].rowspan = item.class ~= nil and 4 or 1
            row_values[column].colspan = 1
        end
    end
end

return NanaminFleet