![]() |
VOOZH | about |
This module implements common UI templates, to avoid overhead from excessive #invoke calls.
{{Crafting Table}}{{Furnace}}{{Brewing Stand}}{{Stonecutter}}{{Loom}}{{Smithing Table}}{{Legacy Smithing Table}}localmoduleSlot=require([[Module:Inventoryslot]]) localslot=moduleSlot.slot localp={} localfunctionaddSlot(args,item,prefix,class,default) localnone,nostacksize prefix=prefixor'' if#prefix==0then none='none' nostacksize=((item==''ornil)and'')or(argsandargs[item]andargs[item]:gsub('[,%d]','')or'') end returnslot{ nostacksizeorargs[item],mod=args.Mod,link=noneorargs[prefix..'link'], title=noneorargs[prefix..'title'],class=class,default=default, parsed=args.parsed } end localfunctionexperience_class(exp_value) localMINMAX={ {-32768,2}, {3,6}, {7,16}, {17,36}, {37,72}, {73,148}, {149,306}, {307,616}, {617,1236}, {1237,2476}, {2477,32767} } localEXP_IMGS={ "xp-2", "xp-6", "xp-16", "xp-36", "xp-72", "xp-148", "xp-306", "xp-616", "xp-1236", "xp-2476", "xp-32767", } localn=assert(tonumber(exp_value),"Module:UI: Experience value is not a number ("..exp_value..")") localidx,exp=2,tonumber(exp_value) ifexp<=MINMAX[#MINMAX][2]then fori=1,#MINMAXdo ifMINMAX[i][1]<expandMINMAX[i][2]>=expthen idx=i break end end end returntostring(EXP_IMGS[idx]) end -- Crafting table functionp.craftingTable(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Crafting_Table pixel-image') localinput=body:tag('span'):addClass('mcui-input') fornum=1,3do localrow=input:tag('span'):addClass('mcui-row') for_,letterinipairs{'A','B','C'}do row:wikitext(addSlot(args,letter..num,letter..num)) end end localarrow=body:tag('span'):addClass('mcui-arrow'):tag('br'):done() body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) localshapeless=args.shapelessor'' localfixed=args.fixedor'' ifshapeless~=''orfixed~=''then localicon=body:tag('span') :addClass('mcui-icons') :tag('span') :tag('br') :done() ifshapeless~=''then icon:addClass('mcui-shapeless') :attr('title', 'This recipe is shapeless; the inputs may be placed in any arrangement in the crafting grid.' ) elseiffixed~=''then localnotFixed=args.notfixedor'' localexceptFixed='' ifnotFixed~=''then exceptFixed='; except for '..notFixed..', which can go anywhere' end icon:addClass('mcui-fixed') :attr('title', 'This recipe is fixed; the input arrangement may not be moved or mirrored in the crafting grid'..exceptFixed..'.' ) end end returntostring(mw.html.create('div'):node(body)) end -- Furnace functionp.furnace(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Furnace pixel-image') localinput=body:tag('span'):addClass('mcui-input') input:wikitext(addSlot(args,'Input','I')) localfuel=input:tag('span'):addClass('mcui-fuel'):tag('br'):done() localburning=args.Inputor''~=''andargs.Fuelor''~='' ifnotburningthen fuel:addClass('mcui-inactive') end input:wikitext(addSlot(args,'Fuel','F')) localarrow=body:tag('span'):addClass('mcui-arrow'):tag('br'):done() ifnotburningor(args.Outputor'')==''then arrow:addClass('mcui-inactive') end body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) args.Experience=args.Experienceor'' ifargs.Experience~=''then -- Converts commas to dots, removes all spaces and splits the arguments with semicolon. localsplit=mw.text.split(string.gsub(args.Experience,'[ ,]',{[' ']='',[',']='.'}),';',true) localanimated=body:tag('span') :attr('title','XP reward. If there is a fractional part, it means the recipe has a chance equal to the fractional part of rewarding an additional XP point.') :addClass('animated mcui-experience') localisNotFirst=true fori,vinipairs(split)do localxp=tonumber(v) assert(xp,'Module:UI: "'..v..'" is not a valid number') localxpWrapper=animated:tag('span') :addClass(isNotFirstand'animated-active'ornil) xpWrapper:tag('span') :addClass(experience_class(xp)..' mcui-experience-orb') xpWrapper:tag('span') :addClass('mcui-experience-text') :wikitext((' 'andxp>72or'')..xp) isNotFirst=false end end returntostring(mw.html.create('div'):node(body)) end -- Brewing Stand functionp.brewingStand(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Brewing_Stand pixel-image') localinput=body:tag('span'):addClass('mcui-input') input:tag('span'):addClass('mcui-bubbling'):tag('br') input:wikitext(addSlot(args,'Input','I')) input:tag('span'):addClass('mcui-arrow'):tag('br') if(args.Inputor'')==''or ((args.Output1or'')==''and(args.Output2or'')==''and(args.Output3or'')=='') then input:addClass('mcui-inactive') end body :tag('span') :addClass('mcui-paths') :tag('br') if((args.Base1or'')~=''or(args.Base2or'')~=''or(args.Base3or'')~='')then localbase=body:tag('span'):addClass('mcui-base') localarrows=body:tag('span'):addClass('mcui-arrowDown') fori=1,3do base:wikitext(addSlot(args,'Base'..i,'B'..i,'mcui-base'..i)) arrows:tag('span'):addClass('mcui-arrowDown'..i):tag('br') end end localoutput=body:tag('span'):addClass('mcui-output') fori=1,3do output:wikitext(addSlot(args,'Output'..i,'O'..i,'mcui-output'..i)) end returntostring(mw.html.create('div'):node(body)) end -- Stonecutter functionp.stonecutter(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Stonecutter pixel-image') localinput=body:tag('span'):addClass('mcui-input') input:wikitext(addSlot(args,'Input','I')) localarrow=body:tag('span'):addClass('mcui-stonecutterArrow') arrow:wikitext(addSlot(args,'Output','','invslot-plain mcui-stonecutterSprite')) body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) returntostring(mw.html.create('div'):node(body)) end -- Loom functionp.loom(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Loom pixel-image') localtapestry=body:tag('span'):addClass('mcui-tapestry') ifargs.Bannerand#args.Banner>0then tapestry:wikitext(addSlot(args,'Banner','B','mcui-inputBanner')) end ifargs.Dyeand#args.Dye>0then tapestry:wikitext(addSlot(args,'Dye','D','mcui-inputDye')) end ifargs.Patternand#args.Pattern>0then tapestry:wikitext(addSlot(args,'Pattern','P','mcui-inputPattern')) end tapestry:tag('span'):tag('br'):done() localarrow=body:tag('span'):addClass('mcui-loomArrow') localbannerSprite ifargs.Spriteand#args.Sprite>0then localanimate=require([[Module:AnimateSprite]]).animate bannerSprite=animate{ args.Sprite, name='SlotSprite' } else bannerSprite='<br>' end arrow :tag('span') :addClass('mcui-bannerSprite') :wikitext(bannerSprite) body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) returntostring(mw.html.create('div'):node(body)) end -- Grindstone functionp.grindstone(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Grindstone pixel-image') localgrindstone=body:tag('span'):addClass('mcui-grindstone') grindstone:wikitext(addSlot(args,'Input1','I1','mcui-input1')) grindstone:wikitext(addSlot(args,'Input2','I2','mcui-input2')) localarrow=body:tag('span'):addClass('mcui-arrow') body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) returntostring(mw.html.create('div'):node(body)) end -- Smithing Table functionp.smithing(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Smithing_Table pixel-image') localsmithingTable=body:tag('span'):addClass('mcui-smithingTable') smithingTable:wikitext(addSlot(args,'Input1','I1','mcui-input1')) smithingTable:wikitext(addSlot(args,'Input2','I2','mcui-input2')) smithingTable:wikitext(addSlot(args,'Input3','I3','mcui-input3')) localarrow=body:tag('span'):addClass('mcui-arrow') arrow:cssText([[display:inline-block; width:44px; height:30px; margin:3px18px; vertical-align:top;]]) ifargs.crossedthen arrow:addClass('mcui-inactive') end body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot')) returntostring(mw.html.create('div'):node(body)) end -- Anvil functionp.anvil(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Anvil pixel-image') localhammer=body:tag('span'):addClass('mcui-hammer') hammer:cssText([[display:block; width:60px; height:60px;]]) localinputbox=body:tag('span'):addClass('mcui-Anvil-inputbox mcui-input') localitemName=mw.text.trim(args.titleor'') ifitemName~=''then -- Manual title override itemName=itemName:gsub(';',',,') elseifargs.Input1and#args.Input1>0then -- Extract the item names from the first input slot. -- The name for each item either -- 1) the overridden title (in square brackets) or -- 2) the item name without "Damaged" prefix. itemName={} ifargs.parsedthen -- pre-parsed slot parameters, args.Input1 is a table for_,slotinipairs(args.Input1)do ifslot[1]then error("Slot subframes are not supported by the anvil UI") end table.insert(itemName,slot.titleorslot.name:gsub(moduleSlot.i18n.prefixes.damaged..' ','')) end else for_,slotinipairs(moduleSlot.splitOnUnenclosedSemicolons(args.Input1))do localslotTitle=slot:match('%[([%w%s]-)%][%w%s]+') ifnotslotTitlethen slotTitle=slot:gsub(moduleSlot.i18n.prefixes.damaged..' ','') end table.insert(itemName,slotTitle) end end end ifitemName~=''then itemName=require([[Module:AnimateText]]).animate{itemName}:gsub('class="animated"','class="mcui-Anvil-inputtext animated"') else inputbox:addClass('mcui-inactive') itemName='<br>' end inputbox:wikitext((itemName)) localanvilA=body:tag('span'):addClass('mcui-anvil'):css('margin-left','18px') anvilA:wikitext(addSlot(args,'Input1','I1','mcui-input1')) localplus=body:tag('span'):addClass('mcui-plus') plus:cssText([[display:inline-block; width:26px; height:26px; margin:6px18px; vertical-align:top;]]) localanvilB=body:tag('span'):addClass('mcui-anvil') anvilB:wikitext(addSlot(args,'Input2','I2','mcui-input2')) localarrow=body:tag('span'):addClass('mcui-arrow') arrow:cssText([[display:inline-block; width:44px; height:30px; margin:4px18px; vertical-align:top;]]) ifargs.crossedthen arrow:addClass('mcui-inactive') end body :tag('span') :addClass('mcui-output') :css('margin-right','18px') :wikitext(addSlot(args,'Output','O','invslot')) ifargs.costthen localcost=body:tag('span'):addClass('mcui-Anvil-cost') ifargs.expensivethen cost:addClass('mcui-Anvil-cost-expensive') else cost:addClass('mcui-Anvil-cost-normal') end ifargs.cost=='expensive'then cost:wikitext('Too expensive') else cost:wikitext('Enchantment Cost: '..args.cost) end end localwrapper=mw.html.create('div') wrapper:wikitext(require([[Module:TSLoader]]).call("Anvil/styles.css")) returntostring(wrapper:node(body)) end functionp.legacySmithing(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Smithing_Table pixel-image') localsmithingA=body:tag('span'):addClass('mcui-smithingTable') smithingA:wikitext(addSlot(args,'Input1','I1','mcui-input1')) localplus=body:tag('span'):addClass('mcui-plus') plus:cssText([[display:inline-block; width:26px; height:26px; margin:6px18px; vertical-align:top;]]) localsmithingB=body:tag('span'):addClass('mcui-smithingTable') smithingB:wikitext(addSlot(args,'Input2','I2','mcui-input2 invslot-default-smithing')) localarrow=body:tag('span'):addClass('mcui-arrow') arrow:cssText([[display:inline-block; width:44px; height:30px; margin:4px18px; vertical-align:top;]]) ifargs.crossedthen arrow:addClass('mcui-inactive') end body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot')) returntostring(mw.html.create('div'):node(body)) end functionp.cartography(f) localargs=f iff==mw.getCurrentFrame()then args=f:getParent().args else f=mw.getCurrentFrame() end localbody=mw.html.create('span'):addClass('mcui mcui-Cartography_Table pixel-image') localinput=body:tag('span'):addClass('mcui-input') input:wikitext(addSlot(args,'Input1','I1')) localplus=input:tag('span'):addClass('mcui-plus'):tag('br'):done() input:wikitext(addSlot(args,'Input2','I2')) localarrow=body:tag('span'):addClass('mcui-arrow'):tag('br'):done() body :tag('span') :addClass('mcui-output') :wikitext(addSlot(args,'Output','O','invslot-large')) returntostring(mw.html.create('div'):node(body)) end returnp