Modul:Iteminfo/idSets

Aus Terraria Wiki
Wechseln zu: Navigation, Suche
Siehe auch die englische Modulseite: Module:Iteminfo/idSets. Sie enthält möglicherweise umfassendere oder aktuellere Informationen.

Für dieses Modul gibt es noch keine Dokumentations-Unterseite. documentation/preload Erstelle jetzt eine.


local data = mw.loadData( 'Module:iteminfo/idSets/data' ) -- loading data

local trim = mw.text.trim
-- cache
local currentFrame
local getArg = function(key)
	local value = currentFrame.args[key]
	if not value then
		return nil
	end
	value = trim(value)
	if value == '' then
		return nil
	else
		return value
	end
end

local function get(setname, itemid)
	if not data[setname] then
		return nil
	end

	if data[setname][itemid] == nil then
		return data[setname]['default']
	else
		return data[setname][itemid]
	end
end


return {
	-- {{#invoke:Iteminfo/idSets|getAllNames}} returns all valid set sets, seperated by comma.
	-- also can be called by other module:  require('Module:Iteminfo/idSets').getAllNames()
	getAllNames = function()
		local str
		for name,_ in pairs(data) do
			if str then
				str = str .. ', ' .. name
			else
				str = name
			end
		end
		return str
	end,

	-- {{#invoke:Iteminfo/idSets|value|<setname>|<itemid>}} returns the value for this item in that set.
	-- return value may be:
	--     ""(Empty string): setname is invaild.
	--     "nil": only for nullable sets.
	--     "true" / "false": for bool values.
	--     other number string: int or float values.
	value = function(frame)
		currentFrame = frame -- cache
		local setname = getArg(1)
		local itemid = tonumber(getArg(2)) or 0
		return get(setname, itemid)
	end,

	-- for module.
	getValue = function(setname, itemid)
		itemid = tonumber(itemid) or 0
		return get(setname, itemid)
	end,

	-- for template
	getSet = function(frame)
		currentFrame = frame -- cache
		local setname = getArg(1)
		if not data[setname] then
			return
		end
		local str
		for k,v in data[setname] do
			if str then 
				str = str .. ', ' .. k
			else
				str = k
			end
		end
		return str
	end,

	-- for module.
	getIdSet = function(setname)
		if not data[setname] then
			return nil
		end
		return data[setname] --readonly?
	end,

}