Module:InventorySlot

Revision as of 13:33, 8 November 2018 by Kroppeb (talk | contribs) (v 0.1)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
-- 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:GenerateHTML ()
	local slot = mw.html.create( 'div' ):addClass( 'invslot-item' )
	if self.__sprite then
		self.__sprite:GenerateHTML(slot)
	end
	return slot
end

return UISlot