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

Changes

Jump to navigation Jump to search
m
no edit summary
Line 1: Line 1:  +
local getArgs = require('Module:GetArgs')
 +
 
local Ship = require("Module:Ship")
 
local Ship = require("Module:Ship")
 
local Equipment = require("Module:Equipment")
 
local Equipment = require("Module:Equipment")
Line 8: Line 10:  
local CombinedFleet = {
 
local CombinedFleet = {
 
     _rows = {},
 
     _rows = {},
     _ship_list = {},
+
     _ship_list = { ["main"] = {}, ["escort"] = {} },
 
      
 
      
     _table_start = [[{|]],
+
     _table_start = [[{| class="mw-collapsible mw-collapsed" id="mw-customcollapsible-${table_name}-${id}"]],
 
     _table_end = [[|}]],
 
     _table_end = [[|}]],
 
     _row_starter = "|-",
 
     _row_starter = "|-",
Line 22: Line 24:  
     _center_align = "center",
 
     _center_align = "center",
 
      
 
      
     _header_top = [[<div class="mw-customtoggle-${toggle_class}" style="width: 615px; background: #A596B5; border-top-right-radius: 60px; border-top-left-radius: 60px; text-align: center; font-size: 18px; color: #000040;">''Main Fleet''</div>]],
+
     _header_top_template = [[<div class="mw-customtoggle-${toggle_class}" style="width: 615px; background: #A596B5; border-top-right-radius: 60px; border-top-left-radius: 60px; text-align: center; font-size: 18px; color: #000040;">''Main Fleet''</div>]],
     _header_mid = [[<div class="mw-customtoggle-${toggle_class}" style="width: 615px; background: #A596B5; text-align:center; font-size: 18px; color:#000040;">''${text}''</div>]],
+
     _header_mid_template = [[<div class="mw-customtoggle-${toggle_class}" style="width: 615px; background: #A596B5; text-align:center; font-size: 18px; color:#000040;">''${text}''</div>]],
     _header_bot = [[<div style="width: 615px; background: #A596B5; border-bottom-right-radius: 60px; border-bottom-left-radius: 60px; text-align: center; font-size: 18px; color:#000040;">''${map}''</div>]],
+
     _header_bot_template = [[<div style="width: 615px; background: #A596B5; border-bottom-right-radius: 60px; border-bottom-left-radius: 60px; text-align: center; font-size: 18px; color:#000040;">''${map}''</div>]],
 
      
 
      
     _ship_image_template = [[| colspan="2" style="background-color: ${values.bg_color};" |${values.ship_image}]],
+
     _ship_image_template = [[| colspan="2" style="background-color: #BDACA0; height: 50px;" mode="packed" |<div style="float: left; margin-top: 7px; margin-left: 3px;">${position_image}</div>${ship_card}]],
     _equip_icon_template = [[| style="text-align: center; background-color: ${values.bg_color};" |${values.equip_icon}]],
+
     _equip_template = [[| style="height: 46px; text-align: center; background-color: #BDACA0;" |${equip_icon}
    _equip_link_template = [[| style="width: 175px; text-align: center; background: ${values.bg_color};" |${values.equip_link}]],
+
| style="width: 175px; text-align: center; background: #E3D6C9;" |${equip_link}]],
     _info_template = [[<b>${values.label}</b>: ${values.text}<br />]],
+
     _info_template = [[| style="background-color: #363636; height: 25px; width: 611px;" |
 +
    {| style="margin: 5px 62px 0 5px;">
 +
    | style="width: 147px; color: #20B2B5;" | ${label}
 +
    | style="width: 438px; background-color: #F1E7E0; border: 2px solid #D0B118; border-top-left-radius: 10px; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; border-top-right-radius: 10px; vertical-align: center; text-align: center;" | ${value}
 +
    |}]],
 
      
 
      
 
     _id = "",
 
     _id = "",
Line 36: Line 42:  
     _hq_level = 0
 
     _hq_level = 0
 
}
 
}
 +
 +
function CombinedFleet:easy_errors()
 +
    --For people that don't know Lua, some errors may not make sense despite being basic
 +
    --This will provide something for missing variables
 +
    if self._args == nil then error("No information has been provided.") end
 +
   
 +
    local must_have = { "route", "hq_level", "map_name" }
 +
    for _, var_name in ipairs(must_have) do
 +
        if self._args[var_name] == nil then
 +
            error(var_name .. " must be provided. Please double-check that you have this variable and that it is spelled correctly.")
 +
        end
 +
    end
 +
end
 +
 +
function CombinedFleet:generate_id()
 +
    --No built-in hashing algorithms, so we'll just cheat and use the route, HQ level and a random number
 +
    self._id = self._args["route"]:gsub("[^%w]", "") .. self._args["hq_level"] .. tostring(math.random(1000000,9999999))
 +
end
    
function CombinedFleet:organize_args()
 
function CombinedFleet:organize_args()
     local entries = {}
+
     local entry = {}
     for _, entry in ipairs(self._args) do
+
     for _, item in ipairs(self._args) do
         if mw.ustring.sub(entry, 1, 1) == "#" then
+
         if mw.ustring.sub(item, 1, 1) == "#" then
         elseif entry == "-" then
+
         elseif item == "-" then
 +
            if #self._ship_list.main < 6 then
 +
                table.insert(self._ship_list.main, entry)
 +
            else
 +
                table.insert(self._ship_list.escort, entry)
 +
            end
 +
            entry = {}
 
         else
 
         else
 +
            local split = Functions.split(item, '/')
 +
            for _, item in pairs(split) do
 +
                table.insert(entry, item)
 +
            end
 
         end
 
         end
 +
    end
 +
    if #entry > 0 then
 +
        table.insert(self._ship_list.escort, entry)
 
     end
 
     end
 
end
 
end
   −
function CombinedFleet:Fleetbox(args)
+
function CombinedFleet:process_equipment(ship, entry, slot)
 +
    if not ship._equipment then return "", "" end --No idea why this fixes ship:slots() being nil
 +
    local slots = ship and ship:slots() or 0
 +
    local equip_icon, equip_link
 +
    if slot > slots then
 +
        equip_icon = ""
 +
        equip_link = "- Locked -"
 +
    elseif entry[slot + 3] == nil then
 +
        equip_icon = ""
 +
        equip_link = "- Unequipped -"
 +
    else
 +
        local equip = Equipment(entry[slot + 3])
 +
        self._fighter_power = Functions.add_to_fighter_power(self._fighter_power, equip, select(2, ship:slot(slot)))
 +
        self._elos = Functions.add_to_elos(self._elos, equip)
 +
        equip_icon = Formatting:format_image{ Formatting:format_equipment_icon(equip:icon()), size = "22x22px" }
 +
        equip_link = Formatting:format_link(equip:link())
 +
    end
 +
    return equip_icon, equip_link
 +
end
 +
 
 +
function CombinedFleet:insert_top_header()
 +
    table.insert(self._rows, format{self._header_top_template,
 +
        toggle_class = "main-fleet-" .. self._id,
 +
    })
 +
end
 +
 
 +
function CombinedFleet:insert_mid_header(text)
 +
    table.insert(self._rows, format{self._header_mid_template,
 +
        toggle_class = string.lower(text:gsub(" ", "-")) .. "-" .. self._id,
 +
        text = text,
 +
    })
 +
end
 +
 
 +
function CombinedFleet:insert_bot_header()
 +
    table.insert(self._rows, format{self._header_bot_template,
 +
        map = self._args["map_name"],
 +
    })
 +
end
 +
 
 +
function CombinedFleet:build_table(table_name)
 +
    table.insert(self._rows, format{self._table_start,
 +
        table_name = table_name .. "-fleet",
 +
        id = self._id,
 +
    })
 +
   
 +
    local ship_list = self._ship_list[table_name]
 +
    for i = 1, 6, 3 do
 +
        local ships = {
 +
            ship1 = Ship(ship_list[i][1], ship_list[i][2]),
 +
            ship2 = Ship(ship_list[i + 1][1], ship_list[i + 1][2]),
 +
            ship3 = Ship(ship_list[i + 2][1], ship_list[i + 2][2]),
 +
        }
 +
       
 +
        for a = 1, 3 do
 +
            local ship = ships["ship" .. a]
 +
            local ship_card = Formatting:format_image{ship:battle_card(), link = ship:link(), caption = ship:name(), align = "center"}
 +
            table.insert(self._rows, format{self._ship_image_template,
 +
                position_image = Formatting:format_image{"Ship position " .. tostring(i + a - 1) .. " icon.png"},
 +
                ship_card = ship_card,
 +
            })
 +
        end
 +
        table.insert(self._rows, self._row_starter)
 +
        for a = 1, 4 do
 +
            for b = 1, 3 do
 +
                local ship = ships["ship" .. b]
 +
                local equip = ship_list[i + b - 1]
 +
                local equip_icon, equip_link = self:process_equipment(ship, equip, a)
 +
                table.insert(self._rows, format{self._equip_template,
 +
                    equip_icon = equip_icon,
 +
                    equip_link = equip_link,
 +
                })
 +
            end
 +
            table.insert(self._rows, self._row_starter)
 +
        end
 +
       
 +
        if i % 3 == 0 then
 +
        end
 +
    end
 +
   
 +
    table.insert(self._rows, self._table_end)
 +
end
 +
 
 +
function CombinedFleet:build_info_table()
 +
    local information = {
 +
        {
 +
            ["label"] = "Route Taken",
 +
            ["value"] = self._args["route"]
 +
        },
 +
        {
 +
            ["label"] = "Fighter Power",
 +
            ["value"] = tostring(self._fighter_power),
 +
        },
 +
        {
 +
            ["label"] = "Effective Line of Sight",
 +
            ["value"] = string.format("%.2f", self._elos - (Functions.get_hq_bracket(self._args["hq_level"]) * 0.61)),
 +
        },
 +
        {
 +
            ["label"] = "HQ Level",
 +
            ["value"] = tostring(self._args["hq_level"])
 +
        },
 +
        {
 +
            ["label"] = "Teitoku Notes",
 +
            ["value"] = self._args["notes"] or "",
 +
        },
 +
    }
 +
   
 +
    table.insert(self._rows, format{self._table_start,
 +
        table_name = "fleet-info",
 +
        id = self._id,
 +
    })
 +
    for _, set in ipairs(information) do
 +
        table.insert(self._rows, format{self._info_template,
 +
            label = set.label,
 +
            value = set.value,
 +
        })
 +
        table.insert(self._rows, self._row_starter)
 +
    end
 +
    table.insert(self._rows, self._table_end)
 +
end
 +
 
 +
function CombinedFleet:Main(args)
 
     self._args = args
 
     self._args = args
 
      
 
      
 +
    self:easy_errors()
 +
    self:organize_args()
 
     self:generate_id()
 
     self:generate_id()
     self:organize_args()
+
   
 +
     self:insert_top_header()
 +
    self:build_table("main")
 +
    self:insert_mid_header("Escort Fleet")
 +
    self:build_table("escort")
 +
    self:insert_mid_header("Fleet Info")
 +
    self:build_info_table()
 +
    self:insert_bot_header()
 
      
 
      
 
     return table.concat(self._rows, '\n')
 
     return table.concat(self._rows, '\n')
 +
end
 +
 +
function CombinedFleet.Begin(frame)
 +
local args = getArgs{frame = frame:getParent()}
 +
return CombinedFleet:Main(args)
 
end
 
end
    
return CombinedFleet
 
return CombinedFleet
48

edits

Navigation menu