Module:Crafting: Difference between revisions

From Official Gamemode 4 Wiki
Jump to navigation Jump to search
(Add the ability to get an inlineable item with count)
(Add inline support by `{{Stack|...|inline = True}}`)
Line 50: Line 50:
args = f:getParent().args or {""}
args = f:getParent().args or {""}
end
end
local tagtype
local inline = args['inline'] or args['Inline']
if inline then
tagtype = "span"
end
local spriteDiv = require([[Module:Sprite]])
local spriteDiv = require([[Module:Sprite]])
:new("inventory")
:new("inventory")
:setItem(mw.text.trim(args[1]))
:setItem(mw.text.trim(args[1] or ""))
:GenerateHTML()
:GenerateHTML(nil, tagtype)





Revision as of 19:09, 4 April 2019

p = {}

function Grid(args, w, h, large)
	return require([[Module:InventorySlot]]).Call(args,w,h,large)
end

function p.Grid( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args
	end

	return Grid(args, 3, 3)
end

function p.Cell( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args
	end

	return Grid(args, 1, 1, args.Large)
end

function p.Hopper( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args
	end

	return Grid(args, 5, 1)
end

function p.Catalyst( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args or {""}
	end
	return require([[Module:Sprite]])
		:new("inventory")
		:setItem(mw.text.trim(args[1]))
		:SetSize(16)
		:GenerateHTML()
		:addClass( "catalyst" )
end

function p.Item( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args or {""}
	end

	local tagtype
	local inline = args['inline'] or args['Inline']

	if inline then
		tagtype = "span"
	end

	local spriteDiv = require([[Module:Sprite]])
		:new("inventory")
		:setItem(mw.text.trim(args[1] or ""))
		:GenerateHTML(nil, tagtype)


	local count = tonumber(args['count']) or tonumber(args['Count']) or 1
	if count ~= 1 then
		local countSpan = spriteDiv:tag("span"):wikitext(count)
		countSpan:addClass("invslot-stacksize")
	end

	return spriteDiv
end

return p