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

From Kancolle Wiki
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...")
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local EnemyShip = {}
+
local Ship = require('Module:Ship')
local ships = {}
+
 
 +
local EnemyShip = Ship:extend{
 +
_enemy = true,
 +
_ships = {}, --maintain a separate cache from Ship
 +
_data_class = false,
 +
}
 
   
 
   
local EnemyShipData = require('Module:EnemyShipData')
+
function EnemyShip:_prepareShipData()
+
self._data_class = self._data_class or 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
 
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
 
return EnemyShip

Latest revision as of 01:52, 24 May 2021

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

local Ship = require('Module:Ship')

local EnemyShip = Ship:extend{
	_enemy = true,
	_ships = {}, --maintain a separate cache from Ship
	_data_class = false,
}
 
function EnemyShip:_prepareShipData()
	self._data_class = self._data_class or require('Module:EnemyShipData')
end

return EnemyShip