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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
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
  

Revision as of 10:55, 22 June 2020

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

local U = require('Module:Utils')
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: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