Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:InfoboxWorkstation

From Vault Hunters Official Wiki

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

local p = {}

local function getImage(frame, baseName)
	local png = 'File:' .. baseName .. '.png'
	local gif = 'File:' .. baseName .. '.gif'

	local existsPng = frame:preprocess('{{#ifexist:' .. png .. '|yes|no}}')
	if existsPng == 'yes' then return png end

	local existsGif = frame:preprocess('{{#ifexist:' .. gif .. '|yes|no}}')
	if existsGif == 'yes' then return gif end

	return nil
end

function p.main(frame)
	local args = frame:getParent().args
	local title = mw.title.getCurrentTitle().text

	local name = args.name or title
	local baseImageName = args.image or ('Invicon_' .. title)
	local imageFile = getImage(frame, baseImageName)
	local questbook = args.questbook or 'Unknown'
	local version = args.version or 'Unknown'

	-- Extract crafting table arguments
	local craftArgs = {}
	local hasInput = false
	local hasOutput = args.Output and args.Output ~= ''

	for k, v in pairs(args) do
		if type(k) == "string" and mw.ustring.match(k, '^[ABC][123]$') and v and v ~= '' then
			craftArgs[k] = v
			hasInput = true
		end
	end

	if hasOutput then
		craftArgs["Output"] = args.Output
	end

	local html = mw.html.create('table')
	html
		:addClass('infobox')
		:addClass('infobox-workstation')
        :cssText('width:300px; float:right;')
		:tag('tr')
			:tag('th')
				:attr('colspan', '2')
				:cssText('text-align:center; font-size:1.25em; background:#ddd;')
				:wikitext(name)
			:done()
		:done()

	-- Main block image
	html
		:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:wikitext(imageFile and ('[[' .. imageFile .. '|center|frameless|128px]]') or 'No image available')
			:done()
		:done()

	-- Inventory slot under image
	html
		:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:wikitext(frame:expandTemplate{title = 'Inventory slot', args = {title}})
			:done()
		:done()

	-- Crafting recipe header and grid
	if hasInput and hasOutput then
		html
			:tag('tr')
				:tag('th')
					:attr('colspan', '2')
					:cssText('text-align:center; background:#eee;')
					:wikitext('Crafting Recipe')
				:done()
			:done()
			:tag('tr')
				:tag('td')
					:attr('colspan', '2')
					:css('text-align', 'center')
					:wikitext(frame:expandTemplate{title = 'Crafting table', args = craftArgs})
				:done()
			:done()
	end

	-- Quest book and version
	html
		:tag('tr')
			:tag('td'):wikitext('Quest Book'):done()
			:tag('td'):wikitext(questbook):done()
		:done()
		:tag('tr')
			:tag('td'):wikitext('Added in'):done()
			:tag('td'):wikitext(version):done()
		:done()

	return tostring(html)
end

return p