Changes

no edit summary
Line 1: Line 1:  +
local U = require('Module:Core')
 +
local ShipClassData = require('Module:ShipClassData')
 +
 
local ShipClass = {}
 
local ShipClass = {}
 +
 
local ship_classes = {}
 
local ship_classes = {}
   −
local ShipClassData = require('Module:ShipClassData')
+
local function requireShipClassModule(name)
 +
  local success, data = U.requireModule(name)
 +
  if not success then
 +
    success, data = U.requireModule('Data/ShipClass/' .. name)
 +
  end
 +
  if not success or not data.class then
 +
    data = {class = {_name = name}}
 +
  end
 +
  return data.class
 +
end
    
function ShipClass:create(name)
 
function ShipClass:create(name)
if model == nil then
+
  if not name then
model = ""
+
    return ShipClassData()
end
+
  end
--check if we already have it
+
  if not ship_classes[name] then
local ship_class = ship_classes[name]
+
    ship_classes[name] = ShipClassData(requireShipClassModule(name))
if ship_class then
+
  end
return ship_class
+
  return ship_classes[name]
else
  −
--Catch a failed require
  −
local success, ship_class_table = pcall(function () return require(mw.ustring.format('Module:%s', name)) end)
  −
--require failed
  −
if success then
  −
ship_class_table = ship_class_table.class
  −
if not ship_class_table then
  −
--create a ShipClassData with what we have
  −
ship_class_table = {_name = name}
  −
end
  −
else
  −
--create a ShipClassData with what we have
  −
ship_class_table = {_name = name}
  −
end
  −
ship_class = ShipClassData(ship_class_table)
  −
ship_classes[name] = ship_class
  −
return ship_class
  −
end
   
end
 
end
  
cssedit, gkautomate
7,064

edits