Anonymous user
Module:Inventory slot: Difference between revisions
m
no edit summary
imported>Ttv pedro270707 mNo edit summary |
imported>Ttv pedro270707 mNo edit summary |
||
Line 65: | Line 65: | ||
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 | 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 slot = mw.html.create( "div" ) | local slot = mw.html.create( "div" ) | ||
Line 81: | Line 84: | ||
: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 = | 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 101: | ||
end | end | ||
-- Set the item count | |||
if count then | if count then | ||
local itemCount = mw.html.create( "span" ) | local itemCount = mw.html.create( "span" ) | ||
Line 108: | Line 112: | ||
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 | if link then | ||
Line 117: | Line 122: | ||
else | else | ||
if link then | if link then | ||
slotContainer:wikitext( "<span style='" .. display .. "'>" .. "[ | slotContainer:wikitext( "<span style='" .. display .. "'>" .. "[https://bta.miraheze.org/wiki/" .. link .. " " .. tostring( slot ) .. "]" .. "</span>" ) | ||
else | else | ||
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" ) | slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" ) | ||
Line 125: | Line 130: | ||
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 slot = mw.html.create( "div" ) | local slot = mw.html.create( "div" ) | ||
slot:addClass( "minecraft-item" ) | slot:addClass( "minecraft-item" ) | ||
:cssText( table.concat( slotCss, ";" ) ) | :cssText( table.concat( slotCss, ";" ) ) | ||
:attr( "data-mctitle", (name or item) ) | :attr( "data-mctitle", (name or item) ) | ||
if descriptions[item] then | if descriptions[item] then | ||
slot:attr( "data-mcdesc", p.formatDescription(descriptions[item], 16) ) | slot:attr( "data-mcdesc", p.formatDescription(descriptions[item], 16) ) | ||
end | end | ||
slot:wikitext( sprite( { data = "InvSprite", id = item } ) ) | |||
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 |