Difference between revisions of "Module:Crafting"

From Gamemode 4
Jump to navigation Jump to search
(the issue is in another caste)
(oof)
Line 42: Line 42:
 
end
 
end
 
local d = require([[Module:InventorySlot]]).Decode(args[1])
 
local d = require([[Module:InventorySlot]]).Decode(args[1])
 +
if not(d) then error(d) end
 
return d:SetSize(16)
 
return d:SetSize(16)
:GenerateHTML()
+
:GenerateHTML()
:addClass( "catalyst" )
+
:addClass( "catalyst" )
 
end
 
end
  
Line 55: Line 56:
  
 
local sprite
 
local sprite
 +
local image = args['image'] or args['Image']
  
 
if image then
 
if image then
  
 
local Sprite = require([[Module:Sprite]])
 
local Sprite = require([[Module:Sprite]])
local image = args['image'] or args['Image']
 
 
sprite = Sprite.Custom:new(args[1], image)
 
sprite = Sprite.Custom:new(args[1], image)
  

Revision as of 11:29, 1 May 2020

p = {}

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

-- Make a 3*3 crafting grid
function p.Grid( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args
	end

	return Grid(args, 3, 3)
end

-- Make a 1*1 crafting grid
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

-- make a 1*5 crafting grid
function p.Hopper( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args
	end

	return Grid(args, 5, 1)
end

-- Make a catalyst
function p.Catalyst( f )
	local args = f.args
	if #args == 0 then
		args = f:getParent().args or {""}
	end
	local d = require([[Module:InventorySlot]]).Decode(args[1])
	if not(d) then error(d) end
	return d:SetSize(16)
			:GenerateHTML()
			:addClass( "catalyst" )
end

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

	local sprite
	local image = args['image'] or args['Image']

	if image then

		local Sprite = require([[Module:Sprite]])
		sprite = Sprite.Custom:new(args[1], image)

	else
		local spriteSheet = args['spriteSheet'] or
		 					args['SpriteSheet']
		if spriteSheet then
			sprite = Sprite
						:new(spriteSheet)
						:setItem(mw.text.trim(args[1] or ""))
		else
			sprite = require([[Module:InventorySlot]]).Decode(args[1])
		end

	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("span")
		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