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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(Add size arg to format_image())
com>Ckwng
(Separate data formatting from *Data)
Line 1: Line 1:
local BaseData = {
+
local BaseData = {}
_image_template = "[[File:%s]]",
 
_image_sized_template = "[[File:%s|%s]]",
 
_no_image = "Catbomb.png|300px",
 
_no_image_size = "300px",
 
_simple_link = "[[%s]]",
 
_aliased_link = "[[%s|%s]]",
 
}
 
 
 
function BaseData:create_formatter(lookup)
 
return function(self, 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
 
 
 
BaseData.format_stat = BaseData:create_formatter({
 
[false] = "",
 
})
 
 
 
BaseData.format_speed = BaseData:create_formatter({
 
[5] = "Slow",
 
[10] = "Fast",
 
})
 
 
 
BaseData.format_range = BaseData:create_formatter({
 
[1] = "Short",
 
[2] = "Medium",
 
[3] = "Long",
 
[0] = "Very Short",
 
[4] = "Very Long",
 
})
 
 
 
function BaseData:format_image(name, size, raw)
 
if raw then
 
return name
 
elseif name == nil then
 
return mw.ustring.format(self._image_sized_template, self._no_image, self._no_image_size)
 
else
 
if size then
 
return mw.ustring.format(self._image_sized_template, name, size)
 
else
 
return mw.ustring.format(self._image_template, name)
 
end
 
end
 
end
 
  
 
function BaseData:create(data)
 
function BaseData:create(data)

Revision as of 22:43, 12 February 2015

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

local BaseData = {}

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

BaseData.__call = function (table, ...)
	return table:create(...)
end

setmetatable(BaseData, BaseData)

return BaseData