Module:Infobox/Mechanic

--Get Required Modules local loadLib = require('Module:LoadLib')

loadLib(_G, {	infobox = 'Infobox',	templates = 'String/Templates',	{'Minimap', values = {			'getMinimapForInfobox',	}},	animate = 'Animate', })

mw.html.create = require('Module:Html').create local curTitle = mw.title.getCurrentTitle

--Begin Exports local p = {} local yesIcon, noIcon, unknownIcon = templates.yes(1), templates.no(1), templates.unknown(1)

local function yesnodefault(val, yes, no, def) if tostring(val):sub(1, 1) == 'u' then return unknownIcon end local bool = yesno(val); if bool == nil then return def or val elseif bool then return yes else return no	end end

local function yesnoIcon(val, def) return yesnodefault(val, yesIcon, noIcon, def) end

function p.infoboxCreate(frame) local args = getArgs(frame) local deftype = args.default_type -- All checkings local isNPC, isQuest do local function checkval(v) return (deftype or ''):lower:match(v) and true or false end isNPC = checkval('npc') or checkval('character') isQuest = checkval('quest') end local minimalist = isQuest and true local pagename = curTitle.text or 'Diamond' local title = args.title or ((not minimalist) and pagename or nil) local category_to_add = args.category_to_add or '' local sections = {} for j = 1,16,1 do		local function argJ(name, default) return args[name..j] or default end local sectionExists = j==1 or argJ('tab') if sectionExists then -- section one does have numbers after params; on 2+ do that local i = j==1 and  or j			local _i = j==1 and  or '_'..j -- needed for when a param ends in a number naturally local function argI(name, default) return args[name..i] or default end -- table of all params for this section local s = {} -- Top level infobox values --0			s.tab = argJ('tab') or argI('tab') -- purposefully use 'j' here since default section does actually use 'tab1' --1			s.image = (not minimalist) and string.wrapTag(animate.animate({ argI('image') or pagename..'.png', class='pi-image-thumbnail' }), 'center') --2			s.caption = argI('caption') or argI('imagecaption') --3			s.aka = argI('aka') --4			s.type = argI('type') or deftype or 'Item' --5			s.color = argI('color') --D0 for count = 1,10,1 do				local desc, name = ('perk%d_desc'):format(count), ('perk%d_name'):format(count) if argI(desc) then s[desc] = argI(desc) s[name] = argI(name) else break end end --E0 s.requirements = argI('requirements') or argI('requirement') --E1 s.rewards = argI('rewards') or argI('reward') --A0 s.xyz = argI('x') and (' %s  %s  %s  '):format(argI('x'), argI('y') or , argI('z') or ) s.xyz = s.xyz and string.wrapHtml(s.xyz, 'table', { style = 'width:100%; table-layout:fixed; text-align:center;' }) --A1 s.coordinates = argI('coordinates') --A2 s.location = argI('location') and (''):format(argI('location')) --A3 s.start_location = argI('start_location') and (''):format(argI('start_location')) --A4 s.start_npc = argI('start_npc') and (''):format(argI('start_npc')) --B0 s.quests = argI('quests') --B1 s.shop = yesnoIcon(argI('shop')) if isNPC then --C0 s.minimap = getMinimapForInfobox{ argI('location'), x=argI('x'), z=argI('z') } end -- Push section data into array sections[#sections+1] = s		end end -- Make infobox local ibox = infobox.create ibox:addTitle{ title } local panel = ibox:addPanel for i,sdata in ipairs(sections) do		local section = --0panel:addSection{ label = sdata.tab } section --1|2:addData{ sdata.image, caption = { sdata.caption }, source='image'..i } --3 :addData{ sdata.aka, label = 'Also known as' } --4 :addData{ sdata.type, label = 'Type' } --5 :addData{ sdata.color, label = 'Color' } --D0 do local group = section:addGroup{ header = 'Perks' } for count = 1,10,1 do				local desc, name = ('perk%d_desc'):format(count), ('perk%d_name'):format(count) if sdata[desc] then group:addData{ sdata[desc], label = sdata[name] } else break end end end section:addGroup --E0 :addData{ sdata.requirements, label = 'Start Req.' } --E1 :addData{ sdata.rewards, label = 'Reward' } :done :addGroup{ header = (not minimalist) and 'Location' or '' } --A0 :addData{ sdata.xyz, label = string.wrapHtml(' Coordinates', 'span', { style = 'white-space:nowrap; vertical-align: middle;' })} --A1 :addData{ sdata.coordinates, label = ' Coordinates' } --A2 :addData{ sdata.location, label = 'Location' } --A3 :addData{ sdata.start_location, label = 'Start Location' } --A4 :addData{ sdata.start_npc, label = 'Start NPC' } :done :addGroup{ header = 'Player interactions' } --B0 :addData { sdata.quests, label = 'Quests' } --B1 :addData { sdata.shop, label = 'Shop' } :done :addGroup{ header = 'Minimap (at Coordinates)', collapse = 'open' } --C0 :addData { sdata.minimap } :done end return table.concat{ ibox:preprocess, curTitle.namespace == 0 and category_to_add or '', } end

--Finish Module/Exports return p