Changes

Extensibility 2
Line 25: Line 25:  
_nick_template = " (''${nick} ${japanese_nick}'')",
 
_nick_template = " (''${nick} ${japanese_nick}'')",
 
_overridden_category_template = "[[Category:Pages that override data modules]]",
 
_overridden_category_template = "[[Category:Pages that override data modules]]",
 +
_fields = {
 +
"edit_link",
 +
"rarity",
 +
"bg_color",
 +
"name",
 +
"localized_name",
 +
"id",
 +
"japanese_name",
 +
"nick",
 +
"class",
 +
"type",
 +
"image",
 +
"hp",
 +
"firepower",
 +
"armor",
 +
"torpedo",
 +
"evasion",
 +
"aa",
 +
"aircraft",
 +
"asw",
 +
"speed",
 +
"los",
 +
"range",
 +
"luck",
 +
"consumption",
 +
"modernization",
 +
"scrap",
 +
"build_remodel_header",
 +
"build_remodel_info",
 +
"slots",
 +
"slot_details",
 +
},
 
_slot_template = [[|- align=center style="background-color: whitesmoke; line-height: 1.1;"
 
_slot_template = [[|- align=center style="background-color: whitesmoke; line-height: 1.1;"
 
| style="width: 36px; height: 36px; background-color: ${color};${extra_style}" | ${icon}
 
| style="width: 36px; height: 36px; background-color: ${color};${extra_style}" | ${icon}
Line 105: Line 137:     
function ShipInfoKai:edit_link()
 
function ShipInfoKai:edit_link()
return Formatting:format_edit_link(self._ship_data_module, self._edit_link_text, self._ship_data_documentation)
+
self._vars.edit_link = Formatting:format_edit_link(self._ship_data_module, self._edit_link_text, self._ship_data_documentation)
 
end
 
end
    
function ShipInfoKai:bg_color()
 
function ShipInfoKai:bg_color()
 
local back = self._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 ""
+
self._vars.top_bg_color, self._vars.top_extra_style = Formatting:format_ship_back(back), Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
 
end
 
end
    
function ShipInfoKai:rarity()
 
function ShipInfoKai:rarity()
return Formatting:format_ship_rarity(self._ship:rarity())
+
self._vars.rarity = Formatting:format_ship_rarity(self._ship:rarity())
 
end
 
end
    
function ShipInfoKai:name()
 
function ShipInfoKai:name()
return Formatting:format_link(self._ship:link())
+
self._vars.name = Formatting:format_link(self._ship:link())
 
end
 
end
   Line 124: Line 156:  
local localized_name = self._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)}
+
self._vars.localized_name = format{self._localized_name_template, localized_name = Formatting:format_stat(localized_name)}
 
else
 
else
return ""
+
self._vars.localized_name = ""
 
end
 
end
 
end
 
end
    
function ShipInfoKai:japanese_name()
 
function ShipInfoKai:japanese_name()
return Formatting:tooltip(Formatting:format_stat(self._ship:japanese_name()), Formatting:format_stat(self._ship:reading()))
+
self._vars.japanese_name = Formatting:tooltip(Formatting:format_stat(self._ship:japanese_name()), Formatting:format_stat(self._ship:reading()))
 
end
 
end
   Line 142: Line 174:  
japanese_nick = Formatting:tooltip(japanese_nick, reading_nick)
 
japanese_nick = Formatting:tooltip(japanese_nick, reading_nick)
 
end
 
end
return format{self._nick_template, nick = nick, japanese_nick = japanese_nick}
+
self._vars.nick = format{self._nick_template, nick = nick, japanese_nick = japanese_nick}
 
end
 
end
return ""
+
self._vars.nick = ""
 
end
 
end
    
function ShipInfoKai:id()
 
function ShipInfoKai:id()
return Formatting:format_stat_with_max(self._ship:id(), self._ship:true_id())
+
self._vars.id = Formatting:format_stat_with_max(self._ship:id(), self._ship:true_id())
 
end
 
end
    
function ShipInfoKai:class()
 
function ShipInfoKai:class()
 
local class = self._ship:class()
 
local class = self._ship:class()
return Formatting:format_stat(class and class:name())
+
self._vars.class = Formatting:format_stat(class and class:name())
 
end
 
end
   Line 162: Line 194:  
ship_type = "(" .. ship_type .. ")"
 
ship_type = "(" .. ship_type .. ")"
 
end
 
end
return ship_type
+
self._vars.type = ship_type
 
end
 
end
    
function ShipInfoKai:image()
 
function ShipInfoKai:image()
return ShipCardKai:card{ship = self._ship}
+
self._vars.image = ShipCardKai:card{ship = self._ship}
 
end
 
end
   Line 175: Line 207:  
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)})
 
end
 
end
return hp
+
self._vars.hp = hp
 
end
 
end
    
function ShipInfoKai:firepower()
 
function ShipInfoKai:firepower()
return Formatting:format_stat_with_max(self._ship:firepower(), self._ship:firepower_max())
+
self._vars.firepower = Formatting:format_stat_with_max(self._ship:firepower(), self._ship:firepower_max())
 
end
 
end
    
function ShipInfoKai:armor()
 
function ShipInfoKai:armor()
return Formatting:format_stat_with_max(self._ship:armor(), self._ship:armor_max())
+
self._vars.armor = Formatting:format_stat_with_max(self._ship:armor(), self._ship:armor_max())
 
end
 
end
    
function ShipInfoKai:torpedo()
 
function ShipInfoKai:torpedo()
return Formatting:format_stat_with_max(self._ship:torpedo(), self._ship:torpedo_max())
+
self._vars.torpedo = Formatting:format_stat_with_max(self._ship:torpedo(), self._ship:torpedo_max())
 
end
 
end
   Line 211: Line 243:  
result = result .. self._overridden_category_template
 
result = result .. self._overridden_category_template
 
end
 
end
return result
+
self._vars.evasion = result
 
end
 
end
    
function ShipInfoKai:aa()
 
function ShipInfoKai:aa()
return Formatting:format_stat_with_max(self._ship:aa(), self._ship:aa_max())
+
self._vars.aa = Formatting:format_stat_with_max(self._ship:aa(), self._ship:aa_max())
 
end
 
end
    
function ShipInfoKai:aircraft()
 
function ShipInfoKai:aircraft()
return Formatting:format_stat(self._ship:total_space())
+
self._vars.aircraft = Formatting:format_stat(self._ship:total_space())
 
end
 
end
   Line 243: Line 275:  
result = result .. self._overridden_category_template
 
result = result .. self._overridden_category_template
 
end
 
end
return result
+
self._vars.asw = result
 
end
 
end
    
function ShipInfoKai:speed()
 
function ShipInfoKai:speed()
return Formatting:format_speed(self._ship:speed())
+
self._vars.speed = Formatting:format_speed(self._ship:speed())
 
end
 
end
   Line 271: Line 303:  
result = result .. self._overridden_category_template
 
result = result .. self._overridden_category_template
 
end
 
end
return result
+
self._vars.los = result
 
end
 
end
    
function ShipInfoKai:range()
 
function ShipInfoKai:range()
return Formatting:format_range(self._ship:range())
+
self._vars.range = Formatting:format_range(self._ship:range())
 
end
 
end
    
function ShipInfoKai:luck()
 
function ShipInfoKai:luck()
return Formatting:format_stat_with_max(self._ship:luck(), self._ship:luck_max())
+
self._vars.luck = Formatting:format_stat_with_max(self._ship:luck(), self._ship:luck_max())
 
end
 
end
    
function ShipInfoKai:build_remodel_header()
 
function ShipInfoKai:build_remodel_header()
return self._ship:remodel_level() and self._remodel_level or self._build_time
+
self._vars.build_remodel_header = self._ship:remodel_level() and self._remodel_level or self._build_time
 
end
 
end
   Line 289: Line 321:  
local remodel_level = self._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, self._ship:remodel_cost(), self._ship:remodel_blueprint())
+
self._vars.build_remodel_info =  Formatting:format_remodel_level_and_cost(remodel_level, self._ship:remodel_cost(), self._ship:remodel_blueprint())
 
else
 
else
 
local buildable = self._ship:buildable()
 
local buildable = self._ship:buildable()
Line 301: Line 333:  
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(self._ship:build_time() * 60), table.concat(buildable_methods, ", "))
+
self._vars.build_remodel_info =  Formatting:format_stat_with_max(Formatting:seconds_to_hms(self._ship:build_time() * 60), table.concat(buildable_methods, ", "))
 
else
 
else
 
local build_time = self._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
+
self._vars.build_remodel_info =  build_time and Formatting:tooltip(self._unbuildable, Formatting:seconds_to_hms(build_time * 60)) or self._unbuildable
 
end
 
end
 
end
 
end
Line 310: Line 342:     
function ShipInfoKai:slots()
 
function ShipInfoKai:slots()
return Formatting:format_stat(self._ship:slots())
+
self._vars.slots = Formatting:format_stat(self._ship:slots())
 
end
 
end
   Line 349: Line 381:  
})
 
})
 
end
 
end
return table.concat(slots)
+
self._vars.slot_details = table.concat(slots)
 
end
 
end
    
function ShipInfoKai:consumption()
 
function ShipInfoKai:consumption()
return Formatting:format_stat(self._ship:fuel()), Formatting:format_stat(self._ship:ammo())
+
self._vars.fuel, self._vars.ammo = Formatting:format_stat(self._ship:fuel()), Formatting:format_stat(self._ship:ammo())
 
end
 
end
    
function ShipInfoKai:modernization()
 
function ShipInfoKai:modernization()
return Formatting:format_modernization_bonuses(self._ship:modernization())
+
self._vars.modernization = Formatting:format_modernization_bonuses(self._ship:modernization())
 
end
 
end
    
function ShipInfoKai:scrap()
 
function ShipInfoKai:scrap()
return Formatting:format_resources(self._ship:scrap())
+
self._vars.scrap = Formatting:format_resources(self._ship:scrap())
 
end
 
end
   Line 373: Line 405:     
function ShipInfoKai:create_infobox_prep()
 
function ShipInfoKai:create_infobox_prep()
self._icons = {
+
local icons = {
 
hp = StatIcons.hp,
 
hp = StatIcons.hp,
 
firepower = StatIcons.firepower,
 
firepower = StatIcons.firepower,
Line 389: Line 421:  
ammo = ResourceIcons.ammo,
 
ammo = ResourceIcons.ammo,
 
}
 
}
self._labels = {}
+
local labels = {}
for k,v in pairs(self._icons) do
+
for k,v in pairs(icons) do
self._icons[k] = Formatting:format_image{v}
+
icons[k] = Formatting:format_image{v}
self._labels[k] = Formatting:format_stat_name(k)
+
labels[k] = Formatting:format_stat_name(k)
 
end
 
end
 +
self._vars = {icons = icons, labels = labels}
 +
local collapsible = self._args.collapsible
 +
self._vars.table_class = collapsible and "mw-collapsible mw-collapsed" or ""
 +
self._vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
 
end
 
end
    
function ShipInfoKai:format_template()
 
function ShipInfoKai:format_template()
local vars = {}
+
for _, field in ipairs(self._fields) do
local collapsible = self._args.collapsible
+
self[field](self)
vars.table_class = collapsible and "mw-collapsible mw-collapsed" or ""
+
end
vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
+
return format(self._template, self._vars)
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
 
end
  
Anonymous user