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 boost = args['boost'] 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, boost, effect, unlock, brews, basePotion, levels) end function p._potionPageRow(name, boost, effect, unlock, brews, basePotion, levels) name = potionAliases[name:lower] local pd = potionData[name] if not pd then return unknownDisplay; end local t = {} local BMW, BBW = '3px', '5px' local levelColSpan = levelsColumnLcm / (basePotion and pd.maxLevel+1 or pd.maxLevel) -- Basic Row Data local row1 = { string.wrapHtml{ tag='th', attrs={ colspan=4, style={ ['text-align']='left !important', ['border-right-width']=BMW } }, text=string.wrapHtml{ tag='div', attrs={ style={ display='flex', gap='4px' } }, text=table.concat{ link.potionName{ name.." I Potion", format=true, bold=true }, string.wrapHtml(table.concat{						'Unlock: ',						string.wrapHtml((unlock or 'Initially Available'), 'span', { style={ ['font-weight']='normal' } })					}, 'span', { style={ flex=1, ['text-align']='right' } }) or '', }			}		},		string.wrapHtml('Levels', 'th'), }	local row2 = { string.wrapHtml(slot{ name.." I Potion" }, 'th', { rowspan=2, style={ ['border-bottom-width']=BBW } }), string.wrapHtml(table.concat{			effect or 'Unknown effect',			brews and string.wrapHtml(table.concat{ brews and string.wrapHtml('Brews: '..brews, 'li') or '', }, 'ul') or ''		}, 'td', { colspan=3, rowspan=2, style={ ['text-align']='left', ['border-right-width']=BMW, ['border-bottom-width']=BBW } }), (pd.ingredients			and string.wrapHtml('Ingredients', 'th')			or string.wrapHtml(boost or 'Stats', 'th', { rowspan=2, style={ ['border-bottom-width']=BBW } })), }	local row3 = { (pd.ingredients and string.wrapHtml(boost or 'Stats', 'th', { style={ ['border-bottom-width']=BBW } }) or '') }	-- Add level data to rows local lastLevelWithItem = 0 for i = 1, pd.maxLevel do		row1[#row1+1] = string.wrapHtml(LEVEL_ROMANS[i], 'th', { colspan=levelColSpan }) local levelVars = {} if pd.vars then for j, varList in pairs(pd.vars) do				levelVars[#levelVars+1] = varList[i] end end -- 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[#row2+1] = string.wrapHtml(ingredient or '?', 'td', { colspan=levelColSpan }) row3[#row3+1] = string.wrapHtml(table.concat(levelVars, ' '), 'td', { colspan=levelColSpan, style={ ['border-bottom-width']=BBW } }) else -- show row 3 as row two with rowspan=2 row2[#row2+1] = string.wrapHtml(table.concat(levelVars, ' '), 'td', { colspan=levelColSpan, rowspan=2, style={ ['border-bottom-width']=BBW } }) end end -- create rows t[#t+1] = string.wrapHtml(table.concat(row1), 'tr') t[#t+1] = string.wrapHtml(table.concat(row2), 'tr', { class='centertext' }) t[#t+1] = string.wrapHtml(table.concat(row3), 'tr', { class='centertext' }) return table.concat(t) end

return p