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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(add _is_type support, remove _type support)
com>Ckwng
(Add short name support)
Line 1: Line 1:
 
local BaseData = require("Module:BaseData")
 
local BaseData = require("Module:BaseData")
local ShipClassData = BaseData({
+
local ShipClassData = BaseData{
 
_class_suffix = "Class",
 
_class_suffix = "Class",
})
+
}
  
 
function ShipClassData:base_name()
 
function ShipClassData:base_name()
 
return self._name
 
return self._name
 +
end
 +
 +
function ShipClassData:short_base_name()
 +
return self._short_name or self:base_name()
 
end
 
end
  
Line 14: Line 18:
 
end
 
end
 
table.insert(result, self:base_name())
 
table.insert(result, self:base_name())
 +
if self._suffix then
 +
table.insert(result, self._suffix)
 +
end
 +
return table.concat(result, " ")
 +
end
 +
 +
function ShipClassData:short_name()
 +
local result = {}
 +
if self._prefix then
 +
table.insert(result, self._prefix)
 +
end
 +
table.insert(result, self:short_base_name())
 
if self._suffix then
 
if self._suffix then
 
table.insert(result, self._suffix)
 
table.insert(result, self._suffix)

Revision as of 22:25, 7 June 2015

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

local BaseData = require("Module:BaseData")
local ShipClassData = BaseData{
	_class_suffix = "Class",
}

function ShipClassData:base_name()
	return self._name
end

function ShipClassData:short_base_name()
	return self._short_name or self:base_name()
end

function ShipClassData:name()
	local result = {}
	if self._prefix then
		table.insert(result, self._prefix)
	end
	table.insert(result, self:base_name())
	if self._suffix then
		table.insert(result, self._suffix)
	end
	return table.concat(result, " ")
end

function ShipClassData:short_name()
	local result = {}
	if self._prefix then
		table.insert(result, self._prefix)
	end
	table.insert(result, self:short_base_name())
	if self._suffix then
		table.insert(result, self._suffix)
	end
	return table.concat(result, " ")
end

function ShipClassData:is_type()
	return self._is_type
end

function ShipClassData:base_type()
	return self._base_type
end

function ShipClassData:create(class)
	class = class or {}
	if class._class and not class._suffix then
		class._suffix = self._class_suffix
	end
	setmetatable(class, class)
	class.__index = self
	return class
end

ShipClassData.__call = ShipClassData.create

return ShipClassData