Module:NecesseItems

From Necesse Wiki
Jump to navigation Jump to search

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

local p = {}

local itemsData = require("Module:NecesseCache").loadItems()

function p.getItemData(frame)
	local itemStringID = frame.args['stringID'] or frame.args[1]
	if itemStringID then 
		local itemData = itemsData[itemStringID];
		if not itemData then
			-- Try to search the item using its name
			local itemStringIDFromName = itemsData['stringIDs'][string.lower(itemStringID)]
			if itemStringIDFromName then
				itemData = itemsData[itemStringIDFromName]
			end
		end
		if itemData then
			local dataQuery = frame.args['value'] or frame.args[2]
			if dataQuery then
				local defaultValue = frame.args['default'] or frame.args[3]
				return itemData[dataQuery] or defaultValue
			end
			return itemsData
		end
		return 'COULD NOT FIND ITEM WITH stringID "' .. itemStringID .. '"'
	end
	return 'MISSING ITEM "stringID" PARAMETER'
end

function p.getItemStringID(frame)
	local itemName = frame.args['name'] or frame.args[1]
	if itemName then
		local stringIDsData = itemsData['stringIDs'];

		local defaultValue = frame.args['default'] or frame.args[2]
		return stringIDsData[string.lower(itemName)] or defaultValue
	end
	return 'MISSING ITEM "name" PARAMETER'
end

return p