From StrategyWiki, the video game walkthrough and strategy guide wiki
Revision as of 01:00, 31 March 2024 by Prod (talk | contribs) (support floating table left, right, or center)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Pokemon/Shop/Documentation

local getArgs = require( 'Module:Arguments' ).getArgs

local p = {}

function p.shop( frame )
	local args = getArgs( frame, { wrappers = 'Template:Pokemon/Shop' } )
	
	return p._shop( args )
end

function p._shop( args )
	local itemList = mw.loadJsonData( 'Module:Pokemon/Shop/data.json' ) 
	local title = args.title or 'Poké Mart'
	local guide = mw.title.getCurrentTitle().rootText
	local root = mw.html.create( 'table' )

	if itemList[ guide ][ "redirect" ] ~= nil then
		guide = itemList[ guide ][ "redirect" ]
	end
	
	root
		:addClass( 'wikitable' )
			:tag( 'tr' )
				:tag( 'th' )
					:attr( 'colspan', 2 )				 
					:css( { ['background-color'] = '#0000BD', color = 'white' } )
					:wikitext( title )

	for k, v in ipairs(args) do
		if v == 'left' or v == 'right' or v == 'center' then
			root:css( { float = v } )
		elseif itemList[ guide ][ v ] == nil then
    		root:tag( 'tr' )
				:tag( 'td' )
					:attr( 'colspan', 2 )
					:css( 'text-align', 'center' )    
					:wikitext( v )
        else
			root:tag( 'tr' )
				:tag( 'td' ):wikitext( v )
				:tag( 'td' ):wikitext( '[[File:Pokebuck.png]]', itemList[ guide ][ v ] )
		end
	end

	return tostring( root )
end

return p