Changes

Extensibility
Line 1: Line 1:  +
local BaseData = require('Module:BaseData')
 
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
 
local ShipCardKai = require('Module:ShipCardKai')
 
local ShipCardKai = require('Module:ShipCardKai')
Line 6: Line 7:  
local format = require('Module:StringInterpolation').format
 
local format = require('Module:StringInterpolation').format
   −
local ShipInfoKai = {
+
local ShipInfoKai = BaseData{
 
_catbomb = "Catbomb.png|300px",
 
_catbomb = "Catbomb.png|300px",
 
_unbuildable = "''Unbuildable''",
 
_unbuildable = "''Unbuildable''",
Line 94: Line 95:  
| colspan="5" style="text-align: center; background-color: LightSkyBlue;"|'''Stock Equipment'''
 
| colspan="5" style="text-align: center; background-color: LightSkyBlue;"|'''Stock Equipment'''
 
| style="text-align: center; background-color: LightSkyBlue; width: 50px;" | '''Space'''
 
| style="text-align: center; background-color: LightSkyBlue; width: 50px;" | '''Space'''
${slot_details}
+
${slot_details}|}]],
|}]],
   
}
 
}
   −
function ShipInfoKai:edit_link(ship_data_module)
+
function ShipInfoKai:Infobox(args)
return Formatting:format_edit_link(ship_data_module, self._edit_link_text, self._ship_data_documentation)
+
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
 
end
   −
function ShipInfoKai:bg_color(ship)
+
function ShipInfoKai:bg_color()
local back = ship:back()
+
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 ""
 
return Formatting:format_ship_back(back), Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
 
end
 
end
   −
function ShipInfoKai:rarity(ship)
+
function ShipInfoKai:rarity()
return Formatting:format_ship_rarity(ship:rarity())
+
return Formatting:format_ship_rarity(self._ship:rarity())
 
end
 
end
   −
function ShipInfoKai:name(ship)
+
function ShipInfoKai:name()
return Formatting:format_link(ship:link())
+
return Formatting:format_link(self._ship:link())
 
end
 
end
   −
function ShipInfoKai:localized_name(ship)
+
function ShipInfoKai:localized_name()
local localized_name = ship:localized_name()
+
local localized_name = self._ship:localized_name()
 
if localized_name then
 
if localized_name then
 
return format{self._localized_name_template, localized_name = Formatting:format_stat(localized_name)}
 
return format{self._localized_name_template, localized_name = Formatting:format_stat(localized_name)}
Line 124: Line 130:  
end
 
end
   −
function ShipInfoKai:japanese_name(ship)
+
function ShipInfoKai:japanese_name()
return Formatting:tooltip(Formatting:format_stat(ship:japanese_name()), Formatting:format_stat(ship:reading()))
+
return Formatting:tooltip(Formatting:format_stat(self._ship:japanese_name()), Formatting:format_stat(self._ship:reading()))
 
end
 
end
   −
function ShipInfoKai:nick(ship)
+
function ShipInfoKai:nick()
local nick = ship:nick()
+
local nick = self._ship:nick()
 
if nick then
 
if nick then
local japanese_nick = ship:japanese_nick()
+
local japanese_nick = self._ship:japanese_nick()
local reading_nick = ship:reading_nick()
+
local reading_nick = self._ship:reading_nick()
 
if reading_nick then
 
if reading_nick then
 
japanese_nick = Formatting:tooltip(japanese_nick, reading_nick)
 
japanese_nick = Formatting:tooltip(japanese_nick, reading_nick)
Line 141: Line 147:  
end
 
end
   −
function ShipInfoKai:id(ship)
+
function ShipInfoKai:id()
return Formatting:format_stat_with_max(ship:id(), ship:true_id())
+
return Formatting:format_stat_with_max(self._ship:id(), self._ship:true_id())
 
end
 
end
   −
function ShipInfoKai:class(ship)
+
function ShipInfoKai:class()
local class = ship:class()
+
local class = self._ship:class()
 
return Formatting:format_stat(class and class:name())
 
return Formatting:format_stat(class and class:name())
 
end
 
end
   −
function ShipInfoKai:type(ship)
+
function ShipInfoKai:type()
local class = ship:class()
+
local class = self._ship:class()
local ship_type = Formatting:format_ship_type(ship:type())
+
local ship_type = Formatting:format_ship_type(self._ship:type())
 
if class and class:is_type() then
 
if class and class:is_type() then
 
ship_type = "(" .. ship_type .. ")"
 
ship_type = "(" .. ship_type .. ")"
Line 159: Line 165:  
end
 
end
   −
function ShipInfoKai:image(ship)
+
function ShipInfoKai:image()
return ShipCardKai:card{ship = ship}
+
return ShipCardKai:card{ship = self._ship}
 
end
 
end
   −
function ShipInfoKai:hp(ship)
+
function ShipInfoKai:hp()
local hp = Formatting:format_stat(ship:hp())
+
local hp = Formatting:format_stat(self._ship:hp())
local hp_max = ship:hp_max()
+
local hp_max = self._ship:hp_max()
 
if hp_max then
 
if hp_max then
 
return Formatting:tooltip(hp, format{self._kekkon_max_template, value = Formatting:format_stat(hp_max)})
 
return Formatting:tooltip(hp, format{self._kekkon_max_template, value = Formatting:format_stat(hp_max)})
Line 172: Line 178:  
end
 
end
   −
function ShipInfoKai:firepower(ship)
+
function ShipInfoKai:firepower()
return Formatting:format_stat_with_max(ship:firepower(), ship:firepower_max())
+
return Formatting:format_stat_with_max(self._ship:firepower(), self._ship:firepower_max())
 
end
 
end
   −
function ShipInfoKai:armor(ship)
+
function ShipInfoKai:armor()
return Formatting:format_stat_with_max(ship:armor(), ship:armor_max())
+
return Formatting:format_stat_with_max(self._ship:armor(), self._ship:armor_max())
 
end
 
end
   −
function ShipInfoKai:torpedo(ship)
+
function ShipInfoKai:torpedo()
return Formatting:format_stat_with_max(ship:torpedo(), ship:torpedo_max())
+
return Formatting:format_stat_with_max(self._ship:torpedo(), self._ship:torpedo_max())
 
end
 
end
   −
function ShipInfoKai:evasion(ship, override, override_max)
+
function ShipInfoKai:evasion()
 
local evasion, evasion_max
 
local evasion, evasion_max
 +
local override = self._args.evasion
 +
local override_max = self._args.evasion_max
 
local overridden = false
 
local overridden = false
 
if override and override ~= "auto" then
 
if override and override ~= "auto" then
Line 191: Line 199:  
overridden = true
 
overridden = true
 
else
 
else
evasion = ship:evasion()
+
evasion = self._ship:evasion()
 
end
 
end
 
if override_max and override_max ~= "auto" then
 
if override_max and override_max ~= "auto" then
Line 197: Line 205:  
overridden = true
 
overridden = true
 
else
 
else
evasion_max = ship:evasion_max()
+
evasion_max = self._ship:evasion_max()
 
end
 
end
 
local result = Formatting:format_stat_with_max(evasion, evasion_max)
 
local result = Formatting:format_stat_with_max(evasion, evasion_max)
Line 206: Line 214:  
end
 
end
   −
function ShipInfoKai:aa(ship)
+
function ShipInfoKai:aa()
return Formatting:format_stat_with_max(ship:aa(), ship:aa_max())
+
return Formatting:format_stat_with_max(self._ship:aa(), self._ship:aa_max())
 
end
 
end
   −
function ShipInfoKai:aircraft(ship)
+
function ShipInfoKai:aircraft()
return Formatting:format_stat(ship:total_space())
+
return Formatting:format_stat(self._ship:total_space())
 
end
 
end
   −
function ShipInfoKai:asw(ship, override, override_max)
+
function ShipInfoKai:asw()
 
local asw, asw_max
 
local asw, asw_max
 
local overridden = false
 
local overridden = false
 +
local override = self._args.asw
 +
local override_max = self._args.asw_max
 
if override and override ~= "auto" then
 
if override and override ~= "auto" then
 
asw = override
 
asw = override
 
overridden = true
 
overridden = true
 
else
 
else
asw = ship:asw()
+
asw = self._ship:asw()
 
end
 
end
 
if override_max and override_max ~= "auto" then
 
if override_max and override_max ~= "auto" then
Line 227: Line 237:  
overridden = true
 
overridden = true
 
else
 
else
asw_max = ship:asw_max()
+
asw_max = self._ship:asw_max()
 
end
 
end
 
local result = Formatting:format_stat_with_max(asw, asw_max)
 
local result = Formatting:format_stat_with_max(asw, asw_max)
Line 236: Line 246:  
end
 
end
   −
function ShipInfoKai:speed(ship)
+
function ShipInfoKai:speed()
return Formatting:format_speed(ship:speed())
+
return Formatting:format_speed(self._ship:speed())
 
end
 
end
   −
function ShipInfoKai:los(ship, override, override_max)
+
function ShipInfoKai:los()
 
local los, los_max
 
local los, los_max
 +
local override = self._args.los
 +
local override_max = self._args.los_max
 
local overridden = false
 
local overridden = false
 
if override and override ~= "auto" then
 
if override and override ~= "auto" then
Line 247: Line 259:  
overridden = true
 
overridden = true
 
else
 
else
los = ship:los()
+
los = self._ship:los()
 
end
 
end
 
if override_max and override_max ~= "auto" then
 
if override_max and override_max ~= "auto" then
Line 253: Line 265:  
overridden = true
 
overridden = true
 
else
 
else
los_max = ship:los_max()
+
los_max = self._ship:los_max()
 
end
 
end
 
local result = Formatting:format_stat_with_max(los, los_max)
 
local result = Formatting:format_stat_with_max(los, los_max)
Line 262: Line 274:  
end
 
end
   −
function ShipInfoKai:range(ship)
+
function ShipInfoKai:range()
return Formatting:format_range(ship:range())
+
return Formatting:format_range(self._ship:range())
 
end
 
end
   −
function ShipInfoKai:luck(ship)
+
function ShipInfoKai:luck()
return Formatting:format_stat_with_max(ship:luck(), ship:luck_max())
+
return Formatting:format_stat_with_max(self._ship:luck(), self._ship:luck_max())
 
end
 
end
   −
function ShipInfoKai:build_remodel_header(ship)
+
function ShipInfoKai:build_remodel_header()
return ship:remodel_level() and self._remodel_level or self._build_time
+
return self._ship:remodel_level() and self._remodel_level or self._build_time
 
end
 
end
   −
function ShipInfoKai:build_remodel_info(ship)
+
function ShipInfoKai:build_remodel_info()
local remodel_level = ship:remodel_level()
+
local remodel_level = self._ship:remodel_level()
 
if remodel_level then
 
if remodel_level then
return Formatting:format_remodel_level_and_cost(remodel_level, ship:remodel_cost(), ship:remodel_blueprint())
+
return Formatting:format_remodel_level_and_cost(remodel_level, self._ship:remodel_cost(), self._ship:remodel_blueprint())
 
else
 
else
local buildable = ship:buildable()
+
local buildable = self._ship:buildable()
local buildable_lsc = ship:buildable_lsc()
+
local buildable_lsc = self._ship:buildable_lsc()
 
if buildable or buildable_lsc then
 
if buildable or buildable_lsc then
 
local buildable_methods = {}
 
local buildable_methods = {}
Line 289: Line 301:  
table.insert(buildable_methods, self._large_ship_construction)
 
table.insert(buildable_methods, self._large_ship_construction)
 
end
 
end
return Formatting:format_stat_with_max(Formatting:seconds_to_hms(ship:build_time() * 60), table.concat(buildable_methods, ", "))
+
return Formatting:format_stat_with_max(Formatting:seconds_to_hms(self._ship:build_time() * 60), table.concat(buildable_methods, ", "))
 
else
 
else
local build_time = ship:build_time()
+
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
 
return build_time and Formatting:tooltip(self._unbuildable, Formatting:seconds_to_hms(build_time * 60)) or self._unbuildable
 
end
 
end
Line 297: Line 309:  
end
 
end
   −
function ShipInfoKai:slots(ship)
+
function ShipInfoKai:slots()
return Formatting:format_stat(ship:slots())
+
return Formatting:format_stat(self._ship:slots())
 
end
 
end
   −
function ShipInfoKai:slot_details(ship)
+
function ShipInfoKai:slot_details()
 
local slots = {}
 
local slots = {}
local num_of_slots = ship:slots()
+
local num_of_slots = self._ship:slots()
 
local slots_to_show
 
local slots_to_show
 
if num_of_slots then
 
if num_of_slots then
Line 315: Line 327:  
equipment, size, icon, color, equipment_type = "- Locked -", "-", "", 0, false
 
equipment, size, icon, color, equipment_type = "- Locked -", "-", "", 0, false
 
else
 
else
equipment, size = ship:slot(i)
+
equipment, size = self._ship:slot(i)
 
if equipment then
 
if equipment then
 
icon = equipment:icon()
 
icon = equipment:icon()
Line 340: Line 352:  
end
 
end
   −
function ShipInfoKai:consumption(ship)
+
function ShipInfoKai:consumption()
return Formatting:format_stat(ship:fuel()), Formatting:format_stat(ship:ammo())
+
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
 
end
   −
function ShipInfoKai:modernization(ship)
+
function ShipInfoKai:create_item()
return Formatting:format_modernization_bonuses(ship:modernization())
+
self._ship = Ship(self._args.name, self._args.model)
 
end
 
end
   −
function ShipInfoKai:scrap(ship)
+
function ShipInfoKai:get_module()
return Formatting:format_resources(ship:scrap())
+
self._ship_data_module = Ship:get_module(self._args.name)
 
end
 
end
   −
function ShipInfoKai:Infobox(args)
+
function ShipInfoKai:create_infobox_prep()
local ship = Ship(args.name, args.model)
+
self._icons = {
local ship_data_module = Ship:get_module(args.name)
  −
local collapsible = args.collapsible
  −
local vars = {}
  −
local icons = {
   
hp = StatIcons.hp,
 
hp = StatIcons.hp,
 
firepower = StatIcons.firepower,
 
firepower = StatIcons.firepower,
Line 373: Line 389:  
ammo = ResourceIcons.ammo,
 
ammo = ResourceIcons.ammo,
 
}
 
}
local labels = {}
+
self._labels = {}
for k,v in pairs(icons) do
+
for k,v in pairs(self._icons) do
icons[k] = Formatting:format_image{v}
+
self._icons[k] = Formatting:format_image{v}
labels[k] = Formatting:format_stat_name(k)
+
self._labels[k] = Formatting:format_stat_name(k)
 
end
 
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_class = collapsible and "mw-collapsible mw-collapsed" or ""
 
vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
 
vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
vars.edit_link = self:edit_link(ship_data_module)
+
vars.edit_link = self:edit_link()
vars.rarity = self:rarity(ship)
+
vars.rarity = self:rarity()
vars.icons = icons
+
vars.icons = self._icons
vars.labels = labels
+
vars.labels = self._labels
vars.top_bg_color, vars.top_extra_style = self:bg_color(ship)
+
vars.top_bg_color, vars.top_extra_style = self:bg_color()
vars.name = self:name(ship)
+
vars.name = self:name()
vars.localized_name = self:localized_name(ship)
+
vars.localized_name = self:localized_name()
vars.id = self:id(ship)
+
vars.id = self:id()
vars.japanese_name = self:japanese_name(ship)
+
vars.japanese_name = self:japanese_name()
vars.nick = self:nick(ship)
+
vars.nick = self:nick()
vars.class = self:class(ship)
+
vars.class = self:class()
vars.type = self:type(ship)
+
vars.type = self:type()
vars.image = self:image(ship)
+
vars.image = self:image()
vars.hp = self:hp(ship)
+
vars.hp = self:hp()
vars.firepower = self:firepower(ship)
+
vars.firepower = self:firepower()
vars.armor = self:armor(ship)
+
vars.armor = self:armor()
vars.torpedo = self:torpedo(ship)
+
vars.torpedo = self:torpedo()
vars.evasion = self:evasion(ship, args.evasion, args.evasion_max)
+
vars.evasion = self:evasion()
vars.aa = self:aa(ship)
+
vars.aa = self:aa()
vars.aircraft = self:aircraft(ship)
+
vars.aircraft = self:aircraft()
vars.asw = self:asw(ship, args.asw, args.asw_max)
+
vars.asw = self:asw()
vars.speed = self:speed(ship)
+
vars.speed = self:speed()
vars.los = self:los(ship, args.los, args.los_max)
+
vars.los = self:los()
vars.range = self:range(ship)
+
vars.range = self:range()
vars.luck = self:luck(ship)
+
vars.luck = self:luck()
vars.fuel, vars.ammo = self:consumption(ship)
+
vars.fuel, vars.ammo = self:consumption()
vars.modernization = self:modernization(ship)
+
vars.modernization = self:modernization()
vars.scrap = self:scrap(ship)
+
vars.scrap = self:scrap()
vars.build_remodel_header = self:build_remodel_header(ship)
+
vars.build_remodel_header = self:build_remodel_header()
vars.build_remodel_info = self:build_remodel_info(ship)
+
vars.build_remodel_info = self:build_remodel_info()
vars.slots = self:slots(ship)
+
vars.slots = self:slots()
vars.slot_details = self:slot_details(ship)
+
vars.slot_details = self:slot_details()
 
return format(self._template, vars)
 
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
 
end
    
return ShipInfoKai
 
return ShipInfoKai
Anonymous user