- 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:VoiceActor"
Jump to navigation
Jump to search
com>Ckwng |
m (5 revisions imported) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | local U = require('Module:Core') | ||
+ | local VoiceActorData = require('Module:VoiceActorData') | ||
+ | |||
local VoiceActor = {} | local VoiceActor = {} | ||
local voice_actors = {} | local voice_actors = {} | ||
− | + | function VoiceActor:get(stat, name) | |
+ | return self:create(name)[stat]() | ||
+ | end | ||
− | function | + | local function requireVoiceActorModule(name) |
− | + | local success, data = U.requireModule('VoiceActor/' .. name) | |
+ | if not success then | ||
+ | success, data = U.requireModule('Data/VoiceActor/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | data = {_name = name} | ||
+ | end | ||
+ | return data | ||
end | end | ||
function VoiceActor:create(name) | function VoiceActor:create(name) | ||
− | + | if not name then | |
− | + | return VoiceActorData() | |
− | + | end | |
− | + | if not voice_actors[name] then | |
− | + | voice_actors[name] = VoiceActorData(requireVoiceActorModule(name)) | |
− | + | end | |
− | + | return voice_actors[name] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
function VoiceActor:get_module(name) | function VoiceActor:get_module(name) | ||
− | + | return name and mw.ustring.format('Module:Data/VoiceActor/%s', name) or nil | |
− | |||
− | |||
− | |||
end | end | ||
function VoiceActor:extend(data) | function VoiceActor:extend(data) | ||
− | + | data = data or {} | |
− | + | setmetatable(data, data) | |
− | + | data.__index = self | |
− | + | data.__call = self.__call | |
− | + | return data | |
end | end | ||
Latest revision as of 12:43, 12 May 2021
Documentation for this module may be created at Module:VoiceActor/doc
local U = require('Module:Core')
local VoiceActorData = require('Module:VoiceActorData')
local VoiceActor = {}
local voice_actors = {}
function VoiceActor:get(stat, name)
return self:create(name)[stat]()
end
local function requireVoiceActorModule(name)
local success, data = U.requireModule('VoiceActor/' .. name)
if not success then
success, data = U.requireModule('Data/VoiceActor/' .. name)
end
if not success then
data = {_name = name}
end
return data
end
function VoiceActor:create(name)
if not name then
return VoiceActorData()
end
if not voice_actors[name] then
voice_actors[name] = VoiceActorData(requireVoiceActorModule(name))
end
return voice_actors[name]
end
function VoiceActor:get_module(name)
return name and mw.ustring.format('Module:Data/VoiceActor/%s', name) or nil
end
function VoiceActor:extend(data)
data = data or {}
setmetatable(data, data)
data.__index = self
data.__call = self.__call
return data
end
VoiceActor.__call = VoiceActor.create
setmetatable(VoiceActor, VoiceActor)
return VoiceActor