- 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:Artist"
Jump to navigation
Jump to search
com>Ckwng (Created page with "local Artist = {} local artists = {} local ArtistData = require('Module:ArtistData') function Artist:get(stat, name) return self:create(name)[stat]() end function Artist:...") |
|||
Line 1: | Line 1: | ||
+ | local U = require('Module:Utils') | ||
+ | local ArtistData = require('Module:ArtistData') | ||
+ | |||
local Artist = {} | local Artist = {} | ||
local artists = {} | local artists = {} | ||
− | + | function Artist:get(stat, name) | |
+ | return self:create(name)[stat]() | ||
+ | end | ||
− | function | + | local function requireArtistModule(name) |
− | + | local success, data = U.requireModule(name) | |
+ | if not success then | ||
+ | success, data = U.requireModule('Data/Artist/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | data = {_name = name} | ||
+ | end | ||
+ | return data | ||
end | end | ||
function Artist:create(name) | function Artist:create(name) | ||
− | + | if not name then | |
− | + | return ArtistData() | |
− | + | end | |
− | + | if not artists[name] then | |
− | + | artists[name] = ArtistData(requireArtistModule(name)) | |
− | + | end | |
− | + | return artists[name] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
function Artist:get_module(name) | function Artist:get_module(name) | ||
− | + | return name and string.format('Module:Data/Artist/%s', name) or nil | |
− | |||
− | |||
− | |||
end | end | ||
function Artist:extend(data) | function Artist:extend(data) | ||
− | + | data = data or {} | |
− | + | setmetatable(data, data) | |
− | + | data.__index = self | |
− | + | data.__call = self.__call | |
− | + | return data | |
end | end | ||
Revision as of 10:46, 22 June 2020
Documentation for this module may be created at Module:Artist/doc
local U = require('Module:Utils')
local ArtistData = require('Module:ArtistData')
local Artist = {}
local artists = {}
function Artist:get(stat, name)
return self:create(name)[stat]()
end
local function requireArtistModule(name)
local success, data = U.requireModule(name)
if not success then
success, data = U.requireModule('Data/Artist/' .. name)
end
if not success then
data = {_name = name}
end
return data
end
function Artist:create(name)
if not name then
return ArtistData()
end
if not artists[name] then
artists[name] = ArtistData(requireArtistModule(name))
end
return artists[name]
end
function Artist:get_module(name)
return name and string.format('Module:Data/Artist/%s', name) or nil
end
function Artist:extend(data)
data = data or {}
setmetatable(data, data)
data.__index = self
data.__call = self.__call
return data
end
Artist.__call = Artist.create
setmetatable(Artist, Artist)
return Artist