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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(Module containing class for ship data retrieval)
 
com>Ckwng
Line 1: Line 1:
local ShipData = {}
+
local BaseData = require("Module:BaseData")
 +
local ShipData = BaseData()
  
function ShipData:name(type, raw)
+
function ShipData:name(raw)
return self.format_stat(self._name, raw)
+
return self:format_stat(self._name, raw)
 
end
 
end
  
 
function ShipData:japanese_name(raw)
 
function ShipData:japanese_name(raw)
return self.format_stat(self._japanese_name, raw)
+
return self:format_stat(self._japanese_name, raw)
 
end
 
end
  
 
function ShipData:id(raw)
 
function ShipData:id(raw)
return self.format_stat(self._id, raw)
+
return self:format_stat(self._id, raw)
 
end
 
end
  
 
function ShipData:true_id(raw)
 
function ShipData:true_id(raw)
return self.format_stat(self._true_id, raw)
+
return self:format_stat(self._true_id, raw)
 
end
 
end
  
Line 22: Line 23:
  
 
function ShipData:rarity(raw)
 
function ShipData:rarity(raw)
return self.format_rarity(self._rarity, raw)
+
return self:format_rarity(self._rarity, raw)
 
end
 
end
  
 
function ShipData:class(raw)
 
function ShipData:class(raw)
return self.format_stat(self._class, raw)
+
return self:format_stat(self._class, raw)
 
end
 
end
  
 
function ShipData:type(raw)
 
function ShipData:type(raw)
return self.format_type(self._type, raw)
+
return self:format_type(self._type, raw)
 
end
 
end
  
function ShipData:card(type)
+
function ShipData:card(raw)
return self._card
+
return self._format_image(self._card, raw)
 
end
 
end
  
 
function ShipData:firepower(raw)
 
function ShipData:firepower(raw)
return self.format_stat(self._firepower, raw)
+
return self:format_stat(self._firepower, raw)
 
end
 
end
  
 
function ShipData:firepower_max(raw)
 
function ShipData:firepower_max(raw)
return self.format_stat(self._firepower_max, raw)
+
return self:format_stat(self._firepower_max, raw)
 
end
 
end
  
Line 50: Line 51:
  
 
function ShipData:torpedo(raw)
 
function ShipData:torpedo(raw)
return self.format_stat(self._torpedo, raw)
+
return self:format_stat(self._torpedo, raw)
 
end
 
end
  
 
function ShipData:torpedo_max(raw)
 
function ShipData:torpedo_max(raw)
return self.format_stat(self._torpedo_max, raw)
+
return self:format_stat(self._torpedo_max, raw)
 
end
 
end
  
Line 62: Line 63:
  
 
function ShipData:aa(raw)
 
function ShipData:aa(raw)
return self.format_stat(self._aa, raw)
+
return self:format_stat(self._aa, raw)
 
end
 
end
  
 
function ShipData:aa_max(raw)
 
function ShipData:aa_max(raw)
return self.format_stat(self._aa_max, raw)
+
return self:format_stat(self._aa_max, raw)
 
end
 
end
  
Line 74: Line 75:
  
 
function ShipData:armor(raw)
 
function ShipData:armor(raw)
return self.format_stat(self._armor, raw)
+
return self:format_stat(self._armor, raw)
 
end
 
end
  
 
function ShipData:armor_max(raw)
 
function ShipData:armor_max(raw)
return self.format_stat(self._armor_max, raw)
+
return self:format_stat(self._armor_max, raw)
 
end
 
end
  
Line 86: Line 87:
  
 
function ShipData:asw(raw)
 
function ShipData:asw(raw)
return self.format_stat(self._asw, raw)
+
return self:format_stat(self._asw, raw)
 
end
 
end
  
 
function ShipData:asw_max(raw)
 
function ShipData:asw_max(raw)
return self.format_stat(self._asw_max, raw)
+
return self:format_stat(self._asw_max, raw)
 
end
 
end
  
Line 98: Line 99:
  
 
function ShipData:evasion(raw)
 
function ShipData:evasion(raw)
return self.format_stat(self._evasion, raw)
+
return self:format_stat(self._evasion, raw)
 
end
 
end
  
 
function ShipData:evasion_max(raw)
 
function ShipData:evasion_max(raw)
return self.format_stat(self._evasion_max, raw)
+
return self:format_stat(self._evasion_max, raw)
 
end
 
end
  
Line 110: Line 111:
  
 
function ShipData:los(raw)
 
function ShipData:los(raw)
return self.format_stat(self._los, raw)
+
return self:format_stat(self._los, raw)
 
end
 
end
  
 
function ShipData:los_max(raw)
 
function ShipData:los_max(raw)
return self.format_stat(self._los_max, raw)
+
return self:format_stat(self._los_max, raw)
 
end
 
end
  
Line 122: Line 123:
  
 
function ShipData:luck(raw)
 
function ShipData:luck(raw)
return self.format_stat(self._luck, raw)
+
return self:format_stat(self._luck, raw)
 
end
 
end
  
 
function ShipData:luck_max(raw)
 
function ShipData:luck_max(raw)
return self.format_stat(self._luck_max, raw)
+
return self:format_stat(self._luck_max, raw)
 
end
 
end
  
Line 199: Line 200:
  
 
function ShipData.speed()
 
function ShipData.speed()
return self.format_speed(self._speed)
+
return self:format_speed(self._speed)
 
end
 
end
  
 
function ShipData.range()
 
function ShipData.range()
return self.format_range(self._speed)
+
return self:format_range(self._speed)
 
end
 
end
 
function ShipData.create_formatter(lookup)
 
return function(stat, raw)
 
if raw then
 
return stat
 
elseif stat == nil then
 
return "??"
 
end
 
local result = lookup[stat]
 
if result == nil then
 
return stat
 
else
 
return result
 
end
 
end
 
end
 
 
ShipData.format_stat = ShipData.create_formatter({
 
[false] = "",
 
})
 
 
ShipData.format_speed = ShipData.create_formatter({
 
[5] = "Slow",
 
[10] = "Fast",
 
})
 
 
ShipData.format_range = ShipData.create_formatter({
 
[1] = "Short",
 
[2] = "Medium",
 
[3] = "Long",
 
[0] = "Very Short",
 
[4] = "Very Long",
 
})
 
  
 
ShipData.format_rarity = ShipData.create_formatter({
 
ShipData.format_rarity = ShipData.create_formatter({

Revision as of 06:11, 11 December 2014

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

local BaseData = require("Module:BaseData")
local ShipData = BaseData()

function ShipData:name(raw)
	return self:format_stat(self._name, raw)
end

function ShipData:japanese_name(raw)
	return self:format_stat(self._japanese_name, raw)
end

function ShipData:id(raw)
	return self:format_stat(self._id, raw)
end

function ShipData:true_id(raw)
	return self:format_stat(self._true_id, raw)
end

function ShipData:has_true_id()
	return self._true_id == false
end

function ShipData:rarity(raw)
	return self:format_rarity(self._rarity, raw)
end

function ShipData:class(raw)
	return self:format_stat(self._class, raw)
end

function ShipData:type(raw)
	return self:format_type(self._type, raw)
end

function ShipData:card(raw)
	return self._format_image(self._card, raw)
end

function ShipData:firepower(raw)
	return self:format_stat(self._firepower, raw)
end

function ShipData:firepower_max(raw)
	return self:format_stat(self._firepower_max, raw)
end

function ShipData:has_firepower_max()
	return self._firepower_max ~= false
end

function ShipData:torpedo(raw)
	return self:format_stat(self._torpedo, raw)
end

function ShipData:torpedo_max(raw)
	return self:format_stat(self._torpedo_max, raw)
end

function ShipData:has_torpedo_max()
	return self._torpedo_max ~= false
end

function ShipData:aa(raw)
	return self:format_stat(self._aa, raw)
end

function ShipData:aa_max(raw)
	return self:format_stat(self._aa_max, raw)
end

function ShipData:has_aa_max()
	return self._aa_max ~= false
end

function ShipData:armor(raw)
	return self:format_stat(self._armor, raw)
end

function ShipData:armor_max(raw)
	return self:format_stat(self._armor_max, raw)
end

function ShipData:has_armor_max()
	return self._armor_max ~= false
end

function ShipData:asw(raw)
	return self:format_stat(self._asw, raw)
end

function ShipData:asw_max(raw)
	return self:format_stat(self._asw_max, raw)
end

function ShipData:has_asw_max()
	return self._asw_max ~= false
end

function ShipData:evasion(raw)
	return self:format_stat(self._evasion, raw)
end

function ShipData:evasion_max(raw)
	return self:format_stat(self._evasion_max, raw)
end

function ShipData:has_evasion_max()
	return self._evasion_max ~= false
end

function ShipData:los(raw)
	return self:format_stat(self._los, raw)
end

function ShipData:los_max(raw)
	return self:format_stat(self._los_max, raw)
end

function ShipData:has_los_max()
	return self._los_max ~= false
end

function ShipData:luck(raw)
	return self:format_stat(self._luck, raw)
end

function ShipData:luck_max(raw)
	return self:format_stat(self._luck_max, raw)
end

function ShipData:has_luck_max()
	return self._luck_max ~= false
end

function ShipData:buildable()
	return self._buildable
end

function ShipData.build_time(raw)
	if raw then
		return self._build_time
	elseif self._build_time then
		return os.date(self._build_time * 60)
	else
		return "??"
	end
end

function ShipData:equipment(slot, raw)
	local equipment_slot = self._equipment[slot]
	if not equipment_slot then
		return not raw and "- Locked -" or nil
	end
	local equipment = equipment_slot["equipment"]
	if raw then
		return equipment
	elseif equipment == nil then
		return "??"
	elseif equipment == false then
		return "- Unequipped -"
	else
		return equipment
	end
end

function ShipData:space(slot, raw)
	local equipment_slot = self._equipment[slot]
	if not equipment_slot then
		return not raw and "-" or nil
	end
	local space = equipment_slot["space"]
	if space == nil then
		return "??"
	elseif space == false then
		return "-"
	else
		return space
	end
end

function ShipData:slots()
	return #self._equipment
end

function ShipData:total_space()
	local total_space, space
	for _, v in ipairs(self._equipment) do
		space = v["space"]
		if space == nil then
			total_space = "??"
			break
		elseif space == false then
		else
			total_space = total_space + space
		end
	end
	return total_space
end

function ShipData.speed()
	return self:format_speed(self._speed)
end

function ShipData.range()
	return self:format_range(self._speed)
end

ShipData.format_rarity = ShipData.create_formatter({
	[0] = "??",
	[1] = "Very Common",
	[2] = "Common",
	[3] = "Uncommon",
	[4] = "Rare",
	[5] = "Very Rare",
	[6] = "Holo",
	[7] = "S Holo",
	[8] = "SS Holo",
	[-1] = "Abyssal",
	[-2] = "Elite",
	[-3] = "Flagship",
	[-4] = "Kai",
	[-5] = "Kai Elite",
	[-6] = "Kai Flagship",
	[-7] = "Late Model",
	float = "Floating Fortress",
	demon = "Demon",
	princess = "Princess",
	war_demon = "War Demon",
	war_princess = "War Princess",
	})

ShipData.format_type = ShipData.create_formatter({
	[0] = "??",
	[1] = "Coastal Defence ShipData",
	[2] = "Destroyer",
	[3] = "Light Cruiser",
	[4] = "Torpedo Cruiser",
	[5] = "Heavy Cruiser",
	[6] = "Aviation Cruiser",
	[7] = "Light Carrier",
	[8] = "Battleship",
	[9] = "Battleship",
	[10] = "Aviation Battleship",
	[11] = "Standard Carrier",
	[12] = "Super Dreadnought",
	[13] = "Submarine",
	[14] = "Aircraft Carrying Submarine",
	[15] = "Replenishment Oiler",
	[16] = "Seaplane Tender",
	[17] = "Amphibious Assault Ship",
	[18] = "Armored Carrier",
	[19] = "Repair Ship",
	[20] = "Submarine Tender",
	})

function ShipData:create(ship)
	ship = ship or {}
	setmetatable(ship, self)
	self.__index = self
	return ship
end

ShipData.__call = ShipData.create

return ShipData