Module:Sandbox/User:Lego6245/InfoboxOre

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Lego6245/InfoboxOre requires Module:Coins.
Module:Sandbox/User:Lego6245/InfoboxOre requires Module:ExchangeLite.
Module:Sandbox/User:Lego6245/InfoboxOre loads data from Module:Rocks.

This module is a sandbox for Lego6245. It can be used to test changes to existing modules, prototype new modules, or just experimenting with lua features.

Invocations of this sandbox should be kept in userspace; if the module is intended for use in other namespaces, it should be moved out of the sandbox into a normal module and template.

This default documentation can be overridden by creating the /doc subpage of this module, as normal.

local gemw = require('Module:ExchangeLite')
local p = {}
local data = mw.loadData('Module:Rocks')
local coins = require('Module:Coins')

function plink(name, opts)
    local file = name.. '.png'
    local link = name
    local text = name
    if type(opts) == 'table' then
        if opts.txt then
            text = opts.txt
        end
        if opts.img then
            file = opts.img
        end
    end
    if text ~= '' then
        text = string.format(' [[%s|%s]]', link,text)
    end
    return string.format('[[File:%s|link=%s|frameless|35px]]%s', file, link, text)
end
function plinkp(name, img)
    return plink(name, {img = img, txt = ''})
end

function getn(a)
	local max = 0
	for i = 1,1000,1 do
		if a[i] ~= nil then max = i
		else break end
	end
return max
end

function p.main(frame)
	local args = frame:getParent().args
	local name = args[1]
	local type = string.lower(args[2] or 'ore')
	local t = mw.html.create('table')
	t:addClass('wikitable')
	:css('text-align', 'center')
	for index,i in ipairs(data) do
		if name == i.name then
			local test = i
			t:tag('tr')
			if type == 'ore' then 
				t:tag('th')	:wikitext(plink((i.output or name), { img = (i.img or i.output or name)..'.png'})) :attr('colspan', 6)	:done() 
			elseif type == 'rock' then
				t:tag('th')	:wikitext(plink((i.source1 or i.source or (name..' rock')), { img = (i.srcimg or i.source1 or i.source or (name..' rock'))..'.png'}  ))	:attr('colspan', 6)	:done() 
			else return 'You must choose either "ore" or "rock" as the type.'
			end
			if i.core == 1 then
				local minVarrockArmourLevel = 0
				for x = 1,4,1 do
					if (i.varrock[x] == 1 and minVarrockArmourLevel == 0) then minVarrockArmourLevel = x
				end end
				local crit,rck,geode_chance_one,geode_chance_two,dbl_chance
				if i.crit[2] ~= nil then crit = '[[File:Mining-icon.png|21x21px|link=]] '..i.crit[2] else crit = '-' end
				if i.rck[2] ~= nil then rck = '[[File:Mining-icon.png|21x21px|link=]] '..i.rck[2] else rck = '-' end
				if i.geode_chance_level[1] ~= nil then geode_chance_one = '[[File:Mining-icon.png|21x21px|link=]] '..i.geode_chance_level[1] else geode_chance_one = '-' end
				if i.geode_chance_level[2] ~= nil then geode_chance_two = '[[File:Mining-icon.png|21x21px|link=]] '..i.geode_chance_level[2] else geode_chance_two = '-' end
				if i.double_ore_chance[2] ~= nil then dbl_chance = '[[File:Mining-icon.png|21x21px|link=]] '..i.double_ore_chance[2] else dbl_chance = '-' end
				t:tag('tr')
				:tag('th')	:wikitext('[[Mining|Mining level]]')							:attr('colspan', 2)	:done()
				:tag('td')	:wikitext('[[File:Mining-icon.png|21x21px|link=]] '..i.level)	:attr('colspan', 2)	:done()
				:tag('th')	:wikitext('Critical Hit Chance')								:attr('colspan', 2)	:done()
				:tag('tr')
				if type == 'ore' then
					t:tag('th')	:wikitext('Source')												:attr('colspan', 2)	:done()
					if i.source == nil then
						t:tag('td')	:wikitext('[['..i.name..' rocks]]')							:attr('colspan', 2)	:done()
					else
						t:tag('td')	:wikitext('[['..i.source..']]')								:attr('colspan', 2)	:done()
					end
				elseif type == 'rock' then
					t:tag('th') :wikitext('Output')	:attr('colspan', 2)	:done()
					if i.output == nil then
						t:tag('td')	:wikitext('[['..name..']]')									:attr('colspan', 2)	:done()
					else
						t:tag('td')	:wikitext('[['..i.output..']]')								:attr('colspan', 2)	:done()
					end
				end
				t:tag('th')	:wikitext('20%')												:done()
				:tag('th')	:wikitext('30%')												:done()
				:tag('tr')
				:tag('th')	:wikitext('Core')												:attr('colspan', 2)	:done()
				:tag('td')	:wikitext('[[File:Yes check.svg|20px|link=]]')					:attr('colspan', 2)	:done()
				:tag('td')	:wikitext('[[File:Mining-icon.png|21x21px|link=]] '..(i.crit[1]))
				:tag('td')	:wikitext(crit)
				:tag('tr')
				:tag('th')	:wikitext('Stone Spirit')										:attr('colspan', 2)	:done()
				:tag('td')	:wikitext(plink(i.spirit..' stone spirit', { txt = i.spirit}))	:attr('colspan', 2)	:done()
				:tag('th')	:wikitext('Rockertunity Multiplier')							:attr('colspan', 2)	:done()
				:tag('tr')
				:tag('th')	:wikitext('Geode')												:attr('colspan', 2)	:done()
				:tag('td')	:wikitext(plink(i.geode..' geode', { txt = i.geode}))			:attr('colspan', 2)	:done()
				:tag('th')	:wikitext('x5')
				:tag('th')	:wikitext('x6')
				:tag('tr')
				:tag('th')	:wikitext('Rock stats')	:attr('colspan', 4)
				:tag('td')	:wikitext('[[File:Mining-icon.png|21x21px|link=]] '..(i.rck[1]))
				:tag('td')	:wikitext(rck)
				:tag('tr')
				:tag('th')	:wikitext('Durability')										:attr('colspan', 2)
				:tag('td')	:wikitext(i.hp)												:attr('colspan', 2)
				:tag('th')	:wikitext('Double Ore Chance')								:attr('colspan', 2)
				:tag('tr')
				:tag('th')	:wikitext('Hardness')										:attr('colspan', 2)
				:tag('td')	:wikitext(i.hardness)										:attr('colspan', 2)
				:tag('th')	:wikitext('5%')
				:tag('th')	:wikitext('10%')
				:tag('tr')
				:tag('th')	:wikitext('Multiplier')										:attr('colspan', 2)
				:tag('td')	:wikitext(i.mult)											:attr('colspan', 2)
				:tag('td')	:wikitext('[[File:Mining-icon.png|21x21px|link=]] '..(i.double_ore_chance[1]))
				:tag('td')	:wikitext(dbl_chance)
				:tag('tr')
				:tag('th')	:wikitext('Base Ore')										:attr('colspan', 2)
				:tag('td')	:wikitext(i.ore)											:attr('colspan', 2)
				:tag('th')	:wikitext('Geode Chance')									:attr('colspan', 2)
				:tag('tr')
				:tag('th')	:wikitext('Varrock Armour')									:attr('colspan', 4)
				:tag('th')	:wikitext('10%')
				:tag('th')	:wikitext('15%')
				:tag('tr')
				if minVarrockArmourLevel > 0 then
					t:tag('td')	:wikitext(plink('Varrock armour ' ..  minVarrockArmourLevel))	:attr('colspan', 2)
					:tag('td')	:wikitext((5-minVarrockArmourLevel) .. '%')						:attr('colspan', 2)
				else
					t:tag('td')	:wikitext('No bonus')											:attr('colspan', 4)
				end
				t:tag('td')	:wikitext(geode_chance_one)
				:tag('td')	:wikitext(geode_chance_two)
			else
				t:tag('tr')
				:tag('th')	:wikitext('[[Mining|Mining level]]')						
				:tag('td')	:wikitext('[[File:Mining-icon.png|21x21px|link=]] '..i.level)
				:tag('tr')
				if type == 'ore' then
					t:tag('th')	:wikitext('Source')
					if i.source ~= nil then
						if getn(i.source) == 0 then
							t:tag('td')	:wikitext('[['..i.source..']]')
						else
							local sources = ''
							for x = 1,getn(i.source),1 do
								sources = sources..'[['..i.source[x]..']]'..'<br>'
							end
							t:tag('td')	:wikitext(sources)
						end
					else
						t:tag('td')	:wikitext('[['..i.name..' rocks]]')
					end
				elseif type == 'rock' then
					t:tag('th') :wikitext('Output')
					if i.output ~= nil then
						if getn(i.output) == 0 then
							t:tag('td')	:wikitext('[['..i.output..']]')
						else
							local outputs = ''
							for x = 1,getn(i.output),1 do
								outputs = outputs..plink(i.output[x])..'<br>'
							end
							t:tag('td')	:wikitext(outputs)
						end
					else
						t:tag('td')	:wikitext('[['..name..']]')
					end
				end										
				t:tag('tr')
				:tag('th')	:wikitext('Core')										
				:tag('td')	:wikitext('[[File:X mark.svg|20px|link=]]')			
				:tag('tr')
				if i.spirit ~= nil then
				t:tag('th')	:wikitext('Stone Spirit')	
				:tag('td')	:wikitext(plink(i.spirit..' stone spirit', { txt = i.spirit}))
				end
				t:tag('tr')
				:tag('th')	:wikitext('Rock stats')	:attr('colspan', 2)
				:tag('tr')
				:tag('th')	:wikitext('Durability')									
				:tag('td')	:wikitext(i.hp)	
				:tag('tr')
				:tag('th')	:wikitext('Hardness')										
				:tag('td')	:wikitext(i.hardness)	
				:tag('tr')
				:tag('th')	:wikitext('Multiplier')										
				:tag('td')	:wikitext(i.mult)	
				:tag('tr')
				:tag('th')	:wikitext('Base Ore')								
				:tag('td')	:wikitext(i.ore)		
			end
		end
	end
return t	
end
return p