Line 1: |
Line 1: |
| + | local U = require('Module:Utils') |
| + | local VoiceActorData = require('Module:VoiceActorData') |
| + | |
| local VoiceActor = {} | | local VoiceActor = {} |
| | | |
| local voice_actors = {} | | local voice_actors = {} |
| | | |
− | local VoiceActorData = require('Module:VoiceActorData')
| + | function VoiceActor:get(stat, name) |
| + | return self:create(name)[stat]() |
| + | end |
| | | |
− | function VoiceActor:get(stat, name) | + | local function requireVoiceActorModule(name) |
− | return self:create(name)[stat]()
| + | 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 name == nil then
| + | if not name then |
− | return VoiceActorData()
| + | return VoiceActorData() |
− | --check if we already have it
| + | end |
− | elseif voice_actors[name] then
| + | if not voice_actors[name] then |
− | return voice_actors[name]
| + | voice_actors[name] = VoiceActorData(requireVoiceActorModule(name)) |
− | else
| + | end |
− | --Catch a failed require
| + | return voice_actors[name] |
− | local success, voice_actor_table = pcall(function () return require(self:get_module(name)) end)
| |
− | --require failed
| |
− | if not success then
| |
− | --create a VoiceActorData with what we have
| |
− | voice_actor_table = {_name = name}
| |
− | end
| |
− | local voice_actor = VoiceActorData(voice_actor_table)
| |
− | voice_actors[name] = voice_actor
| |
− | return voice_actor
| |
− | end
| |
| end | | end |
| | | |
| function VoiceActor:get_module(name) | | function VoiceActor:get_module(name) |
− | if name == nil then
| + | return name and mw.ustring.format('Module:VoiceActor/%s', name) or nil |
− | return nil
| |
− | end
| |
− | return mw.ustring.format('Module:VoiceActor/%s', name)
| |
| end | | end |
| | | |
| function VoiceActor:extend(data) | | function VoiceActor:extend(data) |
− | data = data or {}
| + | data = data or {} |
− | setmetatable(data, data)
| + | setmetatable(data, data) |
− | data.__index = self
| + | data.__index = self |
− | data.__call = self.__call
| + | data.__call = self.__call |
− | return data
| + | return data |
| end | | end |
| | | |