24,493 ARTICLES
ON THIS WIKI

Module:Grid/FTAElement

Lua Logo.svg This is the Lua module for Template:Grid/FTAElement. Below is the documentation for that template.

This template is used inside of {{Grid}}'s content parameter to insert an element from the Periodic Table, as used in the FullThrottle Alchemist mod.

Parameters[edit]

  • name: The element's name or symbol.
  • top: Distance of the top-left image corner from the top edge of the grid.
  • left: Distance of the top-left image corner from the left edge of the grid.
  • link: Replacement link target. Default: The full name of the element; Example: Helium
  • fill: A background color with which to fill the item slot. "Default: No background"

Example[edit]

Code[edit]

{{Grid/FTAElement|name=he}}
{{Grid/FTAElement|name=lead}}

Output[edit]

Helium

Lead


local p = {}
 
local g = require("Module:Common")
local s = require("Module:Sprite")

elemtable = {
	['Hydrogen'] = {1, 'H'};
	['Helium'] = {2, 'He'};
	['Lithium'] = {3, 'Li'};
	['Beryllium'] = {4, 'Be'};
	['Boron'] = {5, 'B'};
	['Carbon'] = {6, 'C'};
	['Nitrogen'] = {7, 'N'};
	['Oxygen'] = {8, 'O'};
	['Fluorine'] = {9, 'F'};
	['Neon'] = {10, 'Ne'};
	['Sodium'] = {11, 'Na'};
	['Magnesium'] = {12, 'Mg'};
	['Aluminium'] = {13, 'Al'};
	['Silicon'] = {14, 'Si'};
	['Phosphorus'] = {15, 'P'};
	['Sulfur'] = {16, 'S'};
	['Chlorine'] = {17, 'cl'};
	['Argon'] = {18, 'Ar'};
	['Potassium'] = {19, 'K'};
	['Calcium'] = {20, 'Ca'};
	['Scandium'] = {21, 'Sc'};
	['Titanium'] = {22, 'Ti'};
	['Vanadium'] = {23, 'V'};
	['Chromium'] = {24, 'Cr'};
	['Manganese'] = {25, 'Mn'};
	['Iron'] = {26, 'Fe'};
	['Cobalt'] = {27, 'Co'};
	['Nickel'] = {28, 'Ni'};
	['Copper'] = {29, 'Cu'};
	['Zinc'] = {30, 'Zn'};
	['Gallium'] = {31, 'Ga'};
	['Germanium'] = {32, 'Ge'};
	['Arsenic'] = {33, 'As'};
	['Selenium'] = {34, 'Se'};
	['Bromine'] = {35, 'Br'};
	['Krypton'] = {36, 'Kr'};
	['Rubidium'] = {37, 'Rb'};
	['Strontium'] = {38, 'Sr'};
	['Yttrium'] = {39, 'Y'};
	['Zirconium'] = {40, 'Zr'};
	['Niobium'] = {41, 'Nb'};
	['Molybdenum'] = {42, 'Mo'};
	['Technetium'] = {43, 'Tc'};
	['Ruthenium'] = {44, 'Ru'};
	['Rhodium'] = {45, 'Rh'};
	['Palladium'] = {46, 'Pd'};
	['Silver'] = {47, 'Ag'};
	['Cadmium'] = {48, 'Cd'};
	['Indium'] = {49, 'In'};
	['Tin'] = {50, 'Sn'};
	['Antimony'] = {51, 'Sb'};
	['Tellurium'] = {52, 'Te'};
	['Iodine'] = {53, 'I'};
	['Xenon'] = {54, 'Xe'};
	['Caesium'] = {55, 'Cs'};
	['Barium'] = {56, 'Ba'};
	
	['Hafnium'] = {72, 'Hf'};
	['Tantalum'] = {73, 'Ta'};
	['Tungsten'] = {74, 'W'};
	['Rhenium'] = {75, 'Re'};
	['Osmium'] = {76, 'Os'};
	['Iridium'] = {77, 'Ir'};
	['Platinum'] = {78, 'Pt'};
	['Gold'] = {79, 'Au'};
	['Mercury'] = {80, 'Hg'};
	['Thallium'] = {81, 'Tl'};
	['Lead'] = {82, 'Pb'};
	['Bismuth'] = {83, 'Bi'};
	['Polonium'] = {84, 'Po'};
	['Astatine'] = {85, 'At'};
	['Radon'] = {86, 'Rn'};
}

tablemap = {}

for name, data in pairs(elemtable) do
	local elem = {data[1], name, data[2]}
	tablemap[string.lower(name)] = elem
	tablemap[string.lower(data[2])] = elem
end
 
function p.makeElement(idx, name, link, tooltip, top, left, fill)
	local output = '<div data-tooltip="' .. tooltip .. '" class="tooltip griditem" '
	output = output .. 'style="top:' .. g.px(top) .. ';left:' .. g.px(left)
	output = output .. '">' .. s.makeSprite('FTAPeriodicTable.png', idx, 64, 1024, link, name) .. '</div>'
	return output
end
 
function p.main(frame)
	local frame, args = g.getFrameAndArgs(frame)
 
	if not g.isGiven(args.name) then
		return ''
	end
	
	local data = tablemap[string.lower(args.name)]
	if data == nil then
		return ''
	end
	
	local tooltip = data[2] .. ' [' .. data[3] .. ']'
 
	local link = args.link
	if not g.isGiven(link) then
		link = data[2]
	end
 
	local top = 0
	if g.isGiven(args.top) and tonumber(args.top) then
		top = tonumber(args.top)
	end
 
	local left = 0
	if g.isGiven(args.left) and tonumber(args.left) then
		left = tonumber(args.left)
	end
 
	return p.makeElement(data[1] - 1, data[2], link, tooltip, top, left, args.fill)
end
 
return p