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

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
 
(5 intermediate revisions by 3 users not shown)
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('Data/ShipClass/' .. name)
 +
  if not success then
 +
    success, data = U.requireModule('Data/Ship/' .. name)
 +
  end
 +
  if not success or not data.class then
 +
    data = {class = {_name = name, _class = true}}
 +
  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
local ship_class = ship_classes[name]
+
  if not ship_classes[name] then
if ship_class then
+
    ship_classes[name] = ShipClassData(requireShipClassModule(name))
return ship_class
+
  end
else
+
  return ship_classes[name]
local ship_class_table = require(mw.ustring.format('Module:%s', name))
 
ship_class = ShipClassData(ship_class_table.class)
 
ship_classes[name] = ship_class
 
return ship_class
 
end
 
 
end
 
end
  

Latest revision as of 19:50, 10 September 2022

Documentation for this module may be created at Module:ShipClass/doc

local U = require('Module:Core')
local ShipClassData = require('Module:ShipClassData')

local ShipClass = {}

local ship_classes = {}

local function requireShipClassModule(name)
  local success, data = U.requireModule('Data/ShipClass/' .. name)
  if not success then
    success, data = U.requireModule('Data/Ship/' .. name)
  end
  if not success or not data.class then
    data = {class = {_name = name, _class = true}}
  end
  return data.class
end

function ShipClass:create(name)
  if not name then
    return ShipClassData()
  end
  if not ship_classes[name] then
    ship_classes[name] = ShipClassData(requireShipClassModule(name))
  end
  return ship_classes[name]
end

ShipClass.__call = ShipClass.create
setmetatable(ShipClass, ShipClass)

return ShipClass