Module:ShipCategoriesKai
Revision as of 22:34, 30 May 2015 by com>Ckwng (better category name for rarity)
Documentation for this module may be created at Module:ShipCategoriesKai/doc
local BaseData = require('Module:BaseData')
local Formatting = require('Module:Formatting')
local Ship = require('Module:Ship')
local format = require('Module:StringInterpolation').format
local ShipCategoriesKai = BaseData{}
function ShipCategoriesKai:Categories(args)
return self{
_args = args
}:create_categories()
end
function ShipCategoriesKai:create_ship()
self._ship = Ship(self._args.ship)
end
function ShipCategoriesKai:create_static_categories()
table.insert(self._categories, "Category:Player ships")
end
function ShipCategoriesKai:create_type_categories()
local ship_type = self._ship:type()
if ship_type then
table.insert(self._categories, format{"Category:${ship_type}s", ship_type = Formatting:format_ship_type(ship_type)})
end
end
function ShipCategoriesKai:create_class_categories()
local ship_class = self._ship:class()
if ship_class then
table.insert(self._categories, format{"Category:${ship_class}", ship_class = ship_class:name()})
end
end
function ShipCategoriesKai:create_rarity_categories()
local rarity = self._ship:rarity()
if rarity then
table.insert(self._categories, format{"Category:${rarity} rarity ships", rarity = Formatting:format_ship_rarity(rarity)})
end
end
function ShipCategoriesKai:create_construction_categories()
local buildable, buildable_lsc = self._ship:buildable(), self._ship:buildable_lsc()
if buildable then
table.insert(self._categories, format{"Category:Ships buildable in Normal Construction"})
end
if buildable_lsc then
table.insert(self._categories, format{"Category:Ships buildable in Large Ship Construction"})
end
end
function ShipCategoriesKai:create_stock_equipment_categories()
local slots = self._ship:slots()
if slots then
for i = 1, slots do
local equipment, size = self._ship:slot(i)
if equipment then
table.insert(self._categories, format{"Category:Ships with ${equipment_name} as stock equipment", equipment_name = equipment:name()})
end
end
end
end
function ShipCategoriesKai:write_categories()
local links = {}
for _, category in ipairs(self._categories) do
table.insert(links, Formatting:format_link(category))
end
return table.concat(links)
end
function ShipCategoriesKai:create_categories()
self._categories = {}
self:create_ship()
self:create_static_categories()
self:create_type_categories()
self:create_class_categories()
self:create_rarity_categories()
self:create_construction_categories()
self:create_stock_equipment_categories()
return self:write_categories()
end
return ShipCategoriesKai