Module:ShipInfoKai
Revision as of 07:42, 22 April 2015 by com>Ckwng (Extensibility)
Documentation for this module may be created at Module:ShipInfoKai/doc
local BaseData = require('Module:BaseData')
local Ship = require('Module:Ship')
local ShipCardKai = require('Module:ShipCardKai')
local ResourceIcons = require('Module:ResourceIcons')
local StatIcons = require('Module:StatIcons')
local Formatting = require('Module:Formatting')
local format = require('Module:StringInterpolation').format
local ShipInfoKai = BaseData{
_catbomb = "Catbomb.png|300px",
_unbuildable = "''Unbuildable''",
_remodel_level = "'''Remodel Level'''",
_build_time = "'''Build Time'''",
_default_slot_num = 4,
_id_1 = "%s",
_id_2 = "%s (%s)",
_stat_1 = "%d",
_stat_2 = "%d (%d)",
_normal_construction = "Normal",
_large_ship_construction = "LSC",
_ship_data_documentation = "Template:ShipDataDocumentation/EditIntro",
_edit_link_text = "Edit",
_localized_name_template = "<p>''${localized_name}''</p>",
_kekkon_max_template = "Maximum after marriage: ${value}",
_nick_template = " (''${nick} ${japanese_nick}'')",
_overridden_category_template = "[[Category:Pages that override data modules]]",
_slot_template = [[|- align=center style="background-color: whitesmoke; line-height: 1.1;"
| style="width: 36px; height: 36px; background-color: ${color};${extra_style}" | ${icon}
| colspan="4" style="width: 190px;" | ${equipment}
| style="width: 50px;" | ${slot_size}
]],
_image_template = "[[File:%s]]",
_template = [[{|class="${table_class}" id="${table_id}" style="border: 1px solid darkgray; width: 320px;"
|-
|colspan="6" style="position: relative; text-align: center; background-color: ${top_bg_color};${top_extra_style}" title="${rarity}"|<div style="position: absolute; right: 5px;">${edit_link}</div>
<p style="font-size:20px">'''${name}'''</p>${localized_name}
<p style="font-size:15px">'''No.${id} ${japanese_name}${nick}'''</p>
<p>'''${class} ${type}'''</p>
|- style="background-color: whitesmoke;"
| align=center colspan="6" | ${image}
|-
| colspan="6" style="text-align: center; background-color: LightSkyBlue;"|'''Statistics'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.hp} ${labels.hp}
| style="width: 66px;" | '''${hp}'''
| style="width: 88px;" | ${icons.firepower} ${labels.firepower}
| colspan="2" style="width: 60px;" | '''${firepower}'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.armor} ${labels.armor}
| style="width: 66px;" | '''${armor}'''
| style="width: 88px;" | ${icons.torpedo} ${labels.torpedo}
| colspan="2" style="width: 66px;" | '''${torpedo}'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.evasion} ${labels.evasion}
| style="width: 66px;" | '''${evasion}'''
| style="width: 88px;" | ${icons.aa} ${labels.aa}
| colspan="2" style="width: 66px;" | '''${aa}'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.aircraft} ${labels.aircraft}
| style="width: 66px;" | '''${aircraft}'''
| style="width: 88px;" | ${icons.asw} ${labels.asw}
| colspan="2" style="width: 66px;" | '''${asw}'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.speed} ${labels.speed}
| style="width: 66px;" | '''${speed}'''
| style="width: 88px;" | ${icons.los} ${labels.los}
| colspan="2" style="width: 66px;" | '''${los}'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.range} ${labels.range}
| style="width: 66px;" | '''${range}'''
| style="width: 88px;" | ${icons.luck} ${labels.luck}
| colspan="2" style="width: 66px;" | '''${luck}'''
|-
| colspan="6" style="text-align: center; background-color: lightgrey;"|'''Resource Consumption'''
|- style="background-color: whitesmoke;"
| colspan="2" style="width: 88px;" | ${icons.fuel} Fuel
| style="width: 66px;" | '''${fuel}'''
| style="width: 88px;" | ${icons.ammo} Ammo
| colspan="2" style="width: 66px;" | '''${ammo}'''
|-
| colspan="6" style="text-align: center; background-color: lightgrey;"|'''Modernization Bonus'''
|- style="background-color: whitesmoke;"
| colspan="6" style="text-align: center;"| ${modernization}
|-
| colspan="6" style="text-align: center; background-color: lightgrey;"|'''Scrap Value'''
|- style="background-color: whitesmoke;"
| colspan="6" style="text-align: center;"| ${scrap}
|-
| colspan="5" style="text-align: center; background-color: LightSkyBlue;"|${build_remodel_header}
| style="text-align: center; background-color: LightSkyBlue; width: 50px;" | '''Slots'''
|- style="background-color: whitesmoke;"
| colspan="5" style="text-align: center;"|${build_remodel_info}
| align=center style="width: 50px;" |${slots}
|-
| colspan="5" style="text-align: center; background-color: LightSkyBlue;"|'''Stock Equipment'''
| style="text-align: center; background-color: LightSkyBlue; width: 50px;" | '''Space'''
${slot_details}|}]],
}
function ShipInfoKai:Infobox(args)
return self{
_args = args,
}:create_infobox()
end
function ShipInfoKai:edit_link()
return Formatting:format_edit_link(self._ship_data_module, self._edit_link_text, self._ship_data_documentation)
end
function ShipInfoKai:bg_color()
local back = self._ship:back()
return Formatting:format_ship_back(back), Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
end
function ShipInfoKai:rarity()
return Formatting:format_ship_rarity(self._ship:rarity())
end
function ShipInfoKai:name()
return Formatting:format_link(self._ship:link())
end
function ShipInfoKai:localized_name()
local localized_name = self._ship:localized_name()
if localized_name then
return format{self._localized_name_template, localized_name = Formatting:format_stat(localized_name)}
else
return ""
end
end
function ShipInfoKai:japanese_name()
return Formatting:tooltip(Formatting:format_stat(self._ship:japanese_name()), Formatting:format_stat(self._ship:reading()))
end
function ShipInfoKai:nick()
local nick = self._ship:nick()
if nick then
local japanese_nick = self._ship:japanese_nick()
local reading_nick = self._ship:reading_nick()
if reading_nick then
japanese_nick = Formatting:tooltip(japanese_nick, reading_nick)
end
return format{self._nick_template, nick = nick, japanese_nick = japanese_nick}
end
return ""
end
function ShipInfoKai:id()
return Formatting:format_stat_with_max(self._ship:id(), self._ship:true_id())
end
function ShipInfoKai:class()
local class = self._ship:class()
return Formatting:format_stat(class and class:name())
end
function ShipInfoKai:type()
local class = self._ship:class()
local ship_type = Formatting:format_ship_type(self._ship:type())
if class and class:is_type() then
ship_type = "(" .. ship_type .. ")"
end
return ship_type
end
function ShipInfoKai:image()
return ShipCardKai:card{ship = self._ship}
end
function ShipInfoKai:hp()
local hp = Formatting:format_stat(self._ship:hp())
local hp_max = self._ship:hp_max()
if hp_max then
return Formatting:tooltip(hp, format{self._kekkon_max_template, value = Formatting:format_stat(hp_max)})
end
return hp
end
function ShipInfoKai:firepower()
return Formatting:format_stat_with_max(self._ship:firepower(), self._ship:firepower_max())
end
function ShipInfoKai:armor()
return Formatting:format_stat_with_max(self._ship:armor(), self._ship:armor_max())
end
function ShipInfoKai:torpedo()
return Formatting:format_stat_with_max(self._ship:torpedo(), self._ship:torpedo_max())
end
function ShipInfoKai:evasion()
local evasion, evasion_max
local override = self._args.evasion
local override_max = self._args.evasion_max
local overridden = false
if override and override ~= "auto" then
evasion = override
overridden = true
else
evasion = self._ship:evasion()
end
if override_max and override_max ~= "auto" then
evasion_max = override_max
overridden = true
else
evasion_max = self._ship:evasion_max()
end
local result = Formatting:format_stat_with_max(evasion, evasion_max)
if overridden then
result = result .. self._overridden_category_template
end
return result
end
function ShipInfoKai:aa()
return Formatting:format_stat_with_max(self._ship:aa(), self._ship:aa_max())
end
function ShipInfoKai:aircraft()
return Formatting:format_stat(self._ship:total_space())
end
function ShipInfoKai:asw()
local asw, asw_max
local overridden = false
local override = self._args.asw
local override_max = self._args.asw_max
if override and override ~= "auto" then
asw = override
overridden = true
else
asw = self._ship:asw()
end
if override_max and override_max ~= "auto" then
asw_max = override_max
overridden = true
else
asw_max = self._ship:asw_max()
end
local result = Formatting:format_stat_with_max(asw, asw_max)
if overridden then
result = result .. self._overridden_category_template
end
return result
end
function ShipInfoKai:speed()
return Formatting:format_speed(self._ship:speed())
end
function ShipInfoKai:los()
local los, los_max
local override = self._args.los
local override_max = self._args.los_max
local overridden = false
if override and override ~= "auto" then
los = override
overridden = true
else
los = self._ship:los()
end
if override_max and override_max ~= "auto" then
los_max = override_max
overridden = true
else
los_max = self._ship:los_max()
end
local result = Formatting:format_stat_with_max(los, los_max)
if overridden then
result = result .. self._overridden_category_template
end
return result
end
function ShipInfoKai:range()
return Formatting:format_range(self._ship:range())
end
function ShipInfoKai:luck()
return Formatting:format_stat_with_max(self._ship:luck(), self._ship:luck_max())
end
function ShipInfoKai:build_remodel_header()
return self._ship:remodel_level() and self._remodel_level or self._build_time
end
function ShipInfoKai:build_remodel_info()
local remodel_level = self._ship:remodel_level()
if remodel_level then
return Formatting:format_remodel_level_and_cost(remodel_level, self._ship:remodel_cost(), self._ship:remodel_blueprint())
else
local buildable = self._ship:buildable()
local buildable_lsc = self._ship:buildable_lsc()
if buildable or buildable_lsc then
local buildable_methods = {}
if buildable then
table.insert(buildable_methods, self._normal_construction)
end
if buildable_lsc then
table.insert(buildable_methods, self._large_ship_construction)
end
return Formatting:format_stat_with_max(Formatting:seconds_to_hms(self._ship:build_time() * 60), table.concat(buildable_methods, ", "))
else
local build_time = self._ship:build_time()
return build_time and Formatting:tooltip(self._unbuildable, Formatting:seconds_to_hms(build_time * 60)) or self._unbuildable
end
end
end
function ShipInfoKai:slots()
return Formatting:format_stat(self._ship:slots())
end
function ShipInfoKai:slot_details()
local slots = {}
local num_of_slots = self._ship:slots()
local slots_to_show
if num_of_slots then
slots_to_show = math.max(self._default_slot_num, num_of_slots)
else
slots_to_show = self._default_slot_num
end
for i = 1, slots_to_show do
local equipment, size, icon, color, equipment_type
if num_of_slots and i > num_of_slots then
equipment, size, icon, color, equipment_type = "- Locked -", "-", "", 0, false
else
equipment, size = self._ship:slot(i)
if equipment then
icon = equipment:icon()
color = equipment:back()
equipment_type = equipment:type()
equipment = Formatting:format_link(equipment:link())
else
icon = false
color = 0
equipment = equipment == false and "- Unequipped -" or Formatting:format_stat(equipment)
equipment_type = false
end
icon = Formatting:format_image{Formatting:format_equipment_icon(icon), caption = Formatting:format_equipment_type(equipment_type)}
end
table.insert(slots, format{self._slot_template,
icon = icon,
equipment = equipment,
slot_size = Formatting:format_stat(size),
color = "whitesmoke", --Formatting:format_equipment_back(color),
extra_style = "", --Formatting:extra_style_background_image(false, color >= 4)
})
end
return table.concat(slots)
end
function ShipInfoKai:consumption()
return Formatting:format_stat(self._ship:fuel()), Formatting:format_stat(self._ship:ammo())
end
function ShipInfoKai:modernization()
return Formatting:format_modernization_bonuses(self._ship:modernization())
end
function ShipInfoKai:scrap()
return Formatting:format_resources(self._ship:scrap())
end
function ShipInfoKai:create_item()
self._ship = Ship(self._args.name, self._args.model)
end
function ShipInfoKai:get_module()
self._ship_data_module = Ship:get_module(self._args.name)
end
function ShipInfoKai:create_infobox_prep()
self._icons = {
hp = StatIcons.hp,
firepower = StatIcons.firepower,
armor = StatIcons.armor,
torpedo = StatIcons.torpedo,
evasion = StatIcons.evasion,
aa = StatIcons.aa,
aircraft = StatIcons.aircraft,
asw = StatIcons.asw,
speed = StatIcons.speed,
los = StatIcons.los,
range = StatIcons.range,
luck = StatIcons.luck,
fuel = ResourceIcons.fuel,
ammo = ResourceIcons.ammo,
}
self._labels = {}
for k,v in pairs(self._icons) do
self._icons[k] = Formatting:format_image{v}
self._labels[k] = Formatting:format_stat_name(k)
end
end
function ShipInfoKai:format_template()
local vars = {}
local collapsible = self._args.collapsible
vars.table_class = collapsible and "mw-collapsible mw-collapsed" or ""
vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
vars.edit_link = self:edit_link()
vars.rarity = self:rarity()
vars.icons = self._icons
vars.labels = self._labels
vars.top_bg_color, vars.top_extra_style = self:bg_color()
vars.name = self:name()
vars.localized_name = self:localized_name()
vars.id = self:id()
vars.japanese_name = self:japanese_name()
vars.nick = self:nick()
vars.class = self:class()
vars.type = self:type()
vars.image = self:image()
vars.hp = self:hp()
vars.firepower = self:firepower()
vars.armor = self:armor()
vars.torpedo = self:torpedo()
vars.evasion = self:evasion()
vars.aa = self:aa()
vars.aircraft = self:aircraft()
vars.asw = self:asw()
vars.speed = self:speed()
vars.los = self:los()
vars.range = self:range()
vars.luck = self:luck()
vars.fuel, vars.ammo = self:consumption()
vars.modernization = self:modernization()
vars.scrap = self:scrap()
vars.build_remodel_header = self:build_remodel_header()
vars.build_remodel_info = self:build_remodel_info()
vars.slots = self:slots()
vars.slot_details = self:slot_details()
return format(self._template, vars)
end
function ShipInfoKai:create_infobox()
self:create_item()
self:get_module()
self:create_infobox_prep()
return self:format_template()
end
return ShipInfoKai