• 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
no edit summary
Line 1: Line 1:  +
local U = require('Module:Utils')
 +
local EquipmentData = require('Module:EquipmentData')
 +
local EquipmentCollection = require('Module:Collection/Equipment')
 +
 
local Equipment = {}
 
local Equipment = {}
    
local equipments = {}
 
local equipments = {}
  −
local U = require('Module:Utils')
  −
local EquipmentData = require('Module:EquipmentData')
  −
  −
function Equipment:get(stat, name)
  −
return self:create(name)[stat]()
  −
end
      
function Equipment:create(name)
 
function Equipment:create(name)
if name == nil then
+
if not name then
 
return EquipmentData()
 
return EquipmentData()
--check if we already have it
+
end
elseif equipments[name] then
+
if equipments[name] then
 
return equipments[name]
 
return equipments[name]
else
+
end
--Catch a failed require
+
local success, equipment_table = U.requireModule(name)
local success, equipment_table = pcall(function () return require(mw.ustring.format('Module:%s', name)) end)
+
if not success then
--require failed, equipment_table can be true on a wikia bug (Ticket 356218)
+
local eq = U.find(EquipmentCollection, name, '_name')
if not success or equipment_table == true then
+
local success2, equipment_table2
--create a EquipmentData with what we have
+
if eq and eq._module then
local eq = U.ifindBy(require('Module:Collection/Equipment'), function (e) return e._name == name or e.__name == name end)
+
success2, equipment_table2 = U.requireModule(eq._module)
if eq and eq.__name then
  −
    eq._name = eq.__name
  −
end
  −
equipment_table = eq or { _name = name }
   
end
 
end
local equipment = EquipmentData(equipment_table)
+
equipment_table = success2 and equipment_table2 or eq or { _name = name }
equipments[name] = equipment
  −
return equipment
   
end
 
end
 +
local equipment = EquipmentData(equipment_table)
 +
equipments[name] = equipment
 +
return equipment
 +
end
 +
 +
function Equipment:get(stat, name)
 +
return self:create(name)[stat]()
 
end
 
end
    
function Equipment:get_module(name)
 
function Equipment:get_module(name)
if name == nil then
+
return name and mw.ustring.format('Module:%s', name) or nil
return nil
  −
end
  −
return mw.ustring.format('Module:%s', name)
   
end
 
end
  
cssedit, gkautomate
7,064

edits

Navigation menu