Module:Profession info

From Brighter Shores Wiki
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Module:Profession info/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Profession info/doc. [edit]
Module:Profession info's function main is invoked by Template:Profession info.
Module:Profession info loads data from Module:Experience/data.

require('strict')
require('Module:Mw.html extension')
local editbutton = require('Module:Edit button')
local edit = editbutton("'''?''' (edit)")
local hc = require('Module:Param Parse').has_content
local yn = require('Module:Yesno')
local qty = require('Module:Quantity box')._main
local pcp = require('Module:Profession clickpic')._main
local currency = require('Module:Currency')
local album_xp_data = mw.loadData('Module:Experience/data').album
local lang = mw.language.getContentLanguage()
local tooltip = require('Module:Tooltip')

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local albumxp = album_xp_data[tonumber(args.level)]

	if albumxp then
		albumxp = lang:formatNum(albumxp)..' xp'
	end
	
	--Checks if the recipe has been flagged as passive, defaults to no.
	local passive = yn(args.passive or 'no', false)
	local quantity = 1
	if passive then
		quantity = 0.005
	end
	
	--Checks if the recipe has been flagged as coop, defaults to no
	local coop = yn(args.coop or 'no', false)
	
	--If set to true, will hide the album xp section as the item does not give album xp.
	local hideAlbum = yn(args.hideAlbum or 'no', false)
	
	local function exparg(xp)
		if hc(xp) then
			return qty(xp)
		else
			return edit..'[[Category:Needs experience info]]'
		end
	end
		
	local function kparg(kp)
		if hc(kp) then
			return kp..' %'
		else
			return edit..'[[Category:Needs knowledge info]]'
		end
	end
	
	local function levelarg(profession, level)
		if hc(profession) and hc(level) then
			return pcp(profession, level)
		else
			return edit..'[[Category:Needs level info]]'
		end
	end
	
	local function durationarg(duration)
		if hc(duration) then
			return duration..' seconds'
		else
			return edit..'[[Category:Needs duration info]]'
		end
	end
	
	-- make a materials table for the JSON export
	-- Will need to update this if multiple inputs are ever used
	local argsMaterials = {}
	if args.input and args.input~='' then
		table.insert(argsMaterials,{ name = args.input, quantity = quantity })
	end
	if args.container and args.container~='' then
		table.insert(argsMaterials,{ name = args.container, quantity = quantity })
	end
	
	local smw_properties = {
		['Skill node name'] = args.name,
		['Uses profession'] = args.profession,
		['Profession level'] = args.level,
		['Activity XP'] = args.xp,
		['Activity album XP'] = album_xp_data[tonumber(args.level)],
		['Activity KP'] = args.kp,
		['Activity duration'] = args.duration,
		['Activity coins'] = args.coins,
		['Activity input'] = args.input,
		['Activity container'] = args.container,
		
		-- straight copy from Infobox Recipe, its good to have a standard format
		['Activity JSON'] = mw.text.jsonEncode({
			xp = args.xp and tonumber(args.xp),
			kp = args.kp and tonumber(args.kp),
			duration = args.duration and tonumber(args.duration),
			respawn = args.respawn and tonumber(args.respawn),
			coop = coop,
			tool = args.tool,
			materials = argsMaterials,
			profession = args.profession,
			passive = passive,
			coins = args.coins and tonumber(args.coins),
			level = args.level and tonumber(args.level),
			-- Make sure to update this when multiple outputs are supported
			output = {
				{ name = args.name, quantity = quantity },
			}
		})
	}
	mw.smw.set(smw_properties)
	
	local out = mw.html.create('table')
		:addClass('wikitable')
		:tag('tr')
			:tag('th')
				:attr{ colspan = '2' }
				:wikitext(args.name)
				:IF(coop)
					:wikitext(' (Co-op)')
				:END()
			:done()
		:done()
		:tag('tr')
			:tag('th')
				:wikitext('Level required')
			:done()
			:tag('td')
				:wikitext(levelarg(args.profession, args.level))
			:done()
		:done()
		:tag('tr')
			:tag('th')
				:IF(passive)
					:wikitext('[[File:Passive small icon.png|20x20px|link=Passive Activity]] [['..args.profession..'|'..args.profession..' XP]] ')
					:node(tooltip._span{ 'passive' })
					:node(tooltip._div{ name = 'passive', content = 'Passive activities give reduced experience when a players level is high enough to perform a new passive activity for that profession. The number shown here is the full experience.' })
				:ELSE()
					:wikitext('[['..args.profession..'|'..args.profession..' XP]]')
				:END()
			:done()
			:tag('td')
				:wikitext(exparg(args.xp))
			:done()
		:done()
		:IF(not hideAlbum)
			:tag('tr')
				:tag('th')
					:wikitext('[[Album|Album XP]] ')
					:node(tooltip._span{ 'album' })
					:node(tooltip._div{ name = 'album', content = 'Album XP is a bonus awarded once for the first time the activity is performed.' })
				:done()
				:tag('td')
					:wikitext(albumxp or 'Unknown')
				:done()
			:done()
		:END()
		:tag('tr')
			:tag('th')
				:wikitext('Duration')
			:done()
			:tag('td')
				:wikitext(durationarg(args.duration))
			:done()
		:done()
		:IF(not passive)
			:tag('tr')
				:tag('th')
					:wikitext('[[Knowledge]]')
				:done()
				:tag('td')
					:wikitext(kparg(args.kp))
				:done()
			:done()
		:END()
	
	if hc(args.respawn) then
		out
			:tag('tr')
				:tag('th')
					:wikitext('Respawn time')
				:done()
				:tag('td')
					:wikitext(durationarg(args.respawn))
				:done()
			:done()
	end
	
	if hc(args.tool) then
		out
			:tag('tr')
				:tag('th')
					:wikitext('Required tool')
				:done()
				:tag('td')
					:wikitext('[[' .. args.tool.. ']]')
				:done()
			:done()
	end
	
	if hc(args.input) then
		out
			:tag('tr')
				:tag('th')
					:wikitext('Required input')
				:done()
				:tag('td')
					:wikitext('[[' .. args.input .. ']]')
				:done()
			:done()
	end
	
	if hc(args.container) then
		out
			:tag('tr')
				:tag('th')
					:wikitext('Required container')
				:done()
				:tag('td')
					:wikitext('[[' .. args.container .. ']]')
				:done()
			:done()
	end
	
	if hc(args.coins) then
		out
			:tag('tr')
				:tag('th')
					:wikitext('Coins')
				:done()
				:tag('td')
					:wikitext(currency.parse(args.coins))
				:done()
			:done()
	end
	
	return out
end

return p