• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
Created page with "local EnemyShip = {} local ships = {} local EnemyShipData = require('Module:EnemyShipData') function EnemyShip:get(stat, name, model) return self:create(name, model)[stat..."
local EnemyShip = {}
local ships = {}

local EnemyShipData = require('Module:EnemyShipData')

function EnemyShip:get(stat, name, model)
return self:create(name, model)[stat]()
end

function EnemyShip:create(name, model)
if name == nil then
return EnemyShipData()
end
if model == nil then
model = ""
end
--check if we already have it
if ships[name] and ships[name][model] then
return ships[name][model]
else
--Catch a failed require
local success, ship_table = pcall(function () return require(mw.ustring.format('Module:%s', name)) end)
--require succeeded
if success then
ship_table = ship_table[model]
if not ship_table then
--Instantiate EnemyShipData with what we have
ship_table = {_name = name, _suffix = model}
end
--require failed
else
--Instantiate EnemyShipData with what we have
ship_table = {_name = name, _suffix = model}
end
local ship = EnemyShipData(ship_table)
if not ships[name] then
ships[name] = {}
end
ships[name][model] = ship
return ship
end
end

function EnemyShip:get_module(name)
if name == nil then
return nil
end
return mw.ustring.format('Module:%s', name)
end

EnemyShip.__call = EnemyShip.create
setmetatable(EnemyShip, EnemyShip)

return EnemyShip
48

edits

Navigation menu