- 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:Equipment"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
local U = require('Module:Core') | local U = require('Module:Core') | ||
local EquipmentData = require('Module:EquipmentData') | local EquipmentData = require('Module:EquipmentData') | ||
− | local EquipmentCollection = | + | |
+ | local EquipmentCollection = mw.loadData('Module:Collection/Equipment') | ||
local Equipment = {} | local Equipment = {} | ||
local equipments = {} | local equipments = {} | ||
+ | |||
+ | local function requireEquipmentModule(name) | ||
+ | local success, data = U.requireModule(name) | ||
+ | if not success then | ||
+ | success, data = U.requireModule('Data/Equipment/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | success, data = U.requireModule('Data/EnemyEquipment/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | success, data = U.requireModule('Data/Item/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | success, data = U.requireModule('Data/PseudoItem/' .. name) | ||
+ | end | ||
+ | if not success then | ||
+ | data = U.find(EquipmentCollection, name, '_name') or {_name = name} | ||
+ | end | ||
+ | return data | ||
+ | end | ||
function Equipment:create(name) | function Equipment:create(name) | ||
− | + | if not name then | |
− | + | return EquipmentData() | |
− | + | end | |
− | + | if not equipments[name] then | |
− | + | equipments[name] = EquipmentData(requireEquipmentModule(name)) | |
− | + | end | |
− | + | return equipments[name] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
function Equipment:get(stat, name) | function Equipment:get(stat, name) | ||
− | + | return self:create(name)[stat]() | |
end | end | ||
− | function Equipment:get_module(name) | + | function Equipment:get_module(name, typeName) |
− | + | return name and string.format('Module:Data/%s/%s', typeName or 'Equipment', name) or nil | |
− | |||
− | |||
− | |||
end | end | ||
function Equipment:extend(data) | function Equipment:extend(data) | ||
− | + | data = data or {} | |
− | + | setmetatable(data, data) | |
− | + | data.__index = self | |
− | + | data.__call = self.__call | |
− | + | return data | |
end | end | ||
Revision as of 11:54, 12 May 2021
Documentation for this module may be created at Module:Equipment/doc
local U = require('Module:Core')
local EquipmentData = require('Module:EquipmentData')
local EquipmentCollection = mw.loadData('Module:Collection/Equipment')
local Equipment = {}
local equipments = {}
local function requireEquipmentModule(name)
local success, data = U.requireModule(name)
if not success then
success, data = U.requireModule('Data/Equipment/' .. name)
end
if not success then
success, data = U.requireModule('Data/EnemyEquipment/' .. name)
end
if not success then
success, data = U.requireModule('Data/Item/' .. name)
end
if not success then
success, data = U.requireModule('Data/PseudoItem/' .. name)
end
if not success then
data = U.find(EquipmentCollection, name, '_name') or {_name = name}
end
return data
end
function Equipment:create(name)
if not name then
return EquipmentData()
end
if not equipments[name] then
equipments[name] = EquipmentData(requireEquipmentModule(name))
end
return equipments[name]
end
function Equipment:get(stat, name)
return self:create(name)[stat]()
end
function Equipment:get_module(name, typeName)
return name and string.format('Module:Data/%s/%s', typeName or 'Equipment', name) or nil
end
function Equipment:extend(data)
data = data or {}
setmetatable(data, data)
data.__index = self
data.__call = self.__call
return data
end
Equipment.__call = Equipment.create
setmetatable(Equipment, Equipment)
return Equipment