Feed The Beast Wiki

Follow the Feed The Beast Wiki on Discord or Mastodon!

READ MORE

Feed The Beast Wiki
m (Fixes)
m (Add default format for "animated" arg if "true" or "1" is supplied)
(3 intermediate revisions by the same user not shown)
Line 40: Line 40:
 
if link == '' then
 
if link == '' then
 
link = item
 
link = item
-- If args.dis is set, this means the user doesn't want to disambiguate,
+
-- If args.dis is set, we only disambiguate if it equals exactly
-- so we want to invert the input!
+
-- 'true' or '1'. Otherwise, disambiguate by default.
local doDisambiguation = not args.dis
+
local doDisambiguation
  +
if args.dis then
  +
doDisambiguation = args.dis == 'true' or args.dis == '1'
  +
else
  +
doDisambiguation = true
  +
end
 
if mod.link and doDisambiguation then
 
if mod.link and doDisambiguation then
 
link = link .. ' (' .. mod.link .. ')'
 
link = link .. ' (' .. mod.link .. ')'
 
end
 
end
 
end
 
end
body:wikitext( '[[', link, require( [[Module:Language]] ).link{}, '|' )
+
link = link .. require( [[Module:Language]] ).link{}
  +
if not args.animated then
  +
body:wikitext( '[[', link, '|' )
  +
end
 
end
 
end
 
 
local icon = body:tag( 'span' ):css{ ['padding'] = args.padding }
+
local icon = mw.html.create( 'span' ):css{ ['padding'] = args.padding }
 
local lang = require([[Module:Utility_functions]]).pageSuffix():sub(2)
 
local lang = require([[Module:Utility_functions]]).pageSuffix():sub(2)
 
local title = args.title or args.tooltiptext or f:callParserFunction("#iconloc", {item, mod.abbr, "name", lang})
 
local title = args.title or args.tooltiptext or f:callParserFunction("#iconloc", {item, mod.abbr, "name", lang})
Line 79: Line 87:
 
body:attr{ ['data-minetip-text'] = args.desc or f:callParserFunction("#iconloc", {item, mod.abbr, "description", lang})}
 
body:attr{ ['data-minetip-text'] = args.desc or f:callParserFunction("#iconloc", {item, mod.abbr, "description", lang})}
 
 
icon:wikitext( f:callParserFunction( '#icon', { "", item = item, mod = mod.abbr, size = args.size or 32 } ) )
+
local size = args.size or 32
  +
if args.animated then
  +
local animated
  +
if args.animated == 'true' or args.animated == '1' then
  +
-- Use a default format that outputs in the form 'Icon (mod abbrv) (item name)'
  +
animated = 'Icon ' .. mod.abbr .. ' ' .. item
  +
else
  +
animated = args.animated
  +
end
  +
icon:wikitext( '[[File:', args.animated, '.gif|', size, 'x', size, 'px|center' )
  +
if link then
  +
icon:wikitext( '|link=', link )
  +
end
  +
icon:wikitext( ']]' )
  +
else
  +
icon:wikitext( f:callParserFunction( '#icon', { "", item = item, mod = mod.abbr, size = size } ) )
  +
end
 
 
 
local num = tonumber( args[2] or 1 )
 
local num = tonumber( args[2] or 1 )
Line 89: Line 113:
 
end
 
end
 
 
if link then
+
body:node( icon )
body:wikitext( ']]' )
+
if link and not args.animated then
  +
body:wikitext( ']]' )
 
end
 
end
 
 

Revision as of 05:15, 23 January 2021

Documentation for this module may be created at Module:Grid/doc

local p = {}
p.cell = function( f )
        local args = f.args or f
        if f == mw.getCurrentFrame() and args[1] == nil then
                args = f:getParent().args
        else
                f = mw.getCurrentFrame()
        end
        args = require( [[Module:ProcessArgs]] ).norm( args )
        
        local item = args[1]
        local renamed = require( [[Module:Grid/Renames]] )[item]
        if renamed and ((args.mod or '') == 'V' or (args.mod or '') == '') then
        	args[1] = renamed
        	return [=[[[Category:Pages using a renamed tile]]]=] .. p.cell(args)
        end
        
        local body = mw.html.create( 'span' ):addClass( 'grid' ):css{ ['vertical-align'] = args.align }
        if args['no-bg'] then
                body:addClass( 'grid-plain' )
        end
        if args.class then
                body:addClass( args.class )
        end
        if args.style then
                body:cssText( args.style )
        end
        
        if not item then
                body:tag( 'br' )
                return tostring( body )
        end
        
        local mod = require([[Module:Mods]]).getData(string.upper(args.mod or '')) or { abbr="", mod="", name="", localized="" }
        
        local link = args.link or ''
        if link:lower() == 'none' then
                link = nil
        else
                if link == '' then
                        link = item
                        -- If args.dis is set, we only disambiguate if it equals exactly
                        -- 'true' or '1'. Otherwise, disambiguate by default.
                        local doDisambiguation
                        if args.dis then
                        	doDisambiguation = args.dis == 'true' or args.dis == '1'
                    	else
                    		doDisambiguation = true
                		end
                        if mod.link and doDisambiguation then
                                link = link .. ' (' .. mod.link .. ')'
                        end
                end
                link = link .. require( [[Module:Language]] ).link{}
                if not args.animated then
                	body:wikitext( '[[', link, '|' )
            	end
        end
        
        local icon = mw.html.create( 'span' ):css{ ['padding'] = args.padding }
        local lang = require([[Module:Utility_functions]]).pageSuffix():sub(2)
        local title = args.title or args.tooltiptext or f:callParserFunction("#iconloc", {item, mod.abbr, "name", lang})
        if args.appendtitle then
        	title = f:callParserFunction("#iconloc", {item, mod.abbr, "name", lang}) .. args.title or args.tooltiptext or ''
        end
        if not title or title == '' then
        	title = item
        elseif title:lower() == 'none' then
                title = ''
        elseif title:match( '&' ) then
                body:attr( 'data-minetip-title', title )
                
                title = title:gsub( '&[0-9a-fk-or]', '' )
                if title == '' then
                        title = item
                end
        end
        ( link and icon or body ):attr{ title = title }
        if args['ore-dict-name'] and mod.localized then
        	local orenamefixed = args['ore-dict-name']:gsub("/", "\\/")
        	if not args.desc or args.desc == '' then
        		args.desc = '&7' .. orenamefixed .. '/&o&9' .. mod.localized
        	else
        		args.desc = args.desc .. '/&7' .. orenamefixed .. '/&o&9' .. mod.localized
    		end
    	end
        body:attr{ ['data-minetip-text'] = args.desc or f:callParserFunction("#iconloc", {item, mod.abbr, "description", lang})}
        
        local size = args.size or 32
        if args.animated then
        	local animated
        	if args.animated == 'true' or args.animated == '1' then
        		-- Use a default format that outputs in the form 'Icon (mod abbrv) (item name)'
        		animated = 'Icon ' .. mod.abbr .. ' ' .. item
    		else
    			animated = args.animated
			end
        	icon:wikitext( '[[File:', args.animated, '.gif|', size, 'x', size, 'px|center' )
        	if link then
        		icon:wikitext( '|link=', link )
    		end
    		icon:wikitext( ']]' )
    	else
    		icon:wikitext( f:callParserFunction( '#icon', { "", item = item, mod = mod.abbr, size = size } ) )
    	end
        
        local num = tonumber( args[2] or 1 )
        if num and num > 1 and num < 1000 then
                local number = icon:tag( 'span' ):addClass( 'grid-number' ):wikitext( num )
                if args.numstyle then
                        number:cssText( args.numstyle )
                end
        end
        
        body:node( icon )
        if link and not args.animated then
            body:wikitext( ']]' )
        end
        
        return tostring( body )
end
return p