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

From Kancolle Wiki
Jump to navigation Jump to search
m
m (13 revisions imported)
 
(4 intermediate revisions by one other user not shown)
Line 5: Line 5:
  
 
function ShipClassData:base_name()
 
function ShipClassData:base_name()
 +
return type(self._name) == 'table' and self._name._name or self._name
 +
end
 +
 +
function ShipClassData:base_name_test()
 
return self._name
 
return self._name
 
end
 
end
Line 26: Line 30:
 
function ShipClassData:name_override()
 
function ShipClassData:name_override()
 
local result = {}
 
local result = {}
local errors = {}
 
 
if self._prefix then
 
if self._prefix then
    if type(self._prefix) == 'string' then
+
table.insert(result, self._prefix)
    table.insert(result, self._prefix)
+
end
else
+
if self._name_override or self:base_name() then
    table.insert(errors, '_prefix ' .. type(self._prefix))
+
    table.insert(result, self._name_override or self:base_name())
end
 
    end
 
    local name = self._name_override or self:base_name()
 
if name then
 
    if type(name) == 'string' then
 
        table.insert(result, name)
 
        else
 
            table.insert(errors, '_name_override ' .. type(self._name_override) .. ', base_name ' .. type(self:base_name()))
 
            local s = ''
 
            if type(self:base_name()) == 'table' then
 
                for k, v in pairs(self:base_name()) do
 
                    s = s .. '; ' .. k
 
                end
 
                table.insert(errors, s)
 
            end
 
        end
 
 
end
 
end
 
if self._suffix then
 
if self._suffix then
    if type(self._suffix) == 'string' then
+
table.insert(result, self._suffix)
    table.insert(result, self._suffix)
 
else
 
    table.insert(errors, '_suffix ' .. type(self._suffix))
 
end
 
 
end
 
end
return table.concat(result, " "), table.concat(errors, ", ")
+
return table.concat(result, " ")
 
end
 
end
  

Latest revision as of 12:26, 12 May 2021

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

local BaseData = require("Module:BaseData")
local ShipClassData = BaseData{
	_class_suffix = "Class",
}

function ShipClassData:base_name()
	return type(self._name) == 'table' and self._name._name or self._name
end

function ShipClassData:base_name_test()
	return self._name
end

function ShipClassData:short_base_name()
	return self._short_name or self:base_name()
end

function ShipClassData:name()
	local result = {}
	if self._prefix then
		table.insert(result, self._prefix)
	end
	table.insert(result, self:base_name())
	if self._suffix then
		table.insert(result, self._suffix)
	end
	return table.concat(result, " ")
end

function ShipClassData:name_override()
	local result = {}
	if self._prefix then
		table.insert(result, self._prefix)
	end
	if self._name_override or self:base_name() then
	    table.insert(result, self._name_override or self:base_name())
	end
	if self._suffix then
		table.insert(result, self._suffix)
	end
	return table.concat(result, " ")
end

function ShipClassData:short_name()
	local result = {}
	if self._prefix then
		table.insert(result, self._prefix)
	end
	table.insert(result, self:short_base_name())
	if self._suffix then
		table.insert(result, self._suffix)
	end
	return table.concat(result, " ")
end

function ShipClassData:is_type()
	return self._is_type
end

function ShipClassData:base_type()
	return self._base_type
end

function ShipClassData:create(class)
	class = class or {}
	if class._class and not class._suffix then
		class._suffix = self._class_suffix
	end
	setmetatable(class, class)
	class.__index = self
	return class
end

ShipClassData.__call = ShipClassData.create

return ShipClassData