Module:InventorySlot

Revision as of 14:01, 8 November 2018 by Kroppeb (talk | contribs) (Off by one)
-- Based on work by the MC wiki: https://minecraft.gamepedia.com/

local UISlot = {}

local Sprite = require([[Module:Sprite]]):new("inventory")

function UISlot:new(item)
	o = {}
	setmetatable(o, {__index = self})
	o:SetItem(item)
	return o
end

function UISlot:SetItem(item)
	self.__sprite = item and Sprite:Item(item) --nil if item = nil else get sprite
	return self
end

function UISlot.Item(item)
	return UISlot:new(item):GenerateHTML()
end

function UISlot.Call(frame)
	return UISlot.Item(frame.args[1] or frame.args.item)
end

function UISlot:GenerateHTML ()
	local slot = mw.html.create( 'div' ):addClass( 'invslot-item' )
	if self.__sprite then
		self.__sprite:GenerateHTML(slot)
	end
	return slot
end

return UISlot