- 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"
Jump to navigation
Jump to search
com>Ckwng (Module for data base class.) |
com>Ckwng m |
||
Line 5: | Line 5: | ||
function BaseData:create_formatter(lookup) | function BaseData:create_formatter(lookup) | ||
+ | local lookup = lookup | ||
return function(self, stat, raw) | return function(self, stat, raw) | ||
if raw then | if raw then |
Revision as of 06:41, 11 December 2014
Documentation for this module may be created at Module:BaseData/doc
local BaseData = {
_image_template = "[[File:%s]]",
_no_image = "Catbomb.png|300px",
}
function BaseData:create_formatter(lookup)
local lookup = 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, raw)
if raw then
return name
elseif name == nil then
return mw.ustring.format(self._image_template, self._no_image)
else
return mw.ustring.format(self._image_template, name)
end
end
function BaseData:create(data)
data = data or {}
setmetatable(data, self)
self.__index = self
return data
end
BaseData.__call = function (table, ...)
return table:create(...)
end
setmetatable(BaseData, BaseData)
return BaseData