Module:Sandbox/User:Alsang: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 79:
end
local allWeapons = {}
for j,jtem in ipairs(weapons) do
table.insert(allWeapons,{suffixPage='[[' .. jtem .. ']]',prefixPage=''})
end
 
for i,item in ipairs(variants) do
for j,jtem in ipairs(weapons) do
table.insert(allWeapons,{pagenamesuffixPage='[[' .. jtem .. ' (' .. item .. ')]]',wrongnameprefixPage='[[' .. item .. ' ' .. jtem .. ']]'})
end
end
 
for i,item in ipairs(allWeapons) do
local query = mw.smw.ask(item.pagenamesuffixPage .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.itemnamesuffixItem = query[1].data
end
local query = mw.smw.ask(item.pagenamesuffixPage .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.facilitysuffixFacility = query[1].data
end
local query = mw.smw.ask(item.wrongnameprefixPage .. '|?Name #- = data|mainlabel=-')
if type(query)=='table' then
item.wrongitemnameprefixItem = query[1].data
end
local query = mw.smw.ask(item.wrongnameprefixPage .. '|?Uses facility #- = data|mainlabel=-')
if type(query)=='table' then
item.wrongfacilityprefixFacility = query[1].data
end
Line 114 ⟶ 118:
:tag('tr')
:tag('th')
:wikitext('Suffix PagenamesuffixPage')
:done()
:tag('th')
:wikitext('Suffix ItemnamesuffixItem')
:done()
:tag('th')
Line 123 ⟶ 127:
:done()
:tag('th')
:wikitext('Prefix PagenamesuffixPage')
:done()
:tag('th')
:wikitext('Prefix ItemnamesuffixItem')
:done()
:tag('th')
Line 136 ⟶ 140:
local row = out:tag('tr')
:tag('td')
:wikitext(item.pagenamesuffixPage)
:done()
:tag('td')
:wikitext(item.itemnamesuffixItem)
:done()
:tag('td')
:wikitext(item.facilitysuffixFacility)
:done()
:tag('td')
:wikitext(item.wrongnameprefixPage)
:done()
:tag('td')
:wikitext(item.wrongitemnameprefixItem)
:done()
:tag('td')
:wikitext(item.wrongfacilityprefixFacility)
:done()

Revision as of 23:58, 5 December 2024

Module documentation
This documentation is transcluded from Module:Sandbox/User:Alsang/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Sandbox/User:Alsang/doc. [edit]
Module:Sandbox/User:Alsang's function main is invoked by Template:Sandbox/User:Alsang.

p = {}

function p.main()
	return nil
end

function p.stone()
	return p.makeTable('stone')
end

function p.metal()
	return p.makeTable('metal')
end

function p.bone()
	return p.makeTable('bone')
end
	
function p.makeTable(args)
	
	local variants = {'Basic','Moderate','Fine','Strong','Superior','Perfect'}
	local weaponsStone = {
		'Hammerfist',
		'Throwing Stones',
		'Stone Slab Shield',
		'Stone Mace',
		'Stone Discs',
		'War Hammer',
		'Bolas',
		'Stone Chunk Shield',
		'Double Headed Hammer',
		'Throwing Clubs',
		'Great Stone Mace',
		' Polished Stone Shield',
		'Throwing Hammers',
		'Great Hammer',
		'Sling'}
	local weaponsMetal = {
		'Rapier ',
		'Throwing Twinblades',
		'Metal Kite Shield',
		'Flanged Mace',
		'Throwing Rings',
		'Shortsword',
		'Metal Javelins',
		'Metal Heater Shield',
		'Longsword',
		'Throwing Knives',
		'Broadsword',
		'Metal Buckler',
		'Throwing Axes',
		'Battleaxe',
		'Metal Bow'}
	local weaponsBone = {
		'Truncheon',
		'Blowpipe',
		'Wooden Round Shield',
		'Cudgel',
		'Javelins',
		'Club',
		'Light Crossbow',
		'Wooden Square Shield',
		'Quarterstaff',
		'Recurve Bow',
		'Spear',
		'Wooden Hexagon Shield',
		'Longbow',
		'Poleaxe',
		'Heavy Crossbow'}
	
	if args=='stone' then
		weapons = weaponsStone
	elseif args=='metal' then
		weapons = weaponsMetal
	elseif args=='bone' then
		weapons = weaponsBone
	else
		return nil
	end
		
	local allWeapons = {}
	
	for j,jtem in ipairs(weapons) do
		table.insert(allWeapons,{suffixPage='[[' .. jtem .. ']]',prefixPage=''})
	end

	for i,item in ipairs(variants) do
		for j,jtem in ipairs(weapons) do
			table.insert(allWeapons,{suffixPage='[[' .. jtem .. ' (' .. item .. ')]]',prefixPage='[[' .. item .. ' ' .. jtem .. ']]'})
		end
	end
	for i,item in ipairs(allWeapons) do
		
		local query = mw.smw.ask(item.suffixPage .. '|?Name #- = data|mainlabel=-')
		if type(query)=='table' then
			item.suffixItem = query[1].data
		end
			
		local query = mw.smw.ask(item.suffixPage .. '|?Uses facility #- = data|mainlabel=-')
		if type(query)=='table' then
			item.suffixFacility = query[1].data
		end
		
		local query = mw.smw.ask(item.prefixPage .. '|?Name #- = data|mainlabel=-')
		if type(query)=='table' then
			item.prefixItem = query[1].data
		end
			
		local query = mw.smw.ask(item.prefixPage .. '|?Uses facility #- = data|mainlabel=-')
		if type(query)=='table' then
			item.prefixFacility = query[1].data
		end
		
	end
	
	local out = mw.html.create('table')
		:addClass('wikitable sortable')
		:tag('tr')
			:tag('th')
				:wikitext('Suffix suffixPage')
			:done()
			:tag('th')
				:wikitext('Suffix suffixItem')
			:done()
			:tag('th')
				:wikitext('Suffix Recipe Facility')
			:done()
			:tag('th')
				:wikitext('Prefix suffixPage')
			:done()
			:tag('th')
				:wikitext('Prefix suffixItem')
			:done()
			:tag('th')
				:wikitext('Prefix Recipe Facility')
			:done()
		:done()
		
		for i,item in ipairs(allWeapons) do
			local row = out:tag('tr')
				:tag('td')
					:wikitext(item.suffixPage)
				:done()
				:tag('td')
					:wikitext(item.suffixItem)
				:done()
				:tag('td')
					:wikitext(item.suffixFacility)
				:done()
				:tag('td')
					:wikitext(item.prefixPage)
				:done()
				:tag('td')
					:wikitext(item.prefixItem)
				:done()
				:tag('td')
					:wikitext(item.prefixFacility)
				:done()
				
			:done()
			:done()
		end
		
	return out
	
	--for debugging
	--return '<pre>'..mw.text.jsonEncode(args, mw.text.JSON_PRETTY)..'</pre>'
	
end

return p