• 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 70: Line 70:
 
end
 
end
  
function NanaminFleet:create_table(frame)
+
function NanaminFleet:create_table()
 +
    local _args = frame.args
 
     local ships = {}
 
     local ships = {}
 
     local vars = {}
 
     local vars = {}
 
     for i = 1, 6 do
 
     for i = 1, 6 do
 
         ships[i] = {}
 
         ships[i] = {}
         ships[i].object = Ship(args["ship" .. tostring(i)], args["ship" .. tostring(i) .. "_remodel"])
+
         ships[i].object = Ship(_args["ship" .. tostring(i)], _args["ship" .. tostring(i) .. "_remodel"])
 
          
 
          
 
         --Get the equips categorized under each ship specifically so the ship number doesn't have to be passed.
 
         --Get the equips categorized under each ship specifically so the ship number doesn't have to be passed.
 
         ships[i].equip = {}
 
         ships[i].equip = {}
 
         for a = 1, 4 do
 
         for a = 1, 4 do
             ships[i].equip[a] = { name = args["ship" .. tostring(i) .. "_equip" .. tostring(a)] }
+
             ships[i].equip[a] = { name = _args["ship" .. tostring(i) .. "_equip" .. tostring(a)] }
 
         end
 
         end
 
          
 
          

Revision as of 11:24, 6 April 2015

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

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

local NanaminFleet = {
    _template = [[{| class="wikitable"
    | style="background: lightskyblue;" |Ship
    | style="background: lightskyblue;" |Equipment
    | style="background: lightskyblue;" |Ship
    | style="background: lightskyblue;" |Equipment
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card1}
    ${ship_equips1}
    | rowspan="4" style="background: whitesmoke;" |${ship_card4}
    ${ship_equips4}
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card2}
    ${ship_equips2}
    | rowspan="4" style="background: whitesmoke;" |${ship_card5}
    ${ship_equips5}
    |-
    | rowspan="4" style="background: whitesmoke;" |${ship_card3}
    ${ship_equips3}
    | rowspan="4" style="background: whitesmoke;" |${ship_card6}
    ${ship_equips6}
    |}]],
    _slot_template = [[|-
    | style="background: whitesmoke;" |${icon} ${equip}
    | style="background: whitesmoke;" |${plane_count}]]
}

function NanaminFleet:ship_card(ship)
    if not ship then
        return Formatting:format_image{"Catbomb.png"}
    end
    return Formatting:format_image{ship:card()}
end

function NanaminFleet:slot_equipment(ship)
    local slots = {}
    local ship_slot_count = ship.card ~= "function" and 0 or ship:slots()
    
    for i = 1, 4 do
        local equip, plane_count, icon, equip_type
        if ship.card == "function" or i > ship_slot_count then
            equip, plane_count, icon, equip_type = "- Locked -", "-", 0, false
        else
            equip, plane_count = ship:slot(i)
            equip = Equipment:create(ship.equip[i].name)
            if equip then
                icon = equip:icon()
                equip_type = false
                equip = Formatting:format_link(equip:link())
            else
                icon = false
                equip_type = false
                equip = "- Unequipped -"
                plane_count = 0
            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:create_table()
    local _args = frame.args
    local ships = {}
    local vars = {}
    for i = 1, 6 do
        ships[i] = {}
        ships[i].object = Ship(_args["ship" .. tostring(i)], _args["ship" .. tostring(i) .. "_remodel"])
        
        --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 = _args["ship" .. tostring(i) .. "_equip" .. tostring(a)] }
        end
        
        vars["ship_card" .. i] = self:ship_card(ships[i].object)
        vars["ship_equips" .. i] = self:slot_equipment(ships[i].object)
    end

    return format(self._template, vars)
end

return NanaminFleet