Bureaucrats, Check users, emailconfirmed, Interface administrators, staff, Administrators, translation-admin, Widget editors
1,637
edits
m (uhhh let's try this) |
mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 127: | Line 127: | ||
local i18n = { | local i18n = { | ||
filename = 'Invicon $1', | filename = 'Invicon $1', | ||
moduleAliases = [[Module: | moduleAliases = [[Module:InventorySlot/Aliases]], | ||
prefixes = { | prefixes = { | ||
any = 'Any', | any = 'Any', | ||
Line 136: | Line 136: | ||
} | } | ||
function | 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 item = mw.html.create( 'span' ):addClass( 'invslot-item' ) | local item = mw.html.create( 'span' ):addClass( 'invslot-item' ) | ||
if args.imgclass then | if args.imgclass then | ||
Line 232: | Line 251: | ||
end | end | ||
-- | -- I see. This frames is where you parse the semicolon separated list | ||
--local frames | -- and enable cycling, in addition to all of the extra data that you | ||
-- need for items. We'll need to investigate whether or not we'll need | |||
-- frames = args[1] | -- this? Like it'll be useful for vanilla items, but not for any of our | ||
-- recipes, since we don't need to cycle any of our custom items in recipes. | |||
-- .... I say that, then realize Zauber armor cycles. But tbf, it's all | |||
-- premade from aliases, and does not need custom in-place data | |||
local frames | |||
if args.parsed then | |||
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 | |||
local body = mw.html.create( 'span' ):addClass( 'invslot' ):css{ ['vertical-align'] = args.align } | |||
if animated then body:addClass( 'animated' ) 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 | |||
local body | -- Figure out cycling here | ||
if | for i, frame in ipairs( frames ) do | ||
local item | |||
-- how? | |||
item = makeItem( frame, i, args) | |||
body:node( item ) | |||
if i == activeFrame and animated then | |||
item:addClass( 'animated-active' ) | |||
end | |||
end | |||
return tostring( body ) | |||
end | |||
function UISlot.parseFrameText ( framesText, aliasReference ) | |||
local frames = {} | |||
local expandedAliases | |||
-- wow so much code for cycling that is being skipped here | |||
-- this line is definitely wrong, but we'll see if this works as a | |||
-- single line hack | |||
local frameText = framesText | |||
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 | end | ||
if | |||
if aliasFrames.name then | |||
aliasFrames = { aliasFrames } | |||
end | end | ||
if | |||
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 | 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 |
edits