• 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 57: Line 57:
  
 
function EquipmentInfoKai:edit_link(equipment_data_module)
 
function EquipmentInfoKai:edit_link(equipment_data_module)
return Formatting:format_edit_link(equipment_data_module, self._edit_link_text, self._equipment_data_documentation)
+
if equipment_data_module then
 +
return Formatting:format_edit_link(equipment_data_module, self._edit_link_text, self._equipment_data_documentation)
 +
end
 +
return format{"<strike>${text}</strike>", text = self._edit_link_text}
 
end
 
end
  

Revision as of 18:47, 2 March 2015

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

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

local EquipmentInfoKai = {
	_template = [[{|style="border: 1px solid darkgray; width: 400px;"
|-
| colspan="2" style="position: relative; text-align: center; background-color: ${back};${extra_style};"|<div style="position: absolute; right: 5px;">${edit_link}</div>
<p style="font-size: 25px">'''${name}'''</p>
<p style="font-size: 20px">'''No.${id} ${japanese_name}'''</p>
|-
| colspan="2" style="text-align: center; background-color: whitesmoke;"|
'''${icon} ${eq_type}'''

<b>Effects: ${effects}</b>

'''Scrap value: ${scrap}'''
|- 
| colspan="2" style="text-align: center;" | ${card}
|-
| colspan="2" style="text-align: center; background-color: LightSkyBlue;" | '''Refittable Class'''
${compatibility_details}
|}]],
	_row_starter = "|-",
	_compatibility_cell = [[| style="width: 200px; text-align: center; background-color: ${bg_color};" | ${label}]],
	_equipment_data_documentation = "Template:EquipmentDataDocumentation/EditIntro",
	_edit_link_text = "Edit",
	_shown_ship_types = {
		2,
		3,
		--
		21,
		4,
		--
		5,
		6,
		--
		8,
		9,
		--
		10,
		7,
		--
		11,
		18,
		--
		13,
		14,
		--
		20,
		16,
		--
		17,
		19,
	}
}

function EquipmentInfoKai:edit_link(equipment_data_module)
	if equipment_data_module then
		return Formatting:format_edit_link(equipment_data_module, self._edit_link_text, self._equipment_data_documentation)
	end
	return format{"<strike>${text}</strike>", text = self._edit_link_text}
end

function EquipmentInfoKai:back(equipment)
	return Formatting:format_equipment_back(equipment:back())
end

function EquipmentInfoKai:extra_style(equipment)
	local back = equipment:back()
	return Formatting:extra_style_background_image(false, back and back >= 4)
end

function EquipmentInfoKai:name(equipment)
	local localized_name = equipment:localized_name()
	if localized_name then
		local name, page, section = equipment:link()
		return Formatting:format_link(Formatting:format_stat_with_max(name, localized_name), page, section)
	end
	return Formatting:format_link(equipment:link())
end

function EquipmentInfoKai:id(equipment)
	return Formatting:format_stat(equipment:id())
end

function EquipmentInfoKai:japanese_name(equipment)
	return Formatting:tooltip(Formatting:format_stat(equipment:japanese_name()), Formatting:format_stat(equipment:reading()))
end

function EquipmentInfoKai:icon(equipment)
	return Formatting:format_image{Formatting:format_equipment_icon(equipment:icon())}
end

function EquipmentInfoKai:eq_type(equipment)
	return Formatting:tooltip(Formatting:format_equipment_type(equipment:type()), Formatting:format_equipment_rarity(equipment:rarity()))
end

function EquipmentInfoKai:effects(equipment)
	return Formatting:format_stat_bonuses{
		firepower = equipment:firepower(), 
		bombing = equipment:bombing(), 
		torpedo = equipment:torpedo(), 
		aa = equipment:aa(), 
		armor = equipment:armor(), 
		asw = equipment:asw(), 
		shelling_accuracy = equipment:shelling_accuracy(),
		torpedo_accuracy = equipment:torpedo_accuracy(),
		evasion = equipment:evasion(),
		los = equipment:los(),
		speed = Formatting:format_speed(equipment:speed()),
		luck = equipment:luck(),
		range = Formatting:format_range(equipment:range()),
		special = equipment:special(),
	}
end

function EquipmentInfoKai:scrap(equipment)
	return Formatting:format_resources(equipment:scrap())
end

function EquipmentInfoKai:card(equipment)
	local card_name = equipment:card_name()
	if card_name then
		local card_caption = {}
		local card_local = equipment:card_localized_name()
		if card_local ~= false 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(equipment:card_japanese_name(), equipment:card_reading()))

		return Formatting:format_image{equipment:card(),
			caption = table.concat(card_caption)
		}
	end
	return Formatting:format_image{equipment:card()}
end

function EquipmentInfoKai:compatibility_details(equipment)
	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 = equipment:equippable(ship_type)
		local ship_label = Formatting:format_ship_type(ship_type)
		if note then
			ship_label = Formatting:tooltip(ship_label, note)
		end
		table.insert(result, format{self._compatibility_cell, bg_color = Formatting:format_equipment_compatibility(compatibility), label = ship_label})
	end
	return table.concat(result, "\n")
end

function EquipmentInfoKai:Infobox(name)
	local equipment = Equipment(name)
	local equipment_data_module = Equipment:get_module(name)

	return format{self._template,
		edit_link = self:edit_link(equipment_data_module),
		back = self:back(equipment), 
		extra_style = self:extra_style(equipment), 
		name = self:name(equipment), 
		id = self:id(equipment),
		japanese_name = self:japanese_name(equipment),
		icon = self:icon(equipment),
		eq_type = self:eq_type(equipment),
		effects = self:effects(equipment),
		scrap = self:scrap(equipment),
		card = self:card(equipment),
		compatibility_details = self:compatibility_details(equipment),
	}
end

return EquipmentInfoKai