Module:Inventory slot: Difference between revisions
m minetip only pays attention to top level titles or next level link titles, so we need to add the title on the top level for it to override the default of the link title. It also should null the title if "title=none" is set, as otherwise it displays blank |
Actually, we were just using an old version of minetip. Updated to support an even newer version of minetip. Now passes along idData to the main sprite function rather than using the base function, so this gets its tracking categories. |
||
| Line 50: | Line 50: | ||
local modIds = {} | local modIds = {} | ||
local animated = args[1]:find( ';' ) | local animated = args[1]:find( ';' ) | ||
local pageName = mw.title.getCurrentTitle(). | local pageName = mw.title.getCurrentTitle().text | ||
local imgClass = args.imgclass | local imgClass = args.imgclass | ||
local numStyle = args.numstyle | local numStyle = args.numstyle | ||
| Line 81: | Line 81: | ||
( item or body ):tag( 'br' ) | ( item or body ):tag( 'br' ) | ||
else | else | ||
local category | |||
local parts = p.getParts( frame, args.mod ) | local parts = p.getParts( frame, args.mod ) | ||
local | local title = parts.title or mw.text.trim( args.title or '' ) | ||
local mod = parts.mod | local mod = parts.mod | ||
local name = parts.name | local name = parts.name | ||
local num = parts.num | local num = parts.num | ||
local | local description = parts.text | ||
local img, | local img, idData | ||
if mod then | if mod then | ||
local modData = modIds[mod] | |||
if not modData and mw.title.new( 'Module:InvSprite/Mods/' .. mod .. '/IDs' ).exists then | |||
modData = mw.loadData( 'Module:InvSprite/Mods/' .. mod .. '/IDs' ) | |||
modIds[mod] = modData | |||
end | end | ||
if | if modData and modData[name] then | ||
idData = modData[name] | |||
else | else | ||
img = name .. ' (' .. mod .. ')' | img = name .. ' (' .. mod .. ')' | ||
end | end | ||
elseif ids[name] then | elseif ids[name] then | ||
idData = ids[name] | |||
else | else | ||
img = name | img = name | ||
| Line 106: | Line 109: | ||
local link = args.link or '' | local link = args.link or '' | ||
if link == '' then | if link == '' then | ||
if | if mod then | ||
link = 'Mods/' .. mod .. '/' .. name | link = 'Mods/' .. mod .. '/' .. name | ||
else | else | ||
link = name | link = name | ||
end | end | ||
elseif link:lower() == 'none' then | |||
link = nil | |||
end | |||
if link == pageName then | |||
link = nil | |||
end | end | ||
local | local formattedTitle | ||
local plainTitle | |||
if title == '' then | if title == '' then | ||
plainTitle = name | |||
elseif title:lower() ~= 'none' then | |||
plainTitle = title:gsub( '\\\\', '\' ):gsub( '\\&', '&' ) | |||
local formatPattern = '&[0-9a-fk-or]' | |||
if plainTitle:match( formatPattern ) then | |||
formattedTitle = title | |||
plainTitle = plainTitle:gsub( formatPattern, '' ) | |||
end | end | ||
plainTitle:gsub( '\', '\\' ):gsub( '&', '&' ) | |||
elseif link then | |||
if img then | |||
formattedTitle = '' | |||
elseif | |||
if | |||
else | else | ||
plainTitle = '' | |||
end | end | ||
end | end | ||
item:attr{ | |||
['data-minetip-title'] = formattedTitle, | |||
['data-minetip-text'] = description | |||
} | |||
if img then | if img then | ||
item:addClass( 'invslot-item-image' ) | item:addClass( 'invslot-item-image' ) | ||
:wikitext( '[[File:Grid ', img, '.png|32x32px|link=', link or '', '|', | :wikitext( '[[File:Grid ', img, '.png|32x32px|link=', link or '', '|', plainTitle or '', ']]' ) | ||
else | else | ||
if not sprite then | if not sprite then | ||
sprite = require( [[Module:Sprite]] ). | sprite = require( [[Module:Sprite]] ).sprite | ||
end | end | ||
local image | local image | ||
| Line 164: | Line 162: | ||
item:wikitext( '[[', link, '|' ) | item:wikitext( '[[', link, '|' ) | ||
end | end | ||
local image, spriteCat = sprite{ | |||
iddata = idData, title = plainTitle, | |||
image = image, settings = 'InvSprite' | image = image, settings = 'InvSprite' | ||
} ) | } | ||
item:wikitext( image ) | |||
category = spriteCat | |||
end | end | ||
| Line 177: | Line 177: | ||
:tag( 'span' ) | :tag( 'span' ) | ||
:addClass( 'invslot-stacksize' ) | :addClass( 'invslot-stacksize' ) | ||
:attr{ title = | :attr{ title = plainTitle } | ||
:wikitext( num ) | :wikitext( num ) | ||
if numStyle then | if numStyle then | ||
| Line 187: | Line 187: | ||
end | end | ||
if | if idData and link then | ||
item:wikitext( ']]' ) | item:wikitext( ']]' ) | ||
end | end | ||
item:wikitext( category ) | |||
end | end | ||