Module:Crafting: Difference between revisions

From Official Gamemode 4 Wiki
Jump to navigation Jump to search
(Better inlining that actually works)
No edit summary
Line 51: Line 51:
end
end


local tagtype
local Sprite = require([[Module:Sprite]])
local sprite
local image = args['image'] or args['Image']
 
if image then
sprite = Sprite.Custom:new(args[1], image)
else
local spriteSheet = args['spriteSheet'] or
args['SpriteSheet'] or
"inventory"
sprite = Sprite
:new(spriteSheet)
:setItem(mw.text.trim(args[1] or ""))
end


local sprite = require([[Module:Sprite]])
:new("inventory")
:setItem(mw.text.trim(args[1] or ""))


if args['small'] or args['Small'] then
if args['small'] or args['Small'] then
sprite:SetSize(16)
sprite:SetSize(16)
else
sprite:SetSize(args['size'] or args['Size'] or 32)
end
end


local spriteDiv = sprite:GenerateHTML()
local inline = args['inline'] or args['Inline']
if args['inline'] or args['Inline'] then
local spriteDiv
 
if inline then
spriteDiv = sprite:GenerateHTML("css")
spriteDiv:css("display","inline-block")
spriteDiv:css("display","inline-block")
spriteDiv:css("vertical-align","middle")
spriteDiv:css("vertical-align","middle")
else
spriteDiv = sprite:GenerateHTML()
end
end



Revision as of 17:01, 2 July 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 Sprite = require([[Module:Sprite]])
	local sprite
	local image = args['image'] or args['Image']

	if image then
		sprite = Sprite.Custom:new(args[1], image)
	else
		local spriteSheet = args['spriteSheet'] or
		 					args['SpriteSheet'] or
							"inventory"
		sprite = Sprite
					:new(spriteSheet)
					:setItem(mw.text.trim(args[1] or ""))
	end


	if args['small'] or args['Small'] then
		sprite:SetSize(16)
	else
		sprite:SetSize(args['size'] or args['Size'] or 32)
	end

	local inline = args['inline'] or args['Inline']
	local spriteDiv
	if inline then
		spriteDiv = sprite:GenerateHTML("css")
		spriteDiv:css("display","inline-block")
		spriteDiv:css("vertical-align","middle")
	else
		spriteDiv = sprite:GenerateHTML()
	end



	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