Module:Accessory

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

local p = {}
local data = mw.loadData("Module:Data/Accessories")
local dataArmor = mw.loadData("Module:Data/Armor")
local dataSet = mw.loadData("Module:Data/Set items")

function p.createInfobox(frame)
	local accessory = data[frame.args.name]
	local setItems = {}
	local setEffects = {}
	local effects = {}
	
	if accessory.partOfSetItems ~= nil then
		for k, v in ipairs(dataSet[accessory.partOfSetItems].availablePieces) do
			local setItemName = dataArmor[v] ~= nil and dataArmor[v].name or data[v].name
			table.insert(setItems, setItemName)
		end
		for k, v in ipairs(dataSet[accessory.partOfSetItems].setBonusDatas) do
			table.insert(setEffects, v.requiredPieces .. ' set: ' .. v.condition)
		end
	end
	
	for k, v in ipairs(accessory.givesConditionsWhenEquipped) do
		table.insert(effects, v)
	end

	if accessory.mechanicDescription ~= nil then
		table.insert(effects, accessory.mechanicDescription)
	end
	
	local str = { 
		type = 'Accessory',
		slot = accessory.type,
		rarity = accessory.rarity,
		effects = table.concat(effects, '<br>'),
		seteffects = table.concat(setEffects, '<br>'),
		setitems = table.concat(setItems, ', '),
		description = accessory.description
	}
	
	return frame:expandTemplate{title = 'Item infobox', args = str}
end

return p