Module:Item

From Idlescape Wiki
Jump to navigation Jump to search

local p = {}

local data_module_names = {
	itemData = 'Module:Items/data'
}
local loaded_data_modules = {}

function p.loadItem (name, parameter, data_type) 
	local module_name = data_module_names[data_type]
	if loaded_data_modules[module_name] == nil then
		loaded_data_modules[module_name] = mw.loadData(module_name)
	end
	
	for key, item in pairs(loaded_data_modules[module_name]) do
		if name == item["name"] then
			return item[parameter]
		end
	end
	
	return loaded_data_modules[module_name][item]
end

function p.addSeparator(num)
	return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end

function p.item(frame)
	local args = frame:getParent().args
	return p._item(args)
end

function p._item(args)
	local name = args[1]
	local parameter = args[2]
	local result = 0
			
	result = p.loadItem (name, parameter, 'itemData')
	
	return result
end

return p