• 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:EquipmentInfoKai"

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
com>Ckwng
Line 218: Line 218:
  
 
function EquipmentInfoKai:effects()
 
function EquipmentInfoKai:effects()
self._vars.effects = Formatting:format_stat_bonuses{
+
    local stats = {
 
firepower = self._equipment:firepower(),  
 
firepower = self._equipment:firepower(),  
 
bombing = self._equipment:bombing(),  
 
bombing = self._equipment:bombing(),  
Line 234: Line 234:
 
special = self._equipment:special(),
 
special = self._equipment:special(),
 
}
 
}
 +
    if self._equipment:type() == 48 then
 +
        self._vars.effects = Formatting:format_stat_bonuses_interceptor(stats)
 +
    else
 +
    self._vars.effects = Formatting:format_stat_bonuses(stats)
 +
    end
 
end
 
end
  

Revision as of 07:06, 7 May 2016

Documentation for this module may be created at Module:EquipmentInfoKai/doc

local BaseData = require('Module:BaseData')
local Equipment = require('Module:Equipment')
local EquipmentCardKai = require('Module:EquipmentCardKai')
local EquipmentGraphicKai = require('Module:EquipmentGraphicKai')
local Formatting = require('Module:Formatting')
local Tabber = require('Module:Tabber')

local format = require('Module:StringInterpolation').format

local EquipmentInfoKai = BaseData{
	_template = [[{|class="${table_class}" id="${table_id}" style="border: 1px solid darkgray; width: 380px; background-color: #fafafa;${float}"
|-
| colspan="2" style="position: relative; padding: 1px 40px; text-align: center; background-color: ${back};${extra_style};" title="${rarity}" | <div style="position: absolute; right: 5px;">${edit_link}</div>
<p style="font-size: 20px;">'''${name}'''</p>${localized_name}
<p>'''No.${id} ${japanese_name}'''</p>
|-
| colspan="2" style="text-align: center; background-color: whitesmoke;" |
<div>${icon} <b>${eq_type}</b><br />
<b>Effects: ${effects}</b>${flight_stats}</div>
<p>'''Scrap value: ${scrap}''' (${buildable})</p>${alternative_names} 
|- 
| colspan="2" style="text-align: center;" | ${card}
|-
| colspan="2" style="text-align: center; background-color: LightSkyBlue;" | '''Refittable Class'''
${compatibility_details}
|}]],
--|-
--| colspan="2" style="text-align: center; padding: 0px;" | <div class="mw-collapsible mw-collapsed">
--<div style="background-color: lightskyblue; text-align: center; margin: 0px;">'''Improvement'''</div>
--<div class="mw-collapsible-content" style="margin-bottom: -2px;">
--${improvement}
--</div>
--</div>
--|}]],
	_row_starter = "|-",
	_compatibility_cell = [[| style="width: 190px; text-align: center; background-color: ${bg_color};" | ${label}]],
	_localized_name_template = "<p>''${localized_name}''</p>",
	_flight_stats_template = [[<br/><b>Combat Radius: ${combat_radius}</b> (Deployment Cost: ${deployment_cost})]],
	_alternative_names_template = [[ 
|-
| colspan="2" style="text-align: center; padding: 0px;" | <div class="mw-collapsible mw-collapsed" style="background-color: lightgrey; margin: 0px;">''Alternate names''<div class="mw-collapsible-content" style="background-color: whitesmoke;">
${names}
</div></div>]],
--	_collapsed_content_header = [[<div style="text-align: center; background-color: lightgrey; margin:2px 0px 2px;">'''${content}'''</div>]],
--	_collapsed_content_row = [[<div style="text-align: center; background-color: whitesmoke; margin:2px 0px 2px;">${content}</div>]],
	_alternative_name_template = [[<div style="display: inline-block; vertical-align: middle;"><small>''${label}:''</small></div> <div style="display: inline-block; vertical-align: middle;"><small>''${name}<br />${japanese_name}''</small></div>]],
	_library_name_label = "Library name",
	_list_name_label = "List name",
	_comparison_name_label = "Comparison name",
	_battle_name_label = "Battle name",
	_equipment_data_documentation = "Template:EquipmentDataDocumentation/EditIntro",
	_edit_link_text = "Edit",
	_empty_card = "Empty equipment card slot.png",
	_buildable = "'''Buildable'''",
	_unbuildable = "''Unbuildable''",
	_float_style_template =  "float: ${float};",
	_shown_ship_types = {
		2, 3,
		21, 4,
		5, 6,
		8, 9,
		10, 7,
		11, 18,
		13, 14,
		20, 16,
		22, 19,
		17, false
	},
	_fields = {
		"edit_link",
		"rarity",
		"back",
		"name",
		"localized_name",
		"flight_stats",
		"alternative_names",
		"id",
		"japanese_name",
		"icon",
		"eq_type",
		"effects",
		"scrap",
		"image",
		"crafting",
		"compatibility_details",
	},
}

function EquipmentInfoKai:Infobox(args)
	return self{
		_args = args,
	}:create_infobox()
end

function EquipmentInfoKai:edit_link()
	self._vars.edit_link = Formatting:format_edit_link(self._equipment_data_module, self._edit_link_text, self._equipment_data_documentation)
end

function EquipmentInfoKai:rarity()
	self._vars.rarity = Formatting:format_equipment_rarity(self._equipment:rarity())
end

function EquipmentInfoKai:back()
	local back = self._equipment:back()
	self._vars.back, self._vars.extra_style = Formatting:format_equipment_back(back), Formatting:extra_style_background_image(false, back and back > 4)
end

function EquipmentInfoKai:name()
	self._vars.name = Formatting:format_link(self._equipment:link())
end

function EquipmentInfoKai:localized_name()
	local localized_name = self._equipment:localized_name()
	if localized_name then
		self._vars.localized_name = format{self._localized_name_template, localized_name = localized_name}
	else
		self._vars.localized_name = ""
	end
end

function EquipmentInfoKai:flight_stats()
    local eq_type = self._equipment:type()
    if eq_type == 6 or eq_type == 7 or eq_type == 8 or eq_type == 9 or eq_type == 11 or eq_type == 10 or eq_type == 41 or eq_type == 45 or eq_type == 47 or eq_type == 48 or eq_type == 94 then
        self._vars.flight_stats = format{self._flight_stats_template, combat_radius = Formatting:format_stat(self._equipment:combat_radius()), deployment_cost = Formatting:format_resources(self._equipment:deployment_cost())}
    else
        self._vars.flight_stats = ""
    end
end

function EquipmentInfoKai:alternative_names()
	local alternative_names = {}
	local list_name = self._equipment:list_name()
	local library_name = self._equipment:library_name()
	local comparison_name = self._equipment:comparison_name()
	local battle_name = self._equipment:battle_name()
	if list_name then
		local list_japanese_name = self._equipment:list_japanese_name()
		local list_reading = self._equipment:list_reading()
		if list_reading ~= false then
			list_japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(list_japanese_name), Formatting:format_stat(list_reading)))
		end
		local list_localized_name = self._equipment:list_localized_name()
		if list_localized_name then
			list_name = Formatting:tooltip(Formatting:format_stat(list_name), Formatting:format_stat(list_localized_name))
		else
			list_name = Formatting:format_stat(list_name)
		end
		table.insert(alternative_names, format{self._alternative_name_template, label = self._list_name_label, name = list_name, japanese_name = list_japanese_name})
	end
	if library_name then
		local library_japanese_name = self._equipment:library_japanese_name()
		local library_reading = self._equipment:library_reading()
		if library_reading ~= false then
			library_japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(library_japanese_name), Formatting:format_stat(library_reading)))
		end
		local library_localized_name = self._equipment:library_localized_name()
		if library_localized_name then
			library_name = Formatting:tooltip(Formatting:format_stat(library_name), Formatting:format_stat(library_localized_name))
		else
			library_name = Formatting:format_stat(library_name)
		end
		table.insert(alternative_names, format{self._alternative_name_template, label = self._library_name_label, name = library_name, japanese_name = library_japanese_name})
	end
	if comparison_name then
		local comparison_japanese_name = self._equipment:comparison_japanese_name()
		local comparison_reading = self._equipment:comparison_reading()
		if comparison_reading ~= false then
			comparison_japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(comparison_japanese_name), Formatting:format_stat(comparison_reading)))
		end
		local comparison_localized_name = self._equipment:comparison_localized_name()
		if comparison_localized_name then
			comparison_name = Formatting:tooltip(Formatting:format_stat(comparison_name), Formatting:format_stat(comparison_localized_name))
		else
			comparison_name = Formatting:format_stat(comparison_name)
		end
		table.insert(alternative_names, format{self._alternative_name_template, label = self._comparison_name_label, name = comparison_name, japanese_name = comparison_japanese_name})
	end
	if battle_name then
		local battle_japanese_name = self._equipment:battle_japanese_name()
		local battle_reading = self._equipment:battle_reading()
		if battle_reading ~= false then
			battle_japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(battle_japanese_name), Formatting:format_stat(battle_reading)))
		end
		local battle_localized_name = self._equipment:battle_localized_name()
		if battle_localized_name then
			battle_name = Formatting:tooltip(Formatting:format_stat(battle_name), Formatting:format_stat(battle_localized_name))
		else
			battle_name = Formatting:format_stat(battle_name)
		end
		table.insert(alternative_names, format{self._alternative_name_template, label = self._battle_name_label, name = battle_name, japanese_name = battle_japanese_name})
	end
	if #alternative_names == 0 then
		self._vars.alternative_names = ""
	else
		self._vars.alternative_names = format{self._alternative_names_template, names = table.concat(alternative_names, "<br/>")}
	end
end

function EquipmentInfoKai:id()
	self._vars.id = Formatting:format_stat(self._equipment:id())
end

function EquipmentInfoKai:japanese_name()
	self._vars.japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(self._equipment:japanese_name()), Formatting:format_stat(self._equipment:reading())))
end

function EquipmentInfoKai:icon()
	self._vars.icon = Formatting:format_image{Formatting:format_equipment_icon(self._equipment:icon())}
end

function EquipmentInfoKai:eq_type()
	self._vars.eq_type = Formatting:format_equipment_type(self._equipment:type())
	local album_type = self._equipment:album_type()
	if album_type then
		self._vars.eq_type = Formatting:tooltip(self._vars.eq_type, album_type)
	end
end

function EquipmentInfoKai:effects()
    local stats = {
		firepower = self._equipment:firepower(), 
		bombing = self._equipment:bombing(), 
		torpedo = self._equipment:torpedo(), 
		aa = self._equipment:aa(), 
		armor = self._equipment:armor(), 
		asw = self._equipment:asw(), 
		shelling_accuracy = self._equipment:shelling_accuracy(),
		torpedo_accuracy = self._equipment:torpedo_accuracy(),
		evasion = self._equipment:evasion(),
		los = self._equipment:los(),
		speed = Formatting:format_speed(self._equipment:speed()),
		luck = self._equipment:luck(),
		range = Formatting:format_range(self._equipment:range()),
		special = self._equipment:special(),
	}
    if self._equipment:type() == 48 then
        self._vars.effects = Formatting:format_stat_bonuses_interceptor(stats)
    else
    	self._vars.effects = Formatting:format_stat_bonuses(stats)
    end
end

function EquipmentInfoKai:scrap()
	self._vars.scrap = Formatting:format_resources(self._equipment:scrap())
end

function EquipmentInfoKai:image()
	local tabber = Tabber()
	local caption = nil
	local card_name = self._equipment:card_name()
	if card_name then
		local card_caption = {}
		local card_local = self._equipment:card_localized_name()
		if card_local then
			table.insert(card_caption, Formatting:format_stat_with_max(card_name, card_local))
		else
			table.insert(card_caption, card_name)
		end
		table.insert(card_caption, "/")
		table.insert(card_caption, Formatting:format_stat_with_max(self._equipment:card_japanese_name(), self._equipment:card_reading()))

		caption = table.concat(card_caption)
	end
	tabber:add_tab("Card", EquipmentCardKai:get{equip = self._equipment, caption = caption})
	tabber:add_tab("Fairy", EquipmentGraphicKai:get{equip = self._equipment, fairy = "only"})
	tabber:add_tab("Equipment", EquipmentGraphicKai:get{equip = self._equipment})
	tabber:add_tab("Combination", EquipmentGraphicKai:get{equip = self._equipment, fairy = true})
	self._vars.card = tostring(tabber)
end

function EquipmentInfoKai:compatibility_details()
	local result = {}
	for index, ship_type in ipairs(self._shown_ship_types) do
		if index % 2 == 1 then
			table.insert(result, self._row_starter)
		end
		local compatibility, note, ship_label
		if ship_type then
			compatibility, note = self._equipment:equippable(ship_type)
			ship_label = Formatting:format_ship_type(ship_type)-- + " " + Formatting:format_equipment_compatibility_symbol(compatibility)
			if note then
				ship_label = Formatting:tooltip(ship_label, note)
			end
		else
			ship_label = Formatting:format_ship_type(ship_type)
		end 
		table.insert(result, format{self._compatibility_cell, bg_color = Formatting:format_equipment_compatibility(compatibility), label = ship_label})
		--table.insert(result, format{self._compatibility_cell, bg_color = Formatting:format_equipment_compatibility_color(compatibility), label = ship_label})
	end
	self._vars.compatibility_details = table.concat(result, "\n")
end

function EquipmentInfoKai:crafting()
	local craft_methods
	if self._equipment:buildable() then
		self._vars.buildable = self._buildable
	else
		self._vars.buildable = self._unbuildable
	end
end

--function EquipmentInfoKai:improvement()
--	local cells = {}
--	local improvement = self._equipment:improvement()
--	if improvement then
--		Formatting:format_resources(improvement:resources())
--		for ship, ship_info in pairs(improvement:ships()) do
--			format{self._}
--end

function EquipmentInfoKai:create_item()
	if self._args.name then
		self._equipment = Equipment(self._args.name, self._args.model)
	else
		self._equipment = Equipment(self._args[1])
	end
end

function EquipmentInfoKai:get_module()
	self._equipment_data_module = Equipment:get_module(self._args.name or self._args[1])
end

function EquipmentInfoKai:create_infobox_prep()
	self._vars = {}
	local table_classes = {"infobox", "infobox-left"}
	if self._args.classes then
		table.insert(table_classes, self._args.classes)
	end
	local collapsible = self._args.collapsible
	if collapsible then
		table.insert(table_classes, "mw-collapsible")
		table.insert(table_classes, "mw-collapsed")
	end
	self._vars.table_class = table.concat(table_classes, " ")
	self._vars.table_id = collapsible and collapsible ~= "true" and ("mw-customcollapsible-" .. collapsible) or ""
	self._vars.float = self._args.float and format{self._float_style_template, float = self._args.float} or ""
end

function EquipmentInfoKai:format_template()
	for _, field in ipairs(self._fields) do
		self[field](self)
	end
	return format(self._template, self._vars)
end

function EquipmentInfoKai:add_fields()
	return
end

function EquipmentInfoKai:create_infobox()
	self:add_fields()
	self:create_item()
	self:get_module()
	self:create_infobox_prep()
	return self:format_template()
end

return EquipmentInfoKai