Module:AttributeData: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
m get_attr_category for restructured attribute data
Sur (talk | contribs)
m get_category_data() -> p.get_data_data()
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {};
local p = {};
local data = mw.loadJsonData("Data:AttributeData.json")
local attributes_data = mw.loadJsonData("Data:AttributeData.json")
local category_data = { --category specific parameters
["Weapon"] = {
unlocalized_name = "CitadelCategoryWeapon",
rgb = "213, 144, 63"
},
["Vitality"] = {
unlocalized_name = "CitadelCategoryArmor",
rgb = "116, 176, 28"
},
["Spirit"] = {
unlocalized_name = "CitadelCategoryTech",
rgb = "194, 136, 240"
},
}
function p.get_category_data()
return category_data
end


-- returns the table of a specific item
-- returns the table of a specific item
function get_json_item(name)
function get_json_item(name)
for i,v in pairs(data) do
for i,v in pairs(attributes_data) do
if (i == name) then
if (i == name) then
return v
return v
Line 12: Line 30:
end
end


function isElementInArray(array, element)
    for _, value in ipairs(array) do
        if value == element then
            return true
        end
    end
    return false
end




--{{#invoke:AttributeData|get_attr_category|ATTR_NAME}}--
 
p.get_attr_category = function(frame)
 
local attr_name = frame.args[1]
 
for category, attributes in pairs(data) do
if isElementInArray(attributes, attr_name) then
return category
end
end
return nil
end


return p
return p

Revision as of 03:28, 19 September 2024

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

local p = {};
local attributes_data = mw.loadJsonData("Data:AttributeData.json")
local category_data = { --category specific parameters
	["Weapon"] = {
		unlocalized_name = "CitadelCategoryWeapon",
		rgb = "213, 144, 63"
	},
	["Vitality"] = {
		unlocalized_name = "CitadelCategoryArmor",
		rgb = "116, 176, 28"
	},
	["Spirit"] = {
		unlocalized_name = "CitadelCategoryTech",
		rgb = "194, 136, 240"
	},
}
	
function p.get_category_data()
	return category_data
end

-- returns the table of a specific item
function get_json_item(name)
	for i,v in pairs(attributes_data) do
		if (i == name) then
			return v
		end
	end
	return nil
end







return p