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(table.concat{			link.potionName{ name.." I Potion", format=true, bold=true },			boost and string.wrapHtml('Boost: '..boost, 'span', { style={ float='right' } }) or '',		}, 'th', { colspan=4, style={ ['text-align']='left !important', ['border-right-width']=BMW } }), }	local row2 = { string.wrapHtml(slot{ name.." I Potion" }, 'th', { rowspan=2, style={ ['border-bottom-width']=BBW } }), string.wrapHtml(table.concat{			effect or 'Unknown effect',			(unlock or brews) and string.wrapHtml(table.concat{ unlock and string.wrapHtml('Unlock: '..unlock, 'li') or '', 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 } }), }	local row3 = {} -- 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 = 1, #pd.vars+1 do				levelVars[#levelVars+1] = pd.vars[j][i] end end local r3rowspan = 1 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 }) else r3rowspan = 2 end row3[#row3+1] = string.wrapHtml(table.concat(levelVars, ' '), 'td', { colspan=levelColSpan, rowspan=r3rowspan, style={ ['border-bottom-width']=BBW } }) 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