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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(typo)
 
(36 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
local BaseTable = require('Module:BaseTable')
 
local BaseTable = require('Module:BaseTable')
 
local Formatting = require('Module:Formatting')
 
local Formatting = require('Module:Formatting')
local ResourceIcons = require('Module:ResourceIcons')
+
local ResourceIcons = require('Module:Data/Asset')
 
local Ship = require('Module:Ship')
 
local Ship = require('Module:Ship')
  
local format = require('Module:StringInterpolation').format
+
local format = require('Module:Core').format
  
 
local ShipRemodelListKai = BaseTable{
 
local ShipRemodelListKai = BaseTable{
_header_template = [[! colspan=5 | Before Remodel
+
_header_template = [[! colspan=4 | Before Remodel
 
! rowspan=2 style="width:30px;" | ⇒
 
! rowspan=2 style="width:30px;" | ⇒
 
! colspan=3 | After Remodel
 
! colspan=3 | After Remodel
! colspan=2 | Required Resources
+
! colspan=12 | Required Resources
 
|-
 
|-
 
! style="width: 50px;" | No.
 
! style="width: 50px;" | No.
Line 16: Line 16:
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Level
 
! style="width: 30px;" | Level
! style="width: 30px;" | ${blueprint}
 
 
! style="width: 50px;" | No.
 
! style="width: 50px;" | No.
 
! style="width: 100px;" | Name
 
! style="width: 100px;" | Name
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Type
! style="width: 30px; text-align: center; vertical-align: middle; background-color: forestgreen;" | ${fuel}
+
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}]],
+
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightgrey;" | ${steel}
 +
! style="width: 30px;" | ${devmat}
 +
! style="width: 30px;" | ${conmat}
 +
! style="width: 30px;" | ${screw}
 +
! style="width: 30px;" | ${blueprint}
 +
! style="width: 30px;" | ${catapult}
 +
! style="width: 30px;" | ${report}
 +
! style="width: 30px;" | ${gunmat}
 +
! style="width: 30px;" | ${airmat}
 +
! style="width: 30px;" | ${armament}
 +
! style="width: 30px;" | ${overseas}]],
 
_header_template_bottom = [[! style="width: 50px;" | No.
 
_header_template_bottom = [[! style="width: 50px;" | No.
 
! style="width: 100px;" | Name
 
! style="width: 100px;" | Name
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Level
 
! style="width: 30px;" | Level
! style="width: 30px;" | ${blueprint}
 
 
! rowspan=2 style="width:30px;" | ⇒
 
! rowspan=2 style="width:30px;" | ⇒
 
! style="width: 50px;" | No.
 
! style="width: 50px;" | No.
 
! style="width: 100px;" | Name
 
! style="width: 100px;" | Name
 
! style="width: 30px;" | Type
 
! style="width: 30px;" | Type
! style="width: 30px; text-align: center; vertical-align: middle; background-color: forestgreen;" | ${fuel}
 
 
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
 
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
 +
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightgrey;" | ${steel}
 +
! style="width: 30px;" | ${devmat}
 +
! style="width: 30px;" | ${conmat}
 +
! style="width: 30px;" | ${screw}
 +
! style="width: 30px;" | ${blueprint}
 +
! style="width: 30px;" | ${catapult}
 +
! style="width: 30px;" | ${report}
 +
! style="width: 30px;" | ${gunmat}
 +
! style="width: 30px;" | ${airmat}
 +
! style="width: 30px;" | ${armament}
 +
! style="width: 30px;" | ${overseas}
 
|-
 
|-
! colspan=5 | Before Remodel
+
! colspan=4 | Before Remodel
 
! colspan=3 | After Remodel
 
! colspan=3 | After Remodel
! colspan=2 | Required Resources]],
+
! colspan=12 | Required Resources]],
 
_columns = {
 
_columns = {
 
"id",
 
"id",
Line 42: Line 60:
 
"type",
 
"type",
 
"remodel_level",
 
"remodel_level",
"remodel_blueprint",
 
 
"arrow",
 
"arrow",
 
"id_after",
 
"id_after",
Line 49: Line 66:
 
"ammo",
 
"ammo",
 
"steel",
 
"steel",
 +
"devmat",
 +
"conmat",
 +
"screw",
 +
"blueprint",
 +
"catapult",
 +
"report",
 +
"gunmat",
 +
"airmat",
 +
"armament",
 +
"overseas",
 
},
 
},
 
_empty_cell = [[| style="text-align: center; vertical-align: middle;" | -]],
 
_empty_cell = [[| style="text-align: center; vertical-align: middle;" | -]],
Line 58: Line 85:
 
_arrow = "⇒",
 
_arrow = "⇒",
 
_question_marks = "??",
 
_question_marks = "??",
 +
_fragment_prefix = "shipremodellistkai",
 
}
 
}
  
Line 69: Line 97:
  
 
function ShipRemodelListKai:name(ship)
 
function ShipRemodelListKai:name(ship)
return {values = {value = tostring(mw.html.create('span'):attr('id', "shipremodellistkai-" .. tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(text, "%s+")))):wikitext(Formatting:format_link(ship:link())))}, bg_color = self._transparent, text_align = self._center_align}
+
return {values = {value = Formatting:id_span(tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(ship:name(), "%s+", self._dash))), self._fragment_prefix, Formatting:format_link(ship:link()))}, bg_color = self._transparent, text_align = self._center_align}
 
end
 
end
  
Line 78: Line 106:
 
function ShipRemodelListKai:remodel_level(ship)
 
function ShipRemodelListKai:remodel_level(ship)
 
self._remodel_to = ship:remodel_to()
 
self._remodel_to = ship:remodel_to()
 +
self._remodel_is_reversion = false
 
local remodel_level = false
 
local remodel_level = false
 
if self._remodel_to then
 
if self._remodel_to then
 +
if self._remodel_to == ship:remodel_from() or ship:remodel_from() and self._remodel_to == Ship(ship:remodel_from()):remodel_from() then
 +
self._remodel_is_reversion = true
 +
else
 +
self._remodel_is_reversion = false
 +
end
 
self._remodel_to = Ship(self._remodel_to)
 
self._remodel_to = Ship(self._remodel_to)
remodel_level = self._remodel_to:remodel_level()
+
if self._remodel_is_reversion then
 +
remodel_level = ship:remodel_to_level()
 +
else
 +
remodel_level = self._remodel_to:remodel_level()
 +
end
 
end
 
end
 
return {values = {value = remodel_level == false and self._dash or Formatting:format_stat(remodel_level)}, bg_color = self._transparent, text_align = self._center_align}
 
return {values = {value = remodel_level == false and self._dash or Formatting:format_stat(remodel_level)}, bg_color = self._transparent, text_align = self._center_align}
end
 
 
function ShipRemodelListKai:remodel_blueprint()
 
local value = self._dash
 
if self._remodel_to then
 
value = Formatting:format_blueprint_requirement_simple(self._remodel_to:remodel_blueprint(), true)
 
elseif self._remodel_to == nil then
 
value = self._question_marks
 
end
 
return {values = {value = value}, bg_color = self._transparent, text_align = self._center_align}
 
 
end
 
end
  
Line 115: Line 143:
 
local name_after = self._remodel_to == nil and self._question_marks or self._dash
 
local name_after = self._remodel_to == nil and self._question_marks or self._dash
 
if self._remodel_to then
 
if self._remodel_to then
local text = select(2, self._remodel_to:link())
+
name_after = Formatting:fragment_link(tostring(self._remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(self._remodel_to:name(), "%s+", self._dash))), self._fragment_prefix, self._remodel_to:name())
name_after = Formatting:format_link("", text, "shipremodellistkai-" .. tostring(self._remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(text, "%s+"))))
 
 
end
 
end
 
return {values = {value = name_after}, bg_color = self._transparent, text_align = self._center_align}
 
return {values = {value = name_after}, bg_color = self._transparent, text_align = self._center_align}
Line 129: Line 156:
 
end
 
end
  
function ShipRemodelListKai:ammo()
+
local function format_remodel_item(item, value)
local ammo = self._remodel_to == nil and self._question_marks or self._dash
+
local special_items = {
if self._remodel_to then
+
blueprint = "blueprint_item",
ammo = Formatting:format_ship_code(self._remodel_to:remodel_cost().ammo)
+
catapult = "prototype_deck_catapult_item",
end
+
report = "report_item",
return {values = {value = ammo}, bg_color = self._transparent, text_align = self._center_align}
+
gunmat = "new_model_gun_mount_improvement_material_item",
 +
airmat = "new_model_aerial_armament_material_item",
 +
armament = "new_model_armament_material_item",
 +
overseas = "latest_overseas_warship_technology_item",
 +
}
 +
value = special_items[item] and Formatting:format_item_requirement(special_items[item], value, true) or value
 +
value = value == true and 1 or value
 +
return value
 +
end
 +
 
 +
function ShipRemodelListKai:remodel_item(ship, item)
 +
local value = self._remodel_to == nil and self._question_marks
 +
or self._remodel_is_reversion and format_remodel_item(item, ship:all_remodel_to_cost()[item])
 +
or self._remodel_to and format_remodel_item(item, self._remodel_to:all_remodel_cost()[item])
 +
return {values = {value = value or self._dash}, bg_color = self._transparent, text_align = self._center_align}
 +
end
 +
 
 +
function ShipRemodelListKai:ammo(ship)
 +
return self:remodel_item(ship, 'ammo')
 +
end
 +
 
 +
function ShipRemodelListKai:steel(ship)
 +
return self:remodel_item(ship, 'steel')
 +
end
 +
 
 +
function ShipRemodelListKai:devmat(ship)
 +
return self:remodel_item(ship, 'devmat')
 +
end
 +
 
 +
function ShipRemodelListKai:conmat(ship)
 +
return self:remodel_item(ship, 'conmat')
 +
end
 +
 
 +
function ShipRemodelListKai:screw(ship)
 +
return self:remodel_item(ship, 'screw')
 +
end
 +
 
 +
function ShipRemodelListKai:blueprint(ship)
 +
return self:remodel_item(ship, 'blueprint')
 +
end
 +
 
 +
function ShipRemodelListKai:catapult(ship)
 +
return self:remodel_item(ship, 'catapult')
 +
end
 +
 
 +
function ShipRemodelListKai:report(ship)
 +
return self:remodel_item(ship, 'report')
 +
end
 +
 
 +
function ShipRemodelListKai:gunmat(ship)
 +
return self:remodel_item(ship, 'gunmat')
 +
end
 +
 
 +
function ShipRemodelListKai:airmat(ship)
 +
return self:remodel_item(ship, 'airmat')
 +
end
 +
 
 +
function ShipRemodelListKai:armament(ship)
 +
return self:remodel_item(ship, 'armament')
 
end
 
end
  
function ShipRemodelListKai:steel()
+
function ShipRemodelListKai:overseas(ship)
local steel = self._remodel_to == nil and self._question_marks or self._dash
+
return self:remodel_item(ship, 'overseas')
if self._remodel_to then
 
steel = Formatting:format_ship_code(self._remodel_to:remodel_cost().steel)
 
end
 
return {values = {value = steel}, bg_color = self._transparent, text_align = self._center_align}
 
 
end
 
end
  
Line 151: Line 232:
 
function ShipRemodelListKai:create_header()
 
function ShipRemodelListKai:create_header()
 
local header_icons = {
 
local header_icons = {
 +
ammo = ResourceIcons.ammo,
 +
steel = ResourceIcons.steel,
 +
devmat = ResourceIcons.devmat,
 +
conmat = ResourceIcons.instant_construction,
 +
screw = ResourceIcons.screw,
 
blueprint = ResourceIcons.blueprint,
 
blueprint = ResourceIcons.blueprint,
fuel = ResourceIcons.fuel,
+
catapult = ResourceIcons.prototype_deck_catapult,
ammo = ResourceIcons.ammo,
+
report = ResourceIcons.report,
 +
gunmat = ResourceIcons.new_model_gun_mount_improvement_material,
 +
airmat = ResourceIcons.new_model_aerial_armament_material,
 +
armament = ResourceIcons.new_model_armament_material,
 +
overseas = ResourceIcons.latest_overseas_warship_technology,
 
}
 
}
 
for key, value in pairs(header_icons) do
 
for key, value in pairs(header_icons) do
header_icons[key] = Formatting:format_image{value, caption = Formatting:format_resource_name(key), size = key == "blueprint" and "x18px" or nil}
+
local title = Formatting:format_resource_name(key)
 +
header_icons[key] = Formatting:format_image{value, caption = title, link = title, size = "24px"}
 
end
 
end
 
self._header = format(self._header_template, header_icons)
 
self._header = format(self._header_template, header_icons)
 
self._header_bottom = format(self._header_template_bottom, header_icons)
 
self._header_bottom = format(self._header_template_bottom, header_icons)
 +
end
 +
 +
function ShipRemodelListKai:test()
 +
mw.log(ShipRemodelListKai:Table({iterator = 'shipsByType', type = '6', sort = '_class', listBase = 'true'}))
 
end
 
end
  
 
return ShipRemodelListKai
 
return ShipRemodelListKai

Latest revision as of 18:31, 17 October 2024

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

local BaseTable = require('Module:BaseTable')
local Formatting = require('Module:Formatting')
local ResourceIcons = require('Module:Data/Asset')
local Ship = require('Module:Ship')

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

local ShipRemodelListKai = BaseTable{
	_header_template = [[! colspan=4 | Before Remodel
! rowspan=2 style="width:30px;" | ⇒
! colspan=3 | After Remodel
! colspan=12 | Required Resources
|-
! style="width: 50px;" | No.
! style="width: 100px;" | Name
! style="width: 30px;" | Type
! style="width: 30px;" | Level
! style="width: 50px;" | No.
! style="width: 100px;" | Name
! style="width: 30px;" | Type
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightgrey;" | ${steel}
! style="width: 30px;" | ${devmat}
! style="width: 30px;" | ${conmat}
! style="width: 30px;" | ${screw}
! style="width: 30px;" | ${blueprint}
! style="width: 30px;" | ${catapult}
! style="width: 30px;" | ${report}
! style="width: 30px;" | ${gunmat}
! style="width: 30px;" | ${airmat}
! style="width: 30px;" | ${armament}
! style="width: 30px;" | ${overseas}]],
	_header_template_bottom = [[! style="width: 50px;" | No.
! style="width: 100px;" | Name
! style="width: 30px;" | Type
! style="width: 30px;" | Level
! rowspan=2 style="width:30px;" | ⇒
! style="width: 50px;" | No.
! style="width: 100px;" | Name
! style="width: 30px;" | Type
! style="width: 30px; text-align: center; vertical-align: middle; background-color: darkgoldenrod;" | ${ammo}
! style="width: 30px; text-align: center; vertical-align: middle; background-color: lightgrey;" | ${steel}
! style="width: 30px;" | ${devmat}
! style="width: 30px;" | ${conmat}
! style="width: 30px;" | ${screw}
! style="width: 30px;" | ${blueprint}
! style="width: 30px;" | ${catapult}
! style="width: 30px;" | ${report}
! style="width: 30px;" | ${gunmat}
! style="width: 30px;" | ${airmat}
! style="width: 30px;" | ${armament}
! style="width: 30px;" | ${overseas}
|-
! colspan=4 | Before Remodel
! colspan=3 | After Remodel
! colspan=12 | Required Resources]],
	_columns = {
		"id",
		"name",
		"type",
		"remodel_level",
		"arrow",
		"id_after",
		"name_after",
		"type_after",
		"ammo",
		"steel",
		"devmat",
		"conmat",
		"screw",
		"blueprint",
		"catapult",
		"report",
		"gunmat",
		"airmat",
		"armament",
		"overseas",
	},
	_empty_cell = [[| style="text-align: center; vertical-align: middle;" | -]],
	_column_empty_cells = {
		arrow = [[| style="text-align: center; vertical-align: middle;" | ⇒]],
	},
	_item_class = Ship,
	_dash = "-",
	_arrow = "⇒",
	_question_marks = "??",
	_fragment_prefix = "shipremodellistkai",
}

function ShipRemodelListKai:id(ship)
	return {values = {value = Formatting:format_stat(ship:id())}, 
		bg_color = self._transparent, --Formatting:format_ship_back(back), 
		extra_style = "", --Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
		text_align = self._center_align
	}
end

function ShipRemodelListKai:name(ship)
	return {values = {value = Formatting:id_span(tostring(ship:api_id() or mw.ustring.lower(mw.ustring.gsub(ship:name(), "%s+", self._dash))), self._fragment_prefix, Formatting:format_link(ship:link()))}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:type(ship)
	return {values = {value = Formatting:format_ship_code(ship:type())}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:remodel_level(ship)
	self._remodel_to = ship:remodel_to()
	self._remodel_is_reversion = false
	local remodel_level = false
	if self._remodel_to then
		if self._remodel_to == ship:remodel_from() or ship:remodel_from() and self._remodel_to == Ship(ship:remodel_from()):remodel_from() then
			self._remodel_is_reversion = true
		else
			self._remodel_is_reversion = false
		end
		self._remodel_to = Ship(self._remodel_to)
		if self._remodel_is_reversion then
			remodel_level = ship:remodel_to_level()
		else			
			remodel_level = self._remodel_to:remodel_level()
		end
	end
	return {values = {value = remodel_level == false and self._dash or Formatting:format_stat(remodel_level)}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:arrow()
	return {values = {value = self._arrow}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:id_after()
	local id_after = self._remodel_to == nil and self._question_marks or self._dash
	if self._remodel_to then
		id_after = Formatting:format_stat(self._remodel_to:id())
	end
	return {values = {value = id_after}, 
		bg_color = self._transparent, --Formatting:format_ship_back(back), 
		extra_style = "", --Formatting:extra_style_background_image(back and back > 7, back and back > 6) or ""
		text_align = self._center_align
	}
end

function ShipRemodelListKai:name_after()
	local name_after = self._remodel_to == nil and self._question_marks or self._dash
	if self._remodel_to then
		name_after = Formatting:fragment_link(tostring(self._remodel_to:api_id() or mw.ustring.lower(mw.ustring.gsub(self._remodel_to:name(), "%s+", self._dash))), self._fragment_prefix, self._remodel_to:name())
	end
	return {values = {value = name_after}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:type_after()
	local type_after = self._remodel_to == nil and self._question_marks or self._dash
	if self._remodel_to then
		type_after = Formatting:format_ship_code(self._remodel_to:type())
	end
	return {values = {value = type_after}, bg_color = self._transparent, text_align = self._center_align}
end

local function format_remodel_item(item, value)
	local special_items = {
		blueprint = "blueprint_item",
		catapult = "prototype_deck_catapult_item",
		report = "report_item",
		gunmat = "new_model_gun_mount_improvement_material_item",
		airmat = "new_model_aerial_armament_material_item",
		armament = "new_model_armament_material_item",
		overseas = "latest_overseas_warship_technology_item",
	}
	value = special_items[item] and Formatting:format_item_requirement(special_items[item], value, true) or value
	value = value == true and 1 or value
	return value
end

function ShipRemodelListKai:remodel_item(ship, item)
	local value = self._remodel_to == nil and self._question_marks
		or self._remodel_is_reversion and format_remodel_item(item, ship:all_remodel_to_cost()[item])
		or self._remodel_to and format_remodel_item(item, self._remodel_to:all_remodel_cost()[item])
	return {values = {value = value or self._dash}, bg_color = self._transparent, text_align = self._center_align}
end

function ShipRemodelListKai:ammo(ship)
	return self:remodel_item(ship, 'ammo')
end

function ShipRemodelListKai:steel(ship)
	return self:remodel_item(ship, 'steel')
end

function ShipRemodelListKai:devmat(ship)
	return self:remodel_item(ship, 'devmat')
end

function ShipRemodelListKai:conmat(ship)
	return self:remodel_item(ship, 'conmat')
end

function ShipRemodelListKai:screw(ship)
	return self:remodel_item(ship, 'screw')
end

function ShipRemodelListKai:blueprint(ship)
	return self:remodel_item(ship, 'blueprint')
end

function ShipRemodelListKai:catapult(ship)
	return self:remodel_item(ship, 'catapult')
end

function ShipRemodelListKai:report(ship)
	return self:remodel_item(ship, 'report')
end

function ShipRemodelListKai:gunmat(ship)
	return self:remodel_item(ship, 'gunmat')
end

function ShipRemodelListKai:airmat(ship)
	return self:remodel_item(ship, 'airmat')
end

function ShipRemodelListKai:armament(ship)
	return self:remodel_item(ship, 'armament')
end

function ShipRemodelListKai:overseas(ship)
	return self:remodel_item(ship, 'overseas')
end

ShipRemodelListKai.process_item_key = Ship.process_item_key

ShipRemodelListKai.build_rows = ShipRemodelListKai.build_rows_breaks_as_empty_rows

function ShipRemodelListKai:create_header()
	local header_icons = {
		ammo = ResourceIcons.ammo,
		steel = ResourceIcons.steel,
		devmat = ResourceIcons.devmat,
		conmat = ResourceIcons.instant_construction,
		screw = ResourceIcons.screw,
		blueprint = ResourceIcons.blueprint,
		catapult = ResourceIcons.prototype_deck_catapult,
		report = ResourceIcons.report,
		gunmat = ResourceIcons.new_model_gun_mount_improvement_material,
		airmat = ResourceIcons.new_model_aerial_armament_material,
		armament = ResourceIcons.new_model_armament_material,
		overseas = ResourceIcons.latest_overseas_warship_technology,
	}
	for key, value in pairs(header_icons) do
		local title = Formatting:format_resource_name(key)
		header_icons[key] = Formatting:format_image{value, caption = title, link = title, size = "24px"}
	end
	self._header = format(self._header_template, header_icons)
	self._header_bottom = format(self._header_template_bottom, header_icons)
end

function ShipRemodelListKai:test()
	mw.log(ShipRemodelListKai:Table({iterator = 'shipsByType', type = '6', sort = '_class', listBase = 'true'}))
end

return ShipRemodelListKai