Module:ItemData: Difference between revisionsGive feedback
split up get type function |
add more comments, fix comments, add headcount |
||
| Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
local data = mw.loadJsonData("Data:ItemData.json") | local data = mw.loadJsonData("Data:ItemData.json") | ||
---------------------------------------- Utility functions | |||
-- Returns the table of a specific item | -- Returns the table of a specific item | ||
-- @function get_json_item | |||
-- @param {string} | |||
-- @return {table} | |||
local function get_json_item(name) | local function get_json_item(name) | ||
for _, v in pairs(data) do | for _, v in pairs(data) do | ||
| Line 10: | Line 15: | ||
end | end | ||
return nil | return nil | ||
end | |||
-- Returns an array of item tables that have the same properties | |||
-- @function get_similar_items | |||
-- @param {string} | |||
-- @return {array of tables} | |||
local function get_similar_items(property) | |||
local similarItems = {} | |||
for _, v in pairs(data) do | |||
if (v[property] ~= nil) then | |||
table.insert(similarItems, v) | |||
end | |||
end | |||
return similarItems | |||
end | end | ||
| Line 43: | Line 62: | ||
-- @function get_type | -- @function get_type | ||
-- @param {string} | -- @param {string} | ||
-- @return { | -- @return {string} | ||
local function get_type(item_name) | local function get_type(item_name) | ||
local item = get_json_item(item_name) | local item = get_json_item(item_name) | ||
| Line 130: | Line 149: | ||
return component['Name'] | return component['Name'] | ||
end | |||
function p.get_headcount(frame) | |||
local iter = 0 | |||
local propertyName = frame.args[1] | |||
local tbl = get_similar_items(propertyName) | |||
for k, v in ipairs(tbl) do | |||
iter = iter + 1 | |||
k = k + 1 | |||
end | |||
return iter, k --double check this and see if iter is necessary; k just may be all i need | |||
end | end | ||
return p | return p | ||