Module:InventorySlot: Difference between revisions

From Official Gamemode 4 Wiki
Jump to navigation Jump to search
(v 0.1)
 
No edit summary
Line 19: Line 19:
function UISlot.Item(item)
function UISlot.Item(item)
return UISlot:new(item):GenerateHTML()
return UISlot:new(item):GenerateHTML()
end
function UISlot.Call(frame)
return UISlot.Item(frame.args[0] or frame.args.item)
end
end



Revision as of 13:35, 8 November 2018

-- 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[0] 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