Pokémon Wiki

Don't like the ads? Then create an account! Users with accounts will only see ads on the Main Page and have more options than anonymous users.

READ MORE

Pokémon Wiki
Advertisement

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

local Type = {}
local data = mw.loadData( 'Module:Type/data' )

local function isempty(s)
-- Empty parameter check
  return s == nil or s == ''
end

function Type.type( frame )
-- Implements {{Type}}
-- This block calls the function _type, where the real magic happens.
-- This part just determines if it's from an #invoke or a Template; it makes sure the arguments are filled accordingly.
	if not isempty( frame.args[1] ) then
	  return Type._type( frame.args )
	else
	  return Type._type( frame:getParent().args )
	end
end

function Type.box( frame )
-- Implements {{Type Box}}
end

function Type.chartkey( frame )
-- Implements {{Type chart key}}
end

function Type._type( args )
-- The reusable part of Type, so that it can be called as a function from other Modules.
-- This first line throws an error when there's no first argument.
	assert( args[1], "There is no type listed.")
	local pokemontype = args[1]
	local fallbacktext = '[['..pokemontype..' type|<span style="color: #F8F8F8;">'..pokemontype..'</span>]]'
	local element = mw.html.create('span')
	  :css('border-style','solid none'):css('border-width','1px')
	  :css('border-radius','5px'):css('padding','0.15em'):css('font-variant','small-caps')
	  :css('font-size','9pt'):css('color','#F8F8F8'):css('text-shadow','0px 1px 1px #807870')
	  :css('background',data.color[string.lower(pokemontype)])
	  :css('border-top-color',data.bordertopcolor[string.lower(pokemontype)])
	  :css('border-bottom-color',data.borderbottomcolor[string.lower(pokemontype)])
	  :wikitext( args[2] or fallbacktext ):allDone()
	return tostring(element)
end

function Type.color( frame )
-- Implements {{Normal}}, etc. (the "Color templates").
-- This really should just call data.color["Normal"] in other templates, and it will be much faster.
-- The template code would be:
-- <includeonly>{{invoke:Type|color|Normal}}</includeonly>
-- <noinclude>{{invoke:Type|color|Normal|description}}[[Category:Color templates]]</noinclude>
-- This first line throws an error when there's no first argument.
	assert( frame.args[1], "There is no type listed.")
	local pokemontype = frame.args[1]
--	if not ( frame.args[2] == "description" ) then
--	  return data.color[string.lower(pokemontype)]
--	 else
	  local label = mw.html.create('th'):css('background',data.color[string.lower(pokemontype)]):css('color','#FFFFFF')
	    :wikitext('<small>[['..pokemontype..' Pokémon|<span style="color:#FFFFFF">'..pokemontype..'</span>]] color:'):done()
	  local colordata = mw.html.create('td'):tag('span'):css('font-weight','bold')
	    :css('color',data.color[string.lower(pokemontype)]):wikitext(data.color[string.lower(pokemontype)]):done():done()
	  local T = mw.html.create('table'):tag('tr'):node(label):node(colordata):done()
	  return tostring(T)
--	end
end
return Type
Advertisement