Module:Inventory slot: Difference between revisions
No edit summary |
No edit summary |
||
(25 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
local i18n = { | local i18n = { | ||
modLink = '$1:$2', | |||
modLink = ' | |||
moduleAliases = [[Module:Inventory slot/Aliases]], | moduleAliases = [[Module:Inventory slot/Aliases]], | ||
moduleRandom = [[Module:Random]], | moduleRandom = [[Module:Random]], | ||
Line 100: | Line 98: | ||
local category | local category | ||
local title = frame.title or mw.text.trim( args.title or '' ) | local title = frame.title or mw.text.trim( args.title or '' ) | ||
local num = frame.num | local num = frame.num | ||
local description = frame.text | local description = frame.text | ||
local | local mod = frame.mod or 'Minecraft' | ||
if | local name = frame.name | ||
if frame.name:match( '%.gif$' ) and frame.name:match( '%.png$' ) then | |||
name = frame.name | |||
mod = '' | |||
end | |||
local minecraft = mod == "Minecraft" or mod == "minecraft" | |||
local img = frame.img | |||
if not img then | |||
if name:match( '%.gif$' ) or name:match( '%.png$' ) then | |||
img = name | |||
-- Remove file extension from name | |||
name = name:sub( 0, -5 ) | |||
elseif minecraft then | |||
img = 'Invicon ' .. name .. '.png' | |||
elseif mod then | |||
img = mod .. ' ' .. name .. '.png' | |||
else | |||
img = name | |||
end | |||
end | |||
if name:match( ' Revision %d+' ) then | |||
name = name:gsub( ' Revision %d+', '' ) | |||
end | end | ||
local link = args.link or '' | local link = args.link or '' | ||
if link == '' then | if link == '' then | ||
link = i18n.modLink:gsub( '%$1', mod ):gsub( '%$2', name ) | |||
elseif link:lower() == 'none' then | elseif link:lower() == 'none' then | ||
link = nil | link = nil | ||
Line 141: | Line 148: | ||
plainTitle = title:gsub( '\\\\', '\' ):gsub( '\\&', '&' ) | plainTitle = title:gsub( '\\\\', '\' ):gsub( '\\&', '&' ) | ||
local | local formatPatterns = {'&[0-9a-jl-qs-vyzr]', '&#%x%x%x%x%x%x', '&$%x%x%x'} | ||
if plainTitle:match( formatPattern ) then | for _, formatPattern in ipairs( formatPatterns ) do | ||
if plainTitle:match( formatPattern ) then | |||
formattedTitle = title | |||
plainTitle = plainTitle:gsub( formatPattern, '' ) | |||
end | |||
end | end | ||
Line 173: | Line 182: | ||
altText = altText .. ' ' .. description:gsub( '/', ' ' ) | altText = altText .. ' ' .. description:gsub( '/', ' ' ) | ||
end | end | ||
altText = altText:gsub( '&[0-9a- | altText = altText:gsub( '&[0-9a-jl-qs-wr]', '' ) | ||
end | end | ||
item:addClass( 'invslot-item-image' ) | item:addClass( 'invslot-item-image' ) | ||
:wikitext( '[[File:', img, '|32x32px|link=', link or '', '|alt=', altText, '|', escapedTitle, ']]' ) | :wikitext( '[[File:', img, '|32x32px|link=', link or '', '|alt=', altText, '|', escapedTitle, ']]' ) | ||
if num and num > 1 and num < 1000 then | if num and num > 1 and num < 1000 then | ||
if link then | if link then | ||
Line 259: | Line 270: | ||
if frame[1] then | if frame[1] then | ||
item = body:tag( 'span' ):addClass( 'animated-subframe' ) | item = body:tag( 'span' ):addClass( 'animated-subframe' ) | ||
local subActiveFrame = frame.randomise and random( #frame ) or 1 | local subActiveFrame = frame.randomise == true and random( #frame ) or 1 | ||
for sI, sFrame in ipairs( frame ) do | for sI, sFrame in ipairs( frame ) do | ||
local sItem = makeItem( sFrame, sI, args ) | local sItem = makeItem( sFrame, sI, args ) | ||
Line 347: | Line 358: | ||
-- or the subframe being the only frame | -- or the subframe being the only frame | ||
if #subframes == 1 or #splitFrames == i and #frames == 0 then | if #subframes == 1 or #splitFrames == i and #frames == 0 then | ||
local lastFrame = #frames | |||
mergeList( frames, subframes ) | mergeList( frames, subframes ) | ||
-- Inherit the randomise flag if it's the only frame | |||
if #splitFrames == 1 then | |||
frames.randomise = subframes.randomise | |||
end | |||
-- Append alias reference data, if present | |||
if aliasReference and subframes.aliasReference then | |||
if not expandedAliases then | |||
expandedAliases = {} | |||
end | |||
for i, aliasRefData in pairs(subframes.aliasReference) do | |||
expandedAliases[lastFrame + i] = aliasRefData | |||
end | |||
end | |||
else | else | ||
table.insert( frames, subframes ) | table.insert( frames, subframes ) | ||
Line 356: | Line 383: | ||
else | else | ||
-- Randomise starting frame for "Any *" aliases, as long as the alias is the only frame | -- Randomise starting frame for "Any *" aliases, as long as the alias is the only frame | ||
if frames.randomise = | if frames.randomise ~= 'never' and frame.name:match( '^' .. i18n.prefixes.any .. ' ' ) then | ||
frames.randomise = true | frames.randomise = true | ||
else | |||
frames.randomise = false | frames.randomise = false | ||
end | end | ||
Line 414: | Line 441: | ||
end | end | ||
return string.format( | return string.format( | ||
'[%s] | '[%s]%s,%s[%s]', | ||
frame.title or '', | frame.title or '', | ||
frame.name, | frame.name, | ||
frame.num or '', | frame.num or '', |