Module:InventorySlot: Difference between revisions

Jump to navigation Jump to search
m
Let's see where this goes wrong
m (Okay Jeeps, this is the start)
m (Let's see where this goes wrong)
Line 135: Line 135:
},
},
}
}
local aliases = mw.loadData( i18n.moduleAliases )
--[[Merges a list, or inserts a string
or table into a table
--]]
local function mergeList( parentTable, content )
local i = #parentTable + 1
if content[1] then
-- Merge list into table
for _, v in ipairs( content ) do
parentTable[i] = v
i = i + 1
end
else
-- Add strings or tables to table
parentTable[i] = content
end
end


local function makeItem( args )
local function makeItem( args )
Line 242: Line 261:
if args.parsed then
if args.parsed then
frames = args[1]
frames = args[1]
elseif args[1] ~= '' then
-- Not using moddata, but that kinda makes me think we could use the
-- module namespaces from automatically imported items... hmm...
frames = UISlot:parseFrameText ( args[1], false )
end
end
local body = mw.html.create( 'span' ):addClass( 'invslot' ):css{ ['vertical-align'] = args.align }
local body = mw.html.create( 'span' ):addClass( 'invslot' ):css{ ['vertical-align'] = args.align }
if animated then
if animated then body:addClass( 'animated' ) end
body:addClass( 'animated' )
if args.class then body:addClass( args.class ) end
end
if args.style then body:cssText( args.style ) end
if args.class then
body:addClass( args.class )
end
if args.style then
body:cssText( args.style )
end


if not frames then return tostring ( body) end
-- Figure out cycling here
-- Figure out cycling here
for i, frame in ipairs( frames ) do
for i, frame in ipairs( frames ) do
local item
local item
-- how?
-- how?
item = makeItem( frame, i, args)
item = makeItem( frame, i, args)
body:node( item )
body:node( item )
Line 268: Line 287:
end
end
return tostring( body )  
return tostring( body )  
end
function UISlot.parseFrameText ( framesText, aliasReference )
local frames = {}
local expandedAliases
-- wow so much code for cycling that is being skipped here
local frame = UISlot.makeFrame( frameText )
local newFrame = frame
-- or gm4 ?
if aliases then
local id = frame.name
if frame.mod and frame.mod == 'gm4' then
-- load gm4 aliases, I guess?
end
-- Figure out how to load and access the gm4 alias
local alias = aliases or aliases[id]
if alias then
newFrame = UISlot.getAlias ( alias, frame )
-- lots of other code that we need to do when we accept cycle lists
end
mergeList( frames, newFrame )
end
return frames
end
function UISlot.getAlias( aliasFrames, parentFrame )
if type( aliasFrames ) == 'string' then
local expandedFrame = mw.clone ( parentFrame )
expandedFrame.name = aliasFrames
return { expandedFrame }
end
if aliasFrames.name then
aliasFrames = { aliasFrames }
end
for i, aliasFrame in ipairs( aliasFrames ) do
local expandedFrame
if type( aliasFrame ) == 'string' then
expandedFrame = { name = aliasFrame }
else
expandedFrame = cloneTable( aliasFrame )
end
expandedFrame.title = parentFrame.title or expandedFrame.title
expandedFrame.mod = parentFrame.mod or expandedFrame.mod
expandedFrame.num = parentFrame.num or expandedFrame.num
expandedFrame.text = parentFrame.text or expandedFrame.text
expandedFrames[i] = expandedFrame
end
return expandedFrames
end
function UISlot.makeFrame( frameText )
local frame = {}
frame.title = frameText:match( '^%[([^%]]+)%]' )
frame.mod = frameText:match( '([^:%]]+):' ) or mod
local vanilla = { v = 1, vanilla = 1, mc = 1, minecraft = 1 }
if frame.mod and vanilla[mw.ustring.lower( frame.mod )] or frame.mod == '' then
frame.mod = nil
end
local nameStart = ( frameText:find( ':' ) or frameText:find( '%]' ) or 0 ) + 1
if nameStart - 1 == #frameText then
nameStart = 1
end
-- Come back to this later.  If we are going to pull names after colons,
-- then we know whether it's vanilla or gm4.  Should maybe use the "mod"
-- stuff at some point, but I'd imagine above is where you'd pull and find
frame.name = frameText:sub( nameStart, ( frameText:find( '[,%[]', nameStart ) or 0 ) - 1 )
frame.text = frameText:match( '%[([^%]]+)%]$' )
return frame
end
end


return UISlot
return UISlot
Bureaucrats, Check users, emailconfirmed, Interface administrators, staff, Administrators, translation-admin, Widget editors
1,659

edits

Navigation menu