• 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 14: Line 14:
 
     ! style="background-color: lightskyblue;" |Ship
 
     ! style="background-color: lightskyblue;" |Ship
 
     ! style="background-color: lightskyblue;" |Equipment]],
 
     ! style="background-color: lightskyblue;" |Equipment]],
    --[=[
 
 
     _column_cell_templates = {
 
     _column_cell_templates = {
 
         ship = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
 
         ship = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
         equips = [[| style="background: whitesmoke;" |${values.equips}]]
+
         equips = [[| style="background: whitesmoke;" |${values.equips}]],
 +
        ship2 = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
 +
        equips2 = [[| style="background: whitesmoke;" |${values.equips}]]
 
     },
 
     },
    --]=]
 
    _cell = [[${values.value}]],
 
 
     _columns = {
 
     _columns = {
 
         "ship",
 
         "ship",
Line 42: Line 41:
 
         value = ShipCardKai:card{ship = row[1], size = self._size, link = row[1]:link(), caption = row[1]:name()}
 
         value = ShipCardKai:card{ship = row[1], size = self._size, link = row[1]:link(), caption = row[1]:name()}
 
     end
 
     end
     return {values = {value = value}, bg_color = self._transparent, text_align = self._center_align}
+
     return {values = {ship_card = value}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
Line 52: Line 51:
 
function NanaminFleet:equips(row)
 
function NanaminFleet:equips(row)
 
     local value = "|-|Lol|-|Lol2|-|Lol3|-|Lol4"
 
     local value = "|-|Lol|-|Lol2|-|Lol3|-|Lol4"
     return {values = {value = value}, bg_color = self._equip_bg, text_align = self._center_align}
+
     return {values = {equips = value}, bg_color = self._equip_bg, text_align = self._center_align}
 
end
 
end
  

Revision as of 12:07, 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}]],
        ship2 = [[| rowspan="4" style="background: whitesmoke;" |${values.ship_card}]],
        equips2 = [[| 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)
    local value
    if row[1] == false then
        value = Formatting:format_image{self._blank, size = self._size}
    else
        value = ShipCardKai:card{ship = row[1], size = self._size, link = row[1]:link(), caption = row[1]:name()}
    end
    return {values = {ship_card = value}, bg_color = self._transparent, text_align = self._center_align}
end

function NanaminFleet:ship2(row)
    row = {row[3], row[4]}
    return self:ship(row)
end

function NanaminFleet:equips(row)
    local 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 == 1 or count % 5 == 2 then
            table.insert(row, item)
        end
        if count % 10 == 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