Module:Sandbox/Fewfre

local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader') local string, table, yesno, uitext, inventoryslot, link = loader.require('String', 'Table', 'Yesno', 'UIText', 'Inventory slot', 'Link') local potionData, potionAliases = loader.loadData('Potion/Data', 'Potion/Aliases')

local p = {} local slot = inventoryslot.slot local unknownDisplay = '&r&f&l???&r' local levelsColumnLcm = 2520 -- smallest number evenly divisible by all number before / including 10 local LEVEL_ROMANS = { 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' } local potionPageRowLevelBoosters = { string.wrapHtml('+', 'span', { style={ opacity=0.5 } }), string.wrapHtml('+', 'span', { style={ opacity=0.5 } }), string.wrapHtml('+', 'span', { style={ opacity=0.5 } }), }

function p.potionPageRow(frame) local args = getArgs(frame) local name = args['name'] local varnames = args['varnames'] local effect = args['effect'] local unlock = args['unlock'] local brews = args['brews'] local basePotion = args['basePotion'] local levels = nil--mapNamedArgs(args, 'levels') return p._potionPageRow(name, varnames, effect, unlock, brews, basePotion, levels) end function p._potionPageRow(name, varnames, effect, unlock, brews, basePotion, levels) name = potionAliases[name:lower] local pd = potionData[name] if not pd then return unknownDisplay; end local t = {} local BRDR_MID = { ['border-right-width']='3px' } local BRDR_BTM = { ['border-bottom-width']='5px' } local BMW, BBW = '3px', '5px' local levelColSpan = levelsColumnLcm / (basePotion and pd.maxLevel+1 or pd.maxLevel) -- Basic Row Data local row1 = mw.html.create('tr'):attr{ id=name } :tag('th'):attr{ rowspan=3 }:css{ ['max-width']=0 }:done :tag('th'):attr{ colspan=4 }:css{ ['text-align']='left !important' }:css(BRDR_MID) :tag('div'):css{ display='flex', gap='4px' } :wikitext( link.potionName{ name.." I Potion", format=true, bold=true } ) :tag('span'):css{ flex=1, ['text-align']='right' } :tag('b'):wikitext('Unlock: '):done :tag('span'):wikitext( unlock or 'Initially Available' ):css{ ['font-weight']='normal' }:done :done :done :done local row2 = mw.html.create('tr'):addClass('centertext'):css{ height='100%' }--100% height needed for cell contents to use 100% height :tag('th'):wikitext( slot{ name.." I Potion" } ):attr{ rowspan=2 }:css(BRDR_BTM):done :tag('td'):attr{ colspan=3, rowspan=2 }:css{ ['text-align']='left' }:css(BRDR_MID):css(BRDR_BTM):css{ height='100%' }--100% height needed for cell contents to use 100% height :tag('div'):css{ display='flex', ['flex-direction']='column' }:css{ height='100%' }--100% height needed for cell contents to use 100% height :tag('div'):css{ flex=1 } -- this flex pushes the varnames text down (if there is any) :wikitext(effect or 'Unknown effect') :wikitext(						brews and string.wrapHtml(table.concat{ brews and string.wrapHtml('Brews: '..brews, 'li') or '', }, 'ul') or ''					) :done :wikitext( varnames and string.wrapHtml(table.concat{ '(in ', varnames, ')' }, 'div', { style={ ['text-align']='right', ['font-style']='italic' } }) or '' ) :done :done local row3 = mw.html.create('tr'):addClass('centertext') -- Add level data to rows local lastLevelWithItem = 0 for i = 1, pd.maxLevel do		row1:tag('th'):wikitext( LEVEL_ROMANS[i] ):attr{ colspan=levelColSpan } local levelVars = {} if pd.vars then for j, varList in pairs(pd.vars) do				levelVars[#levelVars+1] = varList[i] end end levelVars = table.concat(levelVars, ' ') -- If ingredients exist, show them; if not, then only list the stats if pd.ingredients then local ingredient = nil if pd.ingredients[i] then ingredient = slot{ pd.ingredients[i] } lastLevelWithItem = i			elseif pd.ingredients[i..'text'] then ingredient = pd.ingredients[i..'text'] lastLevelWithItem = i			else ingredient = potionPageRowLevelBoosters[i-lastLevelWithItem] end row2:tag('td'):wikitext( ingredient or '?' ):attr{ colspan=levelColSpan } row3:tag('td'):wikitext( levelVars ):attr{ colspan=levelColSpan }:css(BRDR_BTM):css{ ['line-height']=1.3 } else -- show row 3 as row two with rowspan=2 row2:tag('td'):wikitext( levelVars ):attr{ colspan=levelColSpan, rowspan=2 }:css(BRDR_BTM):css{ ['line-height']=1.3 } end end return table.concat{ tostring(row1), tostring(row2), tostring(row3) } end

return p