• 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 33: Line 33:
  
 
function NanaminFleet:ship_card(ship)
 
function NanaminFleet:ship_card(ship)
 +
    if not ship then
 +
        return Formatting:format_image{"Catbomb.png"}
 +
    end
 
     return Formatting:format_image{ship:card()}
 
     return Formatting:format_image{ship:card()}
 
end
 
end
Line 38: Line 41:
 
function NanaminFleet:slot_equipment(ship)
 
function NanaminFleet:slot_equipment(ship)
 
     local slots = {}
 
     local slots = {}
     local ship_slot_count = ship:slots()
+
     local ship_slot_count = ship.card ~= "function" and 0 or ship:slots()
 +
   
 
     for i = 1, 4 do
 
     for i = 1, 4 do
 
         local equip, plane_count, icon, equip_type
 
         local equip, plane_count, icon, equip_type
         if i > ship_slot_count then
+
         if ship.card == "function" or i > ship_slot_count then
 
             equip, plane_count, icon, equip_type = "- Locked -", "-", 0, false
 
             equip, plane_count, icon, equip_type = "- Locked -", "-", 0, false
 
         else
 
         else
Line 67: Line 71:
 
end
 
end
  
function NanaminFleet.create_table(args)
+
function NanaminFleet:create_table(args)
 
     local ships = {}
 
     local ships = {}
 
     local vars = {}
 
     local vars = {}
 
     for i = 1, 6 do
 
     for i = 1, 6 do
         ships[i] = Ship(args["ship" .. tostring(i)], args["ship" .. tostring(i) .. "_remodel"])
+
         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.
 
         --Get the equips categorized under each ship specifically so the ship number doesn't have to be passed.
Line 79: Line 84:
 
         end
 
         end
 
          
 
          
         vars["ship_card" .. i] = self:ship_card(ships[i])
+
         vars["ship_card" .. i] = self:ship_card(ships[i].object)
         vars["ship_equips" .. i] = self:slot_equipment(ships[i])
+
         vars["ship_equips" .. i] = self:slot_equipment(ships[i].object)
 
     end
 
     end
  
 
     mw.log(format(self._template, vars))
 
     mw.log(format(self._template, vars))
 
     return format(self._template, vars)
 
     return format(self._template, vars)
 +
end
 +
 +
function test(frame)
 +
    args = {}
 +
    NanaminFleet:create_table(args)
 
end
 
end
  
 
return NanaminFleet
 
return NanaminFleet

Revision as of 11:00, 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(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

    mw.log(format(self._template, vars))
    return format(self._template, vars)
end

function test(frame)
    args = {}
    NanaminFleet:create_table(args)
end

return NanaminFleet