Difference between revisions of "Module:Item"

From Idlescape Wiki
Jump to navigation Jump to search
(test)
 
m
 
(6 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
local loaded_data_modules = {}
 
local loaded_data_modules = {}
  
function p.loadItem (name, data_type)  
+
function p.loadItem (name, parameter, data_type)  
 
local module_name = data_module_names[data_type]
 
local module_name = data_module_names[data_type]
 
if loaded_data_modules[module_name] == nil then
 
if loaded_data_modules[module_name] == nil then
Line 12: Line 12:
 
end
 
end
 
 
for key, item in loaded_data_modules[module_name] do
+
for key, item in pairs(loaded_data_modules[module_name]) do
 
if name == item["name"] then
 
if name == item["name"] then
return item["id"]
+
return item[parameter]
 
end
 
end
 
end
 
end
Line 32: Line 32:
 
function p._item(args)
 
function p._item(args)
 
local name = args[1]
 
local name = args[1]
local id = 0
+
local parameter = args[2]
 +
local result = 0
 
 
id = p.loadItem (name, 'itemData')
+
result = p.loadItem (name, parameter, 'itemData')
id = tonumber(price)
 
 
 
return id
+
return result
 
end
 
end
  
 
return p
 
return p

Latest revision as of 10:02, 11 September 2023


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