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

From Kancolle Wiki
Jump to navigation Jump to search
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local U = require('Module:Utils')
+
local U = require('Module:Core')
 
local EquipmentData = require('Module:EquipmentData')
 
local EquipmentData = require('Module:EquipmentData')
local EquipmentCollection = require('Module:Collection/Equipment')
+
 
 +
local EquipmentCollection = mw.loadData('Module:Data/Equipment')
  
 
local Equipment = {}
 
local Equipment = {}
Line 7: Line 8:
 
local equipments = {}
 
local equipments = {}
  
function Equipment:create(name)
+
local function requireEquipmentModule(name, is_enemy)
if not name then
+
  local success, data
return EquipmentData()
+
  if not is_enemy then
end
+
success, data = U.requireModule('Data/Equipment/' .. name)
if equipments[name] then
+
    if not success then
return equipments[name]
+
      success, data = U.requireModule('Data/Item/' .. name)
end
+
    end
local success, equipment_table = U.requireModule(name)
+
    if not success then
if not success then
+
      success, data = U.requireModule('Data/PseudoItem/' .. name)
local eq = U.find(EquipmentCollection, name, '_name')
+
    end
local success2, equipment_table2
+
    if not success then
if eq and (eq._module or eq._dev) then
+
      data = U.find(EquipmentCollection, name, '_name')
success2, equipment_table2 = U.requireModule(eq._module or eq._dev and name .. '/Dev')
+
      -- success = true
end
+
    end
equipment_table = success2 and equipment_table2 or eq or { _name = name }
+
  end
if eq and eq._module then
+
  if not success then
equipment_table._module = eq._module
+
    success, data = U.requireModule('Data/EnemyEquipment/' .. name)
end
+
  end
if eq and eq._dev then
+
  if not success then
equipment_table._dev = eq._dev
+
  return {_name = name}
end
+
  end
end
+
  data._is_enemy = is_enemy
local equipment = EquipmentData(equipment_table)
+
  return data
equipments[name] = equipment
+
end
return equipment
+
 
 +
function Equipment:create(name, is_enemy)
 +
  if not name then
 +
    return EquipmentData()
 +
  end
 +
  if not equipments[name] then
 +
    equipments[name] = EquipmentData(requireEquipmentModule(name, is_enemy))
 +
  end
 +
  return equipments[name]
 
end
 
end
  
 
function Equipment:get(stat, name)
 
function Equipment:get(stat, name)
return self:create(name)[stat]()
+
  return self:create(name)[stat]()
 
end
 
end
  
function Equipment:get_module(name)
+
function Equipment:get_module(name, typeName)
return name and mw.ustring.format(
+
  return name and string.format('Module:Data/%s/%s', typeName or 'Equipment', name) or nil
    'Module:%s',
 
    equipments[name] and (equipments[name]._module or equipments[name]._dev and name .. '/Dev') or name
 
    ) or nil
 
 
end
 
end
  
 
function Equipment:extend(data)
 
function Equipment: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
  

Latest revision as of 15:13, 30 April 2023

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:Data/Equipment')

local Equipment = {}

local equipments = {}

local function requireEquipmentModule(name, is_enemy)
  local success, data
  if not is_enemy then
	success, data = U.requireModule('Data/Equipment/' .. name)
    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')
      -- success = true
    end
  end
  if not success then
    success, data = U.requireModule('Data/EnemyEquipment/' .. name)
  end
  if not success then
  	return {_name = name}
  end
  data._is_enemy = is_enemy
  return data
end

function Equipment:create(name, is_enemy)
  if not name then
    return EquipmentData()
  end
  if not equipments[name] then
    equipments[name] = EquipmentData(requireEquipmentModule(name, is_enemy))
  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