• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Module:ShipMetaKai

From Kancolle Wiki
Revision as of 21:48, 2 August 2016 by com>Ckwng (Implement availability and impl date)
Jump to navigation Jump to search

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

local BaseData = require('Module:BaseData')
local Ship = require('Module:Ship')
local Formatting = require('Module:Formatting')

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

local ShipMetaKai = BaseData{
	_template = [[{|class="${table_class}" style="float: right;" 
|-
!colspan=2|${name} ${japanese_name}
|-
!Class
|${class}
|-
!${voice_actor_header}
|${voice_actor}
|-
!${artist_header}
|${artist}
|-
!Availability
|${availability}
|-
!Implemented on
|${implementation_date}
|}]],
    _voice_actor_header = "[[Glossary#List of Vessels by Japanese Voice Actresses|Seiyuu]]",
    _artist_header = "[[Glossary#List of Vessels by Artist|Artist]]",
    _class_template = "[[:Category:${ship_class}|]]",
    _normal_construction_label = "Normal",
    _large_ship_construction_label = "LSC",
    _buildable_label = "Construction",
    _drop_label = "Drop",
    _details_template = " ${details}",
    _event_reward_label = "Event Reward",
    _event_drop_label = "Event Drop",
    _node_name_template = "${world}-${map}-${node}",
    _node_formation_template = "-${formation}",
    _event_node_name_template = "${year} ${quarter} E-${map}-${node}",
    _quarters = {
    	[1] = "Winter",
    	[4] = "Spring",
    	[7] = "Summer",
    	[10] = "Fall",
	},
	_difficulties = {
		[0] = "All",
		[1] = "Easy",
		[2] = "Medium",
		[3] = "Hard",
	},
	_fields = {
	    "name",
	    "class",
	    "voice_actor",
	    "artist",
	    "availability",
	    "implementation_date",
	},
}

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

function ShipMetaKai:name()
    self._vars.name = Formatting:format_stat(self._ship:name())
    self._vars.japanese_name = tostring(Formatting:japanese_text(Formatting:format_stat(self._ship:japanese_name())))
end

function ShipMetaKai:class()
    local ship_class = self._ship:class()
    if ship_class then
        self._vars.class = format{self._class_template, ship_class = ship_class:name()}
    end
end

function ShipMetaKai:voice_actor()
    self._vars.voice_actor = Formatting:format_stat(self._ship:voice_actor())
end

function ShipMetaKai:artist()
    self._vars.artist = Formatting:format_stat(self._ship:artist())
end

function ShipMetaKai:availability()
    local availability = self._ship:availability()
    local result = {}
    for _, method in ipairs(availability) do
        if method == "buildable" then
            local details = {}
            if availability.buildable.normal then
                table.insert(details, self._normal_construction_label)
            end
            if availability.buildable.lsc then
                table.insert(details, self._large_ship_construction_label)
            end
            if #details > 0 then
            	details = format{self._details_template, details = table.concat(details, ", ")}
            else
            	details = ""
            end
            table.insert(result, self._buildable_label .. details)
        elseif method == "drop" then
        	local details = {}
        	if availability.drop then
        		for _, node in availability.drop do
        			local node_name = format{self._node_name_template, world = node[1], map = node[2], node = node[3]}
					if #node == 4 then
						node_name = node_name .. format{self._node_formation_template, formation = node[4]}
					end
        			table.insert(details, node_name)
        		end
        	end
            if #details > 0 then
            	details = format{self._details_template, details = table.concat(details, ", ")}
            else
            	details = ""
            end
            table.insert(result, self._drop_label .. details)
        elseif method == "event_reward" then
        	local details = {}
        	if availability.event_reward then
        		for _, map in availability.event_reward do
        			local map_name = format{self._map_name_template, year = map[1], quarter = self._quarters[node[2]], map = map[3]}
        			if #map == 4 then
        				map_name = map_name .. format{self._details_template, details = self._difficulties[map[4]]}
        			end
        			table.insert(details, map_name)
        		end
        	end
            if #details > 0 then
            	details = format{self._details_template, details = table.concat(details, ", ")}
            else
            	details = ""
            end
            table.insert(result, self._event_reward_label .. details)
        elseif method == "event_drop" then
        	local details = {}
        	if availability.event_drop then
        		for _, node in availability.drop do
        			local node_name = format{self._event_node_name_template, year = node[1], quarter = self._quarters[node[2]], map = node[3], node = node[4]}
					if #node == 5 then
						node_name = node_name .. format{self._node_formation_template, formation = node[5]}
					end
        			table.insert(details, node_name)
        		end
        	end
            if #details > 0 then
            	details = format{self._details_template, details = table.concat(details, ", ")}
            else
            	details = ""
            end
            table.insert(result, self._event_drop_label .. details)
        end
    end
    self._vars.availability = table.concat(result, "<br/>")
end

function ShipMetaKai:implementation_date()
    local implementation_date = self._ship:implementation_date()
    self._vars.implementation_date = format{self._date_template, year = implementation_date[1], month = implementation_date[2], day = implementation_date[3]}
end

function ShipMetaKai:create_item()
	if self._args.name then
		self._ship = Ship(self._args.name, self._args.model)
	else
		self._ship = Ship(self._args[1])
	end
end

function ShipMetaKai:get_module()
	self._ship_data_module = Ship:get_module(self._args.name or self._args[1])
end

function ShipMetaKai:create_infobox_prep()
	self._vars = {}
	local table_classes = {"wikitable"}
	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 ""
	self._vars.voice_actor_header = self._voice_actor_header
	self._vars.artist_header = self._artist_header
end

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

function ShipMetaKai:add_fields()
	return
end

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

return ShipMetaKai