- 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:Ship"
Jump to navigation
Jump to search
com>Ckwng (Entry point module) |
com>Ckwng (Add some sort of memoization) |
||
Line 1: | Line 1: | ||
local Ship = {} | local Ship = {} | ||
+ | local ships = {} | ||
local ShipData = require('Module:ShipData') | local ShipData = require('Module:ShipData') | ||
Line 8: | Line 9: | ||
function Ship:create(name, model) | function Ship:create(name, model) | ||
− | local ship_table = require(mw.ustring.format('Module:%s', name)) | + | if ships[name] and ships[name][model] then |
− | + | return ships[name][model] | |
+ | else | ||
+ | local ship_table = require(mw.ustring.format('Module:%s', name)) | ||
+ | local ship = ShipData:create(ship_table[model]) | ||
+ | if not ships[name] then | ||
+ | ships[name] = {} | ||
+ | end | ||
+ | ships[name][model] = ship | ||
+ | return ship | ||
+ | end | ||
end | end | ||
Revision as of 06:12, 11 December 2014
Documentation for this module may be created at Module:Ship/doc
local Ship = {}
local ships = {}
local ShipData = require('Module:ShipData')
function Ship:get(stat, name, model)
return self:create(name, model)[stat]()
end
function Ship:create(name, model)
if ships[name] and ships[name][model] then
return ships[name][model]
else
local ship_table = require(mw.ustring.format('Module:%s', name))
local ship = ShipData:create(ship_table[model])
if not ships[name] then
ships[name] = {}
end
ships[name][model] = ship
return ship
end
end
Ship.__call = Ship.create
setmetatable(Ship, Ship)
return Ship