Module:Infobox Scenery

From RuneScape Classic Wiki
Jump to: navigation, search

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

--------------------------
-- Module for [[Template:Infobox Scenery]]
------------------------
local p = {}

local onmain = require('Module:Mainonly').on_main
local infobox = require('Module:Infobox')

function p.main(frame)
	local args = frame:getParent().args
	local ret = infobox.new(args)

	ret:defineParams{
		{ name = 'name', func = 'name' },
		{ name = 'image', func = 'image' },
		{ name = 'release', func = 'release' },
		{ name = 'aka', func = 'has_content' },
		{ name = 'members', func = 'has_content' },
		{ name = 'quest', func = 'has_content' },
		{ name = 'location', func = 'has_content' },
		{ name = 'actions', func = 'has_content' },
		{ name = 'examine', func = 'has_content' },
		{ name = 'map', func = 'has_content' },

		{ name = 'id', func = 'has_content' },
		{ name = 'id_smw', func = { name = idsmw, params = { 'id' }, flag = 'p' } },
	}

	ret:defineLinks({ hide = true })

	ret:useSMWSubobject({
		id_smw = 'Object ID',
	})

	ret:create()
	ret:cleanParams()

	ret:customButtonPlacement(true)
	ret:addButtonsCaption()

	ret:defineName('Infobox Scenery')
	ret:addClass('infobox-scenery')

	ret:addRow{
		{ tag = 'argh', content = 'name', class='infobox-header', colspan = '20' }
	}
	:pad(20)

	ret:addRow{
		{ tag = 'argd', content = 'image', class='infobox-image infobox-full-width-content', colspan = '20' }
	}
	:pad(20)

	ret:addRow{
		{ tag = 'th', content = 'Released', colspan = '6' },
		{ tag = 'argd', content = 'release', colspan = '14' }
	}

	if ret:paramDefined('aka') then
		ret:addRow{
			{ tag = 'th', content = 'AKA', colspan = '6' },
			{ tag = 'argd', content = 'aka', colspan = '14' }
		}
	end

	ret:addRow{
		{ tag = 'th', content = '[[Members]]', colspan = '6' },
		{ tag = 'argd', content = 'members', colspan = '14' }
	}
	:addRow{
		{ tag = 'th', content = '[[Quest]]', colspan = '6' },
		{ tag = 'argd', content = 'quest', colspan = '14' }
	}
	:addRow{
		{ tag = 'th', content = 'Location', colspan = '6' },
		{ tag = 'argd', content = 'location', colspan = '14' }
	}
	
	if ret:paramDefined('actions') then
		ret:addRow{
			{ tag = 'th', content = 'Actions', colspan = '6' },
			{ tag = 'argd', content = 'actions', colspan = '14' }
		}
	end

	ret:addRow{
		{ tag = 'th', content = 'Examine', colspan = '6' },
		{ tag = 'argd', content = 'examine', colspan = '14' }
	}
	:pad(20)

	if ret:paramDefined('map') and ret:param('map') ~= 'No' then
		ret:addRow{
			{ tag = 'th', content = 'Map', class = 'infobox-subheader', colspan = '20' }
		}
		:addRow{
			{ tag = 'argd', content = 'map', colspan = '20', class = 'infobox-full-width-content' }
		}
	end

	ret:addRow{
		{ tag = 'th', content = 'Advanced data', class = 'infobox-subheader', colspan = '20' },
		meta = {addClass = 'advanced-data'}
	}
	:pad(20, 'advanced-data')
	:addRow{
		{ tag = 'th', content = 'Object ID', colspan = '6' },
		{ tag = 'argd', content = 'id',  colspan = '14' },
		meta = {addClass = 'advanced-data'}
	}
	ret:pad(20, 'advanced-data')

	if onmain() then
		local a1 = ret:param('all')
		local a2 = ret:categoryData()
		ret:wikitext(addcategories(a1, a2))
	end
	return ret:tostring()
end

-- Filter non-numerical IDs and separate with splitpoint for use in SMW
-- Example: '123 ,hist234, 456' => '123&&SPLITPOINT&&456'
function idsmw(id)
	if not infobox.isDefined(id) then
		return nil
	end
	local res = {}
	for id_i in string.gmatch(id, "[^,]+") do
		local trimmed = id_i:gsub("^%s*(.-)%s*$", "%1")
		if tonumber(trimmed) then
			table.insert(res, trimmed)
		end
	end
	return table.concat(res, '&&SPLITPOINT&&')
end

function addcategories(args, catargs)
	local ret = { 'Scenery' }

 	-- Add the associated category if the parameter has content
	local defined_args = {
		aka = 'Pages with AKA'
	}
	for n, v in pairs(defined_args) do
		if catargs[n] and catargs[n].one_defined then
			table.insert(ret, v)
		end
	end

 	-- Add the associated category if the parameter doesn't have content
 	local notdefined_args = {
 		image = 'Needs image',
 		members = 'Needs members status',
 		release = 'Needs release date',
 		examine = 'Needs examine added',
 		actions = 'Needs actions',
 		id = 'Needs ID'
 	}
	for n, v in pairs(notdefined_args) do
		if catargs[n] and catargs[n].all_defined == false then
			table.insert(ret, v)
		end
	end
	
	if args['actions'] then
		if string.lower(args['actions'].d or '') == 'none' then
			table.insert(ret, 'Non-interactive scenery')
		else
			table.insert(ret, 'Interactive scenery')
		end
	end

	-- combine table and format category wikicode
	for i, v in ipairs(ret) do
		if (v ~= '') then
			ret[i] = string.format('[[Category:%s]]', v)
		end
	end

	return table.concat(ret, '')
end

return p