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+ local MAX_INDEX = infoboxdata.MAX_INDEX local MAX_TAB = infoboxdata.MAX_TAB

--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

local function additergroup(pref, sdata, parent) for count = 1,MAX_INDEX,1 do		local desc, name = (pref..'%d_desc'):format(count), (pref..'%d_name'):format(count) parent:addData{ sdata[desc], label = sdata[name] } end end

function p.infoboxCreate(frame) local args = getArgs(frame) local deftype = args.default_type -- All checkings local isNPC, isQuest, isPuzzle, isStat, isMinion 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') isStat = checkval('stat') isMinion = checkval('minion') 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,MAX_TAB,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..(name:match('%d$') and _i or i)] or default end -- table of all params for this section local s = {} local function additerdata(pref) for count = 1,MAX_INDEX,1 do					local desc, name = (pref..'%d_desc'):format(count), (pref..'%d_name'):format(count) s[desc] = argI(desc) s[name] = argI(name) or ('%s %d'):format(string.ucfirst(pref), count) end end -- 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_gallery = (argI('image') and argI('image'):match("UNIQ%-%-gallery")) and argI('image') s.image = (not s.image_gallery) and (argI('image') or not (minimalist or isStat or isMinion)) and string.wrapTag(animate.animate({ argI('image') or pagename..'.png', class='pi-image-thumbnail' }), 'center') or nil if not s.image_gallery and not s.image and isMinion then s.image_gallery = string.dedent:format(pagename,pagename) end --2			s.caption = argI('caption') or argI('imagecaption') --3			s.slot_item = argI('slot_item') or argI('slot') s.slot_item = yesno(s.slot_item, (isMinion and true or false)) and (s.slot_item or (isMinion and pagename..' I' or pagename)) or nil s.slot_item = s.slot_item and string.wrapHtml((''):format( s.slot_item, argI('slot_text') and '|text='..argI('slot_text') or '', argI('slot_title') and '|title='..argI('slot_title') or '', argI('slot_link') and '|link='..argI('slot_link') or '' ), 'center') --4			s.aka = argI('aka') --5			s.type = argI('type') or ((not minimalist) and deftype or nil) --6			s.color = argI('color') --7			s.appearance = argI('appearance') --8			s.collection = argI('collection') and (''):format(argI('collection')) --9			s.usage = argI('usage') --10			s.uses = argI('uses') --11			s.ways_to_increase = argI('ways_to_increase') --12			s.category = argI('uses') --13			s.collects = argI('collects') and (''):format(argI('collects')) --14			s.upgrade_with = argI('upgrade_with') and (''):format(argI('upgrade_with')) --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)			) --E0 s.requirements = argI('requirements') or argI('requirement') --E1 s.rewards = argI('rewards') or argI('reward') --D0+ additerdata('perk') --J0 s.default_desc = argI('default_desc') s.default_name = argI('default_name') or 'Default' --J1+ additerdata('upgrade') --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')) --K0 s.base_value = argI('base_value') --K1 s.max_value = argI('max_value') --L0 s.unlock_requirement = argI('unlock_requirement') --L1 s.max_level = argI('max_level') --M0 s.skill_special_effect = argI('skill_special_effect') --N0 s.super_compactor = isMinion and yesnoIcon(argI('super_compactor') or true) or nil --N1 s.compactor = isMinion and yesnoIcon(argI('compactor')) or nil --N2 s.auto_smelter = isMinion and yesnoIcon(argI('auto_smelter')) or nil --O0 s.ideal_layout = argI('ideal_layout') and string.wrapHtml(argI('ideal_layout'), 'center', {style = 'margin:0 auto; width:272px;'}) --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 -- P0 s.id = argI('item_id') or argI('id') -- 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 } --1|2		section:addImage{ sdata.image_gallery, caption = { sdata.caption }, source='image'..i } section:addData{ sdata.image, caption = { sdata.caption }, source='image'..i } section --4 :addData{ sdata.aka, label = 'Also known as' } --5 :addData{ sdata.type, label = 'Type' } --6 :addData{ sdata.color, label = 'Color' } --7 :addData{ sdata.appearance, label = 'Appearance' } --8 :addData{ sdata.collection, label = 'Collection' } --9 :addData{ sdata.usage, label = 'Usage' } --10 :addData{ sdata.uses, label = 'Uses' } --11 :addData{ sdata.ways_to_increase, label = 'Ways to Increase' } --12 :addData{ sdata.category, label = 'Category' } --13 :addData{ sdata.collects, label = string.makeTitle('Collects', 'Average items collected per action') } --14 :addData{ sdata.upgrade_with, label = 'Upgrade with' } :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 :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 = section:addGroup{ header = 'Perks' } --D0+ additergroup('perk', sdata, group) end do local group = section:addGroup{ header = 'Perks' } --J0 if sdata.default_desc then group:addData{ sdata.default_desc, label = sdata.default_name } end --J1+ additergroup('upgrade', sdata, group) end 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 = 'Values' } --K0 :addData{ sdata.base_value, label = 'Base value' } --K1 :addData{ sdata.max_value, label = 'Max value' } :done :addGroup{ header = 'Properties' } --L0 :addData{ sdata.unlock_requirement, label = 'Unlock Requirements' } --L1 :addData{ sdata.max_level, label = 'Skill Max Level' } :done :addGroup{ header = 'Special Effects' } --M0 :addData{ sdata.skill_special_effect, label = 'Special Effect' } :done :addGroup{ header = 'Upgrades', layout = 'horizontal', ['row-items'] = 1 } --N0 :addData{ sdata.super_compactor, label = 'Super Compactor 3000' } :done :addGroup{ layout = 'horizontal', ['row-items'] = 2 } --N1 :addData{ sdata.compactor, label = 'Compactor' } --N2 :addData{ sdata.auto_smelter, label = 'Auto Smelter' } :done :addGroup{ header = 'Ideal Layout', collapse = 'closed' } --O0 :addData{ sdata.ideal_layout } :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 :addGroup{ header = 'Item Metadata', ['row-items']=1, collapse = 'closed' } --P0 :addData{ sdata.id, label = 'Item ID' } :done end return table.concat{ ibox:preprocess, curTitle.namespace == 0 and category_to_add or '', } end

--Finish Module/Exports return p