Module:Crafting: Difference between revisions

From Official Gamemode 4 Wiki
Jump to navigation Jump to search
(Better inlining that actually works)
m (check if lore/name is nil before checking length)
(27 intermediate revisions by 3 users not shown)
Line 5: Line 5:
end
end


-- Make a 3*3 crafting grid
function p.Grid( f )
function p.Grid( f )
local args = f.args
local args = f.args
Line 11: Line 12:
end
end


return Grid(args, 3, 3)
return Grid(args, args['width'] or args['Width'] or 3, args['height'] or args['Height'] or 3)
end
end


-- Make a 1*1 crafting grid
function p.Cell( f )
function p.Cell( f )
local args = f.args
local args = f.args
Line 23: Line 25:
end
end


-- make a 1*5 crafting grid
function p.Hopper( f )
function p.Hopper( f )
local args = f.args
local args = f.args
Line 32: Line 35:
end
end


-- Make a catalyst
function p.Catalyst( f )
function p.Catalyst( f )
local args = f.args
local args = f.args
Line 37: Line 41:
args = f:getParent().args or {""}
args = f:getParent().args or {""}
end
end
return require([[Module:Sprite]])
local d = require([[Module:InventorySlot]]).Decode(args[1])
:new("inventory")
if not(d) then error(d) end
:setItem(mw.text.trim(args[1]))
return d:SetSize(16)
:SetSize(16)
:GenerateHTML()
:GenerateHTML()
:addClass( "catalyst" )
:addClass( "catalyst" )
end
end


-- Make an item
function p.Item( f )
function p.Item( f )
local args = f.args
local args = f.args
Line 51: Line 55:
end
end


local tagtype
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


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()
if args['inline'] or args['Inline'] then


    local name = args['name'] or args['Name'] or args['title'] or args['Title']
    if name and #name ~= 0 then
        sprite:SetTitle(name)
    end
    local lore = args['lore'] or args['Lore'] or args['text'] or args['Text']
    if lore and #lore ~= 0 then
        sprite:SetLore(lore)
    end
local hideTooltip = args['hideToolTip'] or args['hideTooltip'] or args['HideToolTip'] or args['HideTooltip']
if hideTooltip then
sprite:HideTooltip()
end
local inline = args['inline'] or args['Inline']
local spriteDiv
if inline ~= 'false' then
spriteDiv = sprite:GenerateHTML("span")
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
local count = tonumber(args['count']) or tonumber(args['Count']) or 1 or '?'
if count ~= 1 then
local countSpan = spriteDiv:tag("span"):wikitext(count)
countSpan:addClass("invslot-stacksize")
end
return spriteDiv
end
-- Make a single item
function p.SingleItem( 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 name = args['name'] or args['Name'] or args['title'] or args['Title']
    if name and #name ~= 0 then
        sprite:SetTitle(name)
    end
    local lore = args['lore'] or args['Lore'] or args['text'] or args['Text']
    if lore and #lore ~= 0 then
        sprite:SetLore(lore)
    end
local hideTooltip = args['hideToolTip'] or args['hideTooltip'] or args['HideToolTip'] or args['HideTooltip']
if hideTooltip then
sprite:HideTooltip()
end
local inline = args['inline'] or args['Inline']
local spriteDiv
spriteDiv = sprite:GenerateHTML("span")
spriteDiv:css("display","inline-block")
spriteDiv:css("vertical-align","middle")
spriteDiv:css("border-width","3px")
spriteDiv:css("border-style","solid")
if args['standard'] or args['Standard'] then
spriteDiv:css("background-color","#8B8B8B")
spriteDiv:css("border-color","#373737 #FFFFFF #FFFFFF #373737")
else
spriteDiv:css("background-color","#67AFD0")
spriteDiv:css("border-color","#1A536E #C0DEEB #C0DEEB #1A536E")
end
end






local count = tonumber(args['count']) or tonumber(args['Count']) or 1
local count = tonumber(args['count']) or tonumber(args['Count']) or 1 or "?"
if count ~= 1 then
if count ~= 1 then
local countSpan = spriteDiv:tag("span"):wikitext(count)
local countSpan = spriteDiv:tag("span"):wikitext(count)

Revision as of 23:40, 16 August 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, args['width'] or args['Width'] or 3, args['height'] or args['Height'] or 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 name = args['name'] or args['Name'] or args['title'] or args['Title']
    if name and #name ~= 0 then
        sprite:SetTitle(name)
    end

    local lore = args['lore'] or args['Lore'] or args['text'] or args['Text']
    if lore and #lore ~= 0 then
        sprite:SetLore(lore)
    end

	local hideTooltip = args['hideToolTip'] or args['hideTooltip'] or args['HideToolTip'] or args['HideTooltip']
	if hideTooltip then
		sprite:HideTooltip()
	end

	local inline = args['inline'] or args['Inline']
	local spriteDiv
	if inline ~= 'false' 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 or '?'
	if count ~= 1 then
		local countSpan = spriteDiv:tag("span"):wikitext(count)
		countSpan:addClass("invslot-stacksize")
	end

	return spriteDiv
end

-- Make a single item
function p.SingleItem( 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 name = args['name'] or args['Name'] or args['title'] or args['Title']
    if name and #name ~= 0 then
        sprite:SetTitle(name)
    end

    local lore = args['lore'] or args['Lore'] or args['text'] or args['Text']
    if lore and #lore ~= 0 then
        sprite:SetLore(lore)
    end

	local hideTooltip = args['hideToolTip'] or args['hideTooltip'] or args['HideToolTip'] or args['HideTooltip']
	if hideTooltip then
		sprite:HideTooltip()
	end

	local inline = args['inline'] or args['Inline']
	local spriteDiv
	spriteDiv = sprite:GenerateHTML("span")
	spriteDiv:css("display","inline-block")
	spriteDiv:css("vertical-align","middle")
	spriteDiv:css("border-width","3px")
	spriteDiv:css("border-style","solid")

	if args['standard'] or args['Standard'] then
		spriteDiv:css("background-color","#8B8B8B")
		spriteDiv:css("border-color","#373737 #FFFFFF #FFFFFF #373737")
	else
		spriteDiv:css("background-color","#67AFD0")
		spriteDiv:css("border-color","#1A536E #C0DEEB #C0DEEB #1A536E")
	end



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

	return spriteDiv
end

return p