Jump to content

Module:Inventory slot: Difference between revisions

m
no edit summary
imported>Ttv pedro270707
m (Added padding to remove empty space between items and removed page existence check)
imported>Ttv pedro270707
mNo edit summary
 
(23 intermediate revisions by the same user not shown)
Line 49: Line 49:
local slotContainer = mw.html.create( "div" )
local slotContainer = mw.html.create( "div" )
slotContainer:addClass( "inventory-slot" )
slotContainer:addClass( "inventory-slot" )
:addClass( "animated" )
:cssText( table.concat( slotContainerCss, ";" ) )
:cssText( table.concat( slotContainerCss, ";" ) )
Line 65: Line 66:
for j, subvalue in ipairs(aliases[item]) do
for j, subvalue in ipairs(aliases[item]) do
local display = i == j == 1 and "display: inline-block" or "display: none" -- sets display of the first element to `inline-block` and the rest to `none`
local display = i == j == 1 and "display: inline-block" or "display: none" -- sets display of the first element to `inline-block` and the rest to `none`
-- Set name, item and description
local subname = nil
local subname = nil
local subitem = nil
local subitem = nil
local sublink = nil
local subdescription = nil
if type(subvalue) == "string" then
if type(subvalue) == "string" then
subname = subvalue
subname = subvalue
subitem = subvalue
subitem = subvalue
subdescription = subvalue
else
else
subname = subvalue.name or subvalue.item
subname = subvalue.name or subvalue.item
subitem = subvalue.item
subitem = subvalue.item
subdescription = subvalue.description or subvalue.item
end
end
local link = nil
local slot = mw.html.create( "div" )
local slot = mw.html.create( "div" )
Line 81: Line 85:
:cssText( table.concat( slotCss, ";" ) )
:cssText( table.concat( slotCss, ";" ) )
:attr( "data-mctitle", (name or subname or subitem) )
:attr( "data-mctitle", (name or subname or subitem) )
if descriptions[subdescription] or descriptions[subitem] or descriptions[subname] then
if descriptions[subitem] or descriptions[subname] then
slot:attr( "data-mcdesc", p.formatDescription((descriptions[subdescription] or descriptions[subitem] or descriptions[subname]), 16) )
slot:attr( "data-mcdesc", p.formatDescription((descriptions[subitem] or descriptions[subname]), 16) )
end
end
if not subitem:match( '\.gif$' ) and not subitem:match( '\.png$' ) then
if not subitem:match( '\.gif$' ) and not subitem:match( '\.png$' ) then
slot:wikitext( sprite( { data = "InvSprite", id = subvalue } ) )
slot:wikitext( sprite( { data = "InvSprite", id = subitem } ) )
end
end
-- Set link
local link = nil
if args.link and args.link ~= "y" then
if args.link and args.link ~= "y" then
if args.link ~= "n" then
if args.link ~= "n" then
Line 98: Line 102:
end
end
-- Set the item count
if count then
if count then
local itemCount = mw.html.create( "span" )
local itemCount = mw.html.create( "span" )
itemCount:cssText( "position: absolute; right: -2px; bottom: -5px; pointer-events: none;" )
itemCount:cssText( "position: absolute; right: 0; bottom: -2px; pointer-events: none;" )
:addClass( "c-0" )
:addClass( "c-0" )
:addClass( "shadow" )
:addClass( "shadow" )
Line 108: Line 113:
end
end
-- Use an image if the item ends in .gif or .png
if subitem:match( '\.gif$' ) or subitem:match( '\.png$' ) then
if subitem:match( '\.gif$' ) or subitem:match( '\.png$' ) then
if link then
slot:wikitext( "<span class=\"sprite pixelated\" style=\"width: 32px; height: 32px;\">[[File:" .. subitem .. "|160px|link=" .. (link or "") .. "]]</span>" )
slot:wikitext( "<span class=\"sprite pixelated\">[[" .. subitem .. "|160px|link=" .. link .. "]]</span>" )
else
slot:wikitext( "<span class=\"sprite pixelated\">[[File:" .. subitem .. "|160px|link=]]</span>" )
end
slotContainer:wikitext( tostring( slot ) )
slotContainer:wikitext( tostring( slot ) )
else
else
if link then
if link then
slotContainer:wikitext( "<span style='" .. display .. "'>" .. "[[" .. link .. "|" .. tostring( slot ) .. "]]" .. "</span>" )
slotContainer:wikitext( "<span style='" .. display .. "' class='no-external-icon'>" .. "[https://bta.miraheze.org/wiki/" .. link:gsub(" ", "_") .. " " .. tostring( slot ) .. "]" .. "</span>" )
else
else
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
Line 125: Line 127:
else
else
local display = i == 1 and "display: inline-block" or "display: none"
local display = i == 1 and "display: inline-block" or "display: none"
local link = nil
local slot = mw.html.create( "div" )
if item ~= 'Air' then
slot:addClass( "minecraft-item" )
local slot = mw.html.create( "div" )
:cssText( table.concat( slotCss, ";" ) )
slot:addClass( "minecraft-item" )
:attr( "data-mctitle", (name or item) )
:cssText( table.concat( slotCss, ";" ) )
:attr( "data-mctitle", (name or item) )
if descriptions[item] then
slot:attr( "data-mcdesc", p.formatDescription(descriptions[item], 16) )
end
slot:wikitext( sprite( { data = "InvSprite", id = item } ) )
local link = nil
if args.link and args.link ~= "y" then
if args.link ~= "n" then
link = args.link
end
elseif (require("Module:Inventory slot/links").links[item] ~= pageName and item) or args.link == "y" then
link = require("Module:Inventory slot/links").links[item]
end
if count then
local itemCount = mw.html.create( "span" )
itemCount:cssText( "position: absolute; right: 0; bottom: -2px; pointer-events: none;" )
:addClass( "c-0" )
:addClass( "shadow" )
:wikitext( count )
slot:node( itemCount )
end
if descriptions[item] then
if link or (args.link and args.link ~= "y" and args.link ~= "n") then
slot:attr( "data-mcdesc", p.formatDescription(descriptions[item], 16) )
slotContainer:wikitext( "<span style='" .. display .. "' class='no-external-icon'>" .. "[https://bta.miraheze.org/wiki/" .. link:gsub(" ", "_") .. " " .. tostring( slot ) .. "]" .. "</span>" )
end
else
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
slot:wikitext( sprite( { data = "InvSprite", id = item } ) )
if args.link and args.link ~= "y" then
if args.link ~= "n" then
link = args.link
end
end
elseif (require("Module:Inventory slot/links").links[item] ~= pageName and item) or args.link == "y" then
link = require("Module:Inventory slot/links").links[item]
end
if count then
local itemCount = mw.html.create( "span" )
itemCount:cssText( "position: absolute; right: -2px; bottom: -5px; pointer-events: none;" )
:addClass( "c-0" )
:addClass( "shadow" )
:wikitext( count )
slot:node( itemCount )
end
if link or (args.link and args.link ~= "y" and args.link ~= "n") then
slotContainer:wikitext( "<span style='" .. display .. "' class='no-external-icon'>" .. "[https://bta.miraheze.org/wiki/" .. link:gsub(" ", "_") .. " " .. tostring( slot ) .. "]" .. "</span>" )
else
else
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
slotContainer:wikitext( "<span style='" .. display .. "'><!-- Air --></span>")
end
end
end
end