Module:Infobox/Mechanic

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

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

mw.html.create = require('Module:Html').create local curTitle = mw.title.getCurrentTitle local allstats = infoboxdata.allstats --G1+

--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, isPuzzle 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') isPuzzle = checkval('puzzle') end local minimalist = (isQuest or isPuzzle) 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 = (argI('image') or 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 (minimalist and deftype or nil) --5			s.color = argI('color') --I0 do local d = argI('dungeon') s.dungeon = d and (					(d == 'c' or d == 'cat' or d == 'catacombs' or d == 'the_catacombs')					and 'The Catacombs'					or ' Invalid dungeon name '				) end --I1 s.floor = argI('floor') --I2 s.boss = argI('boss') --I3 s.status = argI('status') --I4 s.dungeon_size = argI('dungeon_size') --I5 s.party_size = argI('party_size') --I6 s.required_combat_level = argI('required_combat_level') --I7 s.required_catacombs_level = argI('required_catacombs_level') --I8 s.reqs = argI('reqs') --I9 s.base_xp = argI('base_xp') --I10 s.failable = yesnoIcon(argI('failable')) --F0 s.level = argI('level') --F1 s.damage_deals = argI('damage_deals') --F2 s.damage_resistance = argI('damage_resistance') --F3 s.spawn_location = argI('spawn_location') and (''):format(argI('spawn_location')) --F4 s.spawn_condition = argI('spawn_condition') --F5 s.special = argI('special') --F6 s.special_behavior = argI('special_behavior') --F7 local ee = argI('effective_enchant') s.effective_enchant = ee and (				(ee == 'none' or ee == 'no' or ee == 'n') and 'None'				or (''):format(ee)			) --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') --G0 s.stats = argI("stats") --G1+ table.each(table.keys(allstats), function(ln)				s[ln] = argI(ln)			end) --H0 s.drops = argI('drops') and (''):format(argI('drops')) --H1 s.xp = argI('xp') and (''):format(argI('xp')) --H2 s.coins = argI('coins') and (''):format(argI('coins')) --H3 s.essence = argI('essence') and (''):format(argI('essence')) --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' } :addGroup --I0 :addData{ sdata.dungeon, label = 'Dungeon' } --I1 :addData{ sdata.floor, label = 'Dungeon Floor' } --I2 :addData{ sdata.boss, label = 'Boss' } --I3 :addData{ sdata.status, label = 'Status' } --I4 :addData{ sdata.dungeon_size, label = 'Dungeon Size' } --I5 :addData{ sdata.party_size, label = 'Party Size' } --I6 :addData{ sdata.required_combat_level, label = 'Required Level' } --I7 :addData{ sdata.required_catacombs_level, label = 'Required Level' } --I8 :addData{ sdata.reqs, label = 'Requirements to enter' } --I9 :addData{ sdata.base_xp, label = 'Base XP' } --I10:addData{ sdata.failable, label = 'Failable' } :done --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 --F0 :addData{ sdata.level, label = 'Level' } --F1 :addData{ sdata.damage_deals, label = 'Damage Deals' } --F2 :addData{ sdata.damage_resistance, label = 'Damage Resistance' } --F3 :addData{ sdata.spawn_location, label = 'Spawn Location' } --F4 :addData{ sdata.spawn_condition, label = 'Spawn Condition' } --F5 :addData{ sdata.special, label = 'Special' } --F6 :addData{ sdata.special_behavior, label = 'Special Behavior' } --F7 :addData{ sdata.effective_enchant, label = string.makeTitle('Effective Enchant', 'The weapon enchant that is most effective for killing this mob') } :done :addGroup --E0 :addData{ sdata.requirements, label = 'Start Req.' } --E1 :addData{ sdata.rewards, label = 'Reward' } :done do local group_ group_ = section:addGroup{ header = 'Stats', name = 'infobox-stats-list' } --G0 group_:addData{ sdata.stats } table.each(table.keys(allstats), function(ln)				--G1+group_:addData{ sdata[ln], label = makeStat(ln, nil, true) }			end) end section:addGroup{ header = 'Drops' } --H0:addData{ sdata.drops, label = 'Possible Drops' } --H1:addData{ sdata.xp, label = 'XP' } --H2:addData{ sdata.coins, label = '' } --H2:addData{ sdata.essence, label = 'Essence' } :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