- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Difference between revisions of "Module:ShipInfoKai"
Jump to navigation
Jump to search
com>Ckwng |
com>Ckwng (Factor out common css effects) |
||
Line 1: | Line 1: | ||
local Ship = require('Module:Ship') | local Ship = require('Module:Ship') | ||
local StatIcons = require('Module:StatIcons') | local StatIcons = require('Module:StatIcons') | ||
+ | local Effects = require('Module:Effects') | ||
local Formatting = require('Module:Formatting') | local Formatting = require('Module:Formatting') | ||
local format = require('Module:StringInterpolation').format | local format = require('Module:StringInterpolation').format | ||
Line 95: | Line 96: | ||
local extra = "" | local extra = "" | ||
if rarity > 6 then | if rarity > 6 then | ||
− | extra = | + | extra = format{" background-image: ${bloom}${sparkles}", bloom = rarity > 7 and Effects.bloom or "", sparkles = Effects.sparkles} |
end | end | ||
return self._rarity_map[rarity], extra | return self._rarity_map[rarity], extra |
Revision as of 12:15, 16 February 2015
Documentation for this module may be created at Module:ShipInfoKai/doc
local Ship = require('Module:Ship')
local StatIcons = require('Module:StatIcons')
local Effects = require('Module:Effects')
local Formatting = require('Module:Formatting')
local format = require('Module:StringInterpolation').format
local ShipInfoKai = {
_rarity_map = {
[0] = "whitesmoke",
[1] = "cornflowerblue",
[2] = "lightskyblue",
[3] = "mediumturquoise",
[4] = "silver",
[5] = "gold",
[6] = "#eebbee",
[7] = "#eebbee",
[8] = "#eebbee",
},
_equipment_rarity_map = {
[0] = "whitesmoke",
[1] = "lightgrey",
[2] = "lightsteelblue",
[3] = "#eebbee",
[4] = "#eebbee",
[5] = "#eebbee",
},
_catbomb = "Catbomb.png|300px",
_unbuilable = "''Unbuildable''",
_remodel_level = "'''Remodel Level'''",
_build_time = "'''Build Time'''",
_id_1 = "%s",
_id_2 = "%s (%s)",
_stat_1 = "%d",
_stat_2 = "%d (%d)",
_slot_template = [[|- align=center style="background-color: whitesmoke; line-height: 1.1;"
| style="width: 36px; height: 36px; background-color: ${color};" | ${icon}
| colspan="4" style="width: 190px;" | ${equipment}
| style="width: 50px;" | ${slot_size}
]],
_image_template = "[[File:%s]]",
_template = [[{|style="border: 1px solid darkgray; width: 320px;"
|-
|colspan="6" style="text-align: center; background-color: ${top_bg_color};${top_extra_style}"|<p style="font-size:20px">'''${name}'''</p>
<p style="font-size:15px">'''No.${id} ${japanese_name}'''</p>
<p>'''${class} ${type}'''</p>
|-
| align=center colspan="6" | ${image}
|-
| colspan="6" style="text-align: center; background-color: LightSkyBlue;"|'''Statistics'''
|-
| colspan="2" style="width: 88px;" | ${hp_icon} HP
| style="width: 66px;" | '''${hp}'''
| style="width: 88px;" | ${firepower_icon} Firepower
| colspan="2" style="width: 60px;" | '''${firepower}'''
|-
| colspan="2" style="width: 88px;" | ${armor_icon} Armor
| style="width: 66px;" | '''${armor}'''
| style="width: 88px;" | ${torpedo_icon} Torpedo
| colspan="2" style="width: 66px;" | '''${torpedo}'''
|-
| colspan="2" style="width: 88px;" | ${evasion_icon} Evasion
| style="width: 66px;" | '''${evasion}'''
| style="width: 88px;" | ${aa_icon} AA
| colspan="2" style="width: 66px;" | '''${aa}'''
|-
| colspan="2" style="width: 88px;" | ${aircraft_icon} Aircraft
| style="width: 66px;" | '''${aircraft}'''
| style="width: 88px;" | ${asw_icon} ASW
| colspan="2" style="width: 66px;" | '''${asw}'''
|-
| colspan="2" style="width: 88px;" | ${speed_icon} Speed
| style="width: 66px;" | '''${speed}'''
| style="width: 88px;" | ${los_icon} LOS
| colspan="2" style="width: 66px;" | '''${los}'''
|-
| colspan="2" style="width: 88px;" | ${range_icon} Range
| style="width: 66px;" | '''${range}'''
| style="width: 88px;" | ${luck_icon} Luck
| colspan="2" style="width: 66px;" | '''${luck}'''
|-
| colspan="5" style="text-align: center; background-color: LightSkyBlue;"|${build_remodel_header}
| style="text-align: center; background-color: LightSkyBlue; width: 50px;" | '''Slots'''
|-
| 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:bg_color(ship)
local rarity = ship:rarity()
local extra = ""
if rarity > 6 then
extra = format{" background-image: ${bloom}${sparkles}", bloom = rarity > 7 and Effects.bloom or "", sparkles = Effects.sparkles}
end
return self._rarity_map[rarity], extra
end
function ShipInfoKai:name(ship)
return Formatting:format_link(ship:link())
end
function ShipInfoKai:id(ship)
return Formatting:format_stat_with_max(ship:id(), ship:true_id())
end
function ShipInfoKai:class(ship)
return Formatting:format_stat(ship:class():name())
end
function ShipInfoKai:type(ship)
return Formatting:format_ship_type(ship:type())
end
function ShipInfoKai:image(ship)
return Formatting:format_image(ship:card())
end
function ShipInfoKai:hp(ship)
return Formatting:format_stat(ship:hp())
end
function ShipInfoKai:firepower(ship)
return Formatting:format_stat_with_max(ship:firepower(), ship:firepower_max())
end
function ShipInfoKai:armor(ship)
return Formatting:format_stat_with_max(ship:armor(), ship:armor_max())
end
function ShipInfoKai:torpedo(ship)
return Formatting:format_stat_with_max(ship:torpedo(), ship:torpedo_max())
end
function ShipInfoKai:evasion(ship)
return Formatting:format_stat_with_max(ship:evasion(), ship:evasion_max())
end
function ShipInfoKai:aa(ship)
return Formatting:format_stat_with_max(ship:aa(), ship:aa_max())
end
function ShipInfoKai:asw(ship)
return Formatting:format_stat_with_max(ship:asw(), ship:asw_max())
end
function ShipInfoKai:speed(ship)
return Formatting:format_speed(ship:speed())
end
function ShipInfoKai:los(ship)
return Formatting:format_stat_with_max(ship:los(), ship:los_max())
end
function ShipInfoKai:range(ship)
return Formatting:format_range(ship:range())
end
function ShipInfoKai:luck(ship)
return Formatting:format_stat_with_max(ship:luck(), ship:luck_max())
end
function ShipInfoKai:build_remodel_header(ship)
return ship:remodel_level() and self._remodel_level or self._build_time
end
function ShipInfoKai:build_remodel_info(ship)
local remodel_level = ship:remodel_level()
if remodel_level then
return Formatting:format_remodel_level_and_cost(remodel_level, ship:remodel_cost(), ship:remodel_blueprint())
elseif ship:buildable() then
return Formatting:seconds_to_hms(ship:build_time() * 60)
else
return self._unbuildable
end
end
function ShipInfoKai:slots(ship)
return Formatting:format_stat(ship:slots())
end
function ShipInfoKai:slot_details(ship)
local slots = {}
local num_of_slots = ship:slots()
for i = 1, math.max(4, num_of_slots) do
local equipment, size, icon, color
if i > num_of_slots then
equipment, size, icon, color = "- Locked -", "-", "", 0
else
equipment, size = ship:slot(i)
if equipment then
icon = equipment:icon()
color = equipment:back()
equipment = Formatting:format_link(equipment:link())
else
icon = false
color = 0
equipment = "- Unequipped -"
end
icon = Formatting:format_image(Formatting:format_equipment_icon(icon))
end
color = self._equipment_rarity_map[color]
table.insert(slots, format{self._slot_template, icon = icon, equipment = equipment, slot_size = size, color = color})
end
return table.concat(slots)
end
function ShipInfoKai:Infobox(name, model)
local ship = Ship(name, model)
local vars = {
hp_icon = StatIcons.hp,
firepower_icon = StatIcons.firepower,
armor_icon = StatIcons.armor,
torpedo_icon = StatIcons.torpedo,
evasion_icon = StatIcons.evasion,
aa_icon = StatIcons.aa,
aircraft_icon = StatIcons.aircraft,
asw_icon = StatIcons.asw,
speed_icon = StatIcons.speed,
los_icon = StatIcons.los,
range_icon = StatIcons.range,
luck_icon = StatIcons.luck,
}
for k,v in pairs(vars) do
vars[k] = mw.ustring.format(self._image_template, v)
end
local rarity = ship:rarity(true) or 0
vars.top_bg_color, vars.top_extra_style = self:bg_color(ship)
vars.name = self:name(ship)
vars.id = self:id(ship)
vars.japanese_name = ship:japanese_name()
vars.class = self:class(ship)
vars.type = self:type(ship)
vars.image = self:image(ship)
vars.hp = self:hp(ship)
vars.firepower = self:firepower(ship)
vars.armor = self:armor(ship)
vars.torpedo = self:torpedo(ship)
vars.evasion = self:evasion(ship)
vars.aa = self:aa(ship)
vars.aircraft = ship:total_space()
vars.asw = self:asw(ship)
vars.speed = self:speed(ship)
vars.los = self:los(ship)
vars.range = self:range(ship)
vars.luck = self:luck(ship)
vars.build_remodel_header = self:build_remodel_header(ship)
vars.build_remodel_info = self:build_remodel_info(ship)
vars.slots = self:slots(ship)
vars.slot_details = self:slot_details(ship)
return format(self._template, vars)
end
return ShipInfoKai