Module:ShipPage

local Utils = require("Module:Utils") local format = require("Module:StringOperations").format local Formatting = require("Module:Formatting") local BaseData = require("Module:BaseData") local Ship = require("Module:Ship")

-- : support passing Ship object in those modules, use Ship object, redo and move ship_remodel_forms function local ShipMetaKai = require("Module:ShipMetaKai") local ShipInfoKai = require("Module:ShipInfoKai") local ShipCategoriesKai = require("Module:ShipCategoriesKai")

function ship_remodel_forms(ship_name) local success, ship_data = Utils.requireModule(ship_name) local forms = { ship_name } if not success then table.insert(forms, string.format("%s/Kai", ship_name)) return forms end local form_data = ship_data[""] local i = 0 while form_data and form_data._remodel_to and not Utils.find(forms, form_data._remodel_to) and i < 10 do       table.insert(forms, form_data._remodel_to) local ship_base_name, ship_suffix = Ship:process_ship_key(form_data._remodel_to) form_data = ship_data[ship_suffix] i = i + 1 end return forms end

local ShipPage = {

_header = "${ship_meta}${clear}${ship_infoboxes}${ship_categories}",

_ship_infobox = [[

${title}
${infobox} ]],

_ship_infobox_titles = { "Basic", "Upgrade", "Second Upgrade", "Third Upgrade (Reversible)" },

}

function ShipPage:format_ship_meta self._vars.ship_meta = ShipMetaKai:Infobox({ self._vars.ship_name }) end

function ShipPage:format_ship_infoboxes local forms = ship_remodel_forms(self._vars.ship_name) local infoboxes = {} for i, form in ipairs(forms) do       table.insert(infoboxes, format{            self._ship_infobox,            title = self._ship_infobox_titles[i],            infobox = ShipInfoKai:Infobox({ form })        }) end self._vars.ship_infoboxes = table.concat(infoboxes, "\n") end

function ShipPage:format_ship_categories self._vars.ship_categories = ShipCategoriesKai:Categories({ self._vars.ship_name }) end

function ShipPage:format_header(ship_name) self._vars = { ship_name = ship_name, clear = Formatting:clear, }   self:format_ship_meta self:format_ship_infoboxes self:format_ship_categories return format(self._header, self._vars) end

function ShipPage.Header(frame, args) args = args or Utils.getTemplateArgs(frame) local ship_name = args.explicit.ship or args.implicit.pagename or "" return ShipPage:format_header(ship_name) end

--[[ ShipPage.t1 = ShipPage.Header(nil, {   explicit = { ship = "Ayanami" },    implicit = {}, }) -- print(p.t1)

ShipPage.t2 = ShipPage.Header(nil, {   explicit = { ship = "Hibiki" },    implicit = {}, }) -- print(p.t2)

ShipPage.t3 = ShipPage.Header(nil, {   explicit = { ship = "Zuikaku" },    implicit = {}, }) -- print(p.t3)

ShipPage.t4 = ShipPage.Header(nil, {   explicit = {},    implicit = {}, }) -- print(p.t4) ]]--

return ShipPage