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

Module:NanaminFleet

From Kancolle Wiki
Revision as of 03:56, 6 April 2015 by Nanamin (talk | contribs) (Created page with "local BaseTable = require('Module:BaseTable') local Ship = require('Module:Ship') local Equipment = require('Module:Equipment') local Formatting = require('Module:Formatting')...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local BaseTable = require('Module:BaseTable')
local Ship = require('Module:Ship')
local Equipment = require('Module:Equipment')
local Formatting = require('Module:Formatting')

local format = require('Module:StringInterpolation').format

local NanaminFleet = BaseTable{
    _slots_per_ship = 4,
    _template = [[{| class="mw-collapsible mw-collapsed"
    | style="background: lightskyblue;" |Ship
    | style="background: lightskyblue;" |Equipment
    | style="background: lightskyblue;" |Ship
    | style="background: lightskyblue;" |Equipment
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card(1)}
    ${slot_equipment(1)}
    | rowspan="4" style="background: whitesmoke;" |${ship_card(4)}
    ${slot_equipment(4)}
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card(2)}
    ${slot_equipment(2)}
    | rowspan="4" style="background: whitesmoke;" |${ship_card(5)}
    ${slot_equipment(5)}
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card(3)}
    ${slot_equipment(3)}
    | rowspan="4" style="background: whitesmoke;" |${ship_card(6)}
    ${slot_equipment(6)}
    ]],
    _slot_template = [[|-
    | style="background: whitesmoke;" |${icon} ${equip}
    | style="background: whitesmoke;" |${plane_count}
    ]]
}

function NanaminFleet:ship_card(ships, fleet_slot)
    return Formatting:format_image(ships[fleet_slot]:card())
end

function NanaminFleet:slot_equipment(ships, fleet_slot)
    local slots = {}
    local ship_slot_count = ship:slots()
    for i = 1, 4 do
        if i > ship_slot_count then
            equip, plane_count, icon, equip_type = "- Locked -", "-", 0, false
        else
            local equip, plane_count, icon, equip_type
            equip, plane_count = ships[fleet_slot]:slot(i)
            equip = ships[fleet_slot][i].name
            if equip then
                icon = equip:icon()
                equip_type = equip:type()
                equip = Formatting:format_link(equip:link())
            else
                icon = false
                equip_type = false
                equip = "- Unequipped -"
            end
            icon = Formatting:format_image{Formatting:format_equipment_icon(icon), caption = Formatting:format_equipment_type(equip_type)}
        end
        table.insert(slots, format{self._slot_template,
            icon = icon,
            equip = equip,
            plane_count = plane_count
        })
    end
    return table.concat(slots)
end

function NanaminFleet:Infobox(args)
    local ships = {
        --When you have no idea how to do dynamic variable naming...hard-coding.
        ship1 = Ship(args.ships.ship1.name, args.ships.ship1.remodel),
        ship2 = Ship(args.ships.ship2.name, args.ships.ship2.remodel),
        ship3 = Ship(args.ships.ship3.name, args.ships.ship3.remodel),
        ship4 = Ship(args.ships.ship4.name, args.ships.ship4.remodel),
        ship5 = Ship(args.ships.ship5.name, args.ships.ship5.remodel),
        ship6 = Ship(args.ships.ship6.name, args.ships.ship6.remodel)
    }
    return format(self._template)
end

return NanaminFleet