Module:Inventory slot: Difference between revisions

Default the mod to vanilla otherwise the mod will be wrong when a default mod is set and this goes through .getParts() the second time.
Move alias expansion to a function
Line 37: Line 37:
if alias then
if alias then
local aliasFrames = {}
table.insert( frames, p.expandAlias( frameParts, alias ) )
for aliasFrame in mw.text.gsplit( alias, '%s*;%s*' ) do
local aliasParts = p.getParts( aliasFrame )
aliasParts.title = frameParts.title or aliasParts.title or ''
aliasParts.mod = frameParts.mod or aliasParts.mod or 'Minecraft'
aliasParts.num = frameParts.num or aliasParts.num or ''
aliasParts.text = frameParts.text or aliasParts.text or ''
aliasFrames[#aliasFrames + 1] = string.format( '[%s]%s:%s,%s[%s]', aliasParts.title, aliasParts.mod, aliasParts.name, aliasParts.num, aliasParts.text )
end
frames[#frames + 1] = table.concat( aliasFrames, ';' )
else
else
frames[#frames + 1] = frame
table.insert( frames, frame )
end
end
end
end
Line 190: Line 179:
html = table.concat( html, '' ):gsub( ' "', '"' )
html = table.concat( html, '' ):gsub( ' "', '"' )
return html
return html
end
function p.expandAlias( frameParts, alias )
-- If the frame has no parts, we can just return the alias as-is
if not frameParts.title and not frameParts.mod and not frameParts.num and not frameParts.text then
return alias
end
local expandedFrames = {}
for aliasFrame in mw.text.gsplit( alias, '%s*;%s*' ) do
local aliasParts = p.getParts( aliasFrame )
aliasParts.title = frameParts.title or aliasParts.title or ''
aliasParts.mod = frameParts.mod or aliasParts.mod or 'Minecraft'
aliasParts.num = frameParts.num or aliasParts.num or ''
aliasParts.text = frameParts.text or aliasParts.text or ''
table.insert( expandedFrames, string.format( '[%s]%s:%s,%s[%s]', aliasParts.title, aliasParts.mod, aliasParts.name, aliasParts.num, aliasParts.text ) )
end
return table.concat( expandedFrames, ';' )
end
end