Module:Sandbox/Fewfre

-- Initially taken from: https://minecraft.gamepedia.com/Module:Inventory_slot

local p = {}

function p.test return 'hi' end

function p.test2 require(Module:Item) return 'hi2' end

function p.test3 local item = require(Module:Item) return 'hi3 - '..item._sellPrice('wheat') end

local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs local string, table, yesno, mctxt, rarity = loader.require('String', 'Table', 'Yesno', 'Mctxt', 'RarityTier') local link, skillname = loader.require('Link', 'Skillname') local enchData = loader.require('Enchantment/Data')

--- -- Generates multiple rows needed for a single potion on Potions page -- Invoked by Template:PotionPageRow --- function p.enchantmentPageRow(frame) local args = getArgs(frame) local name = args[1] local affects = args['affects'] local desc = args['desc'] local source = args['source'] return p._enchantmentPageRow(name, affects, desc, source) end function p._enchantmentPageRow(enchantName, affects, desc, source) local ench = enchData[enchantName] if not ench then return string._error('Invalid enchantment name \"' .. enchantName .. '\"') end local sourceMap = nil if source then sourceMap = {} source = string.parseTextList( source, '*' ) for i = 1, #source do			local numsAndData = string.split(source[i], '%s*~%s*') if #numsAndData == 1 then -- If source is just a string with no tier/span data, then just make it take up whole thing sourceMap[1] = { ench.max, numsAndData[1] } else local nums, str = numsAndData[1], numsAndData[2] local tierAndSpan = string.split(nums, 'span') local tier, span = tonumber(tierAndSpan[1]), tonumber(tierAndSpan[2]) sourceMap[tier] = { span or 1, str } end end end if affects then affects = table.concat(string.parseTextList( affects, '*' ), ', ') end -- Basic Row Data local introTable = mw.html.create('table'):addClass('wikitable') :css{ height="100%" } -- This and other 100% on lable elements below are required for 100% height to work inside the description cell local row1 = introTable:tag('tr'):css{ height="35px" } local temp = row1:attr{ id=enchantName }:addClass('article-row-main') -- max width added purely for stylistic reasons on wider table :tag('th'):attr{ colspan=2 }:css{ ['text-align']='left !important' } :tag('div'):css{ display='flex', gap='16px' } :tag('div') :wikitext( link.enchantmentsLink{ enchantName } ) :done if ench.req and ench.req > 0 then -- note: parent div hasn't been `done` yet, so `temp` here is adding it to the parent div, not the row or cell - basically this just acts as a continuation temp:tag('span'):css{ flex=1, ['text-align']='right' } :tag('b'):wikitext(table.concat{ skillname.getSkillName{ 'enchanting', short=true }, ' Lvl: ' }):done :tag('span'):wikitext( ench.req ):css{ ['font-weight']='normal' }:done :done end temp:done :done local row2 = introTable:tag('tr'):addClass('article-row-bound'):css{ height='100%' }--100% height needed for cell contents to use 100% height :tag('td'):css{ ['text-align']='left' }:addClass('seperator-cell'):wikitext(table.concat{			affects and table.concat{ 'Affects: ', affects, ' ' } or '',			desc or 'Unknown description'		}):done :done -- Level data half of table / data sub table local dataTable = mw.html.create('table'):addClass('wikitable centertext') local dataRow1 = dataTable:tag('tr'):css{ height="35px" } local dataRow2 = dataTable:tag('tr') local dataRow3 = dataTable:tag('tr'):css{ ['line-height']='1.3' } -- Add level data to rows local numDataColumns = ench.max; local lastLevelWithItem = 0 for i = 1, ench.max do		-- This if checks if both vars and cost for this tier are nil, and skips it if they are (needed for enchants that don't start at 1) if ((ench.vars or {})[1] or {})[i] ~= nil or (ench.cost or {})[i] ~= nil then dataRow1:tag('th'):wikitext( rarity._link(ench.rarity[i], ench.cost[i] and string.makeTitle(string._toRoman(i), table.concat{ 'Apply Cost: ', ench.cost[i], ' Exp Levels' }) or string._toRoman(i), false, true) ):css{ width=(100/numDataColumns)..'%' } if ench.vars then local levelVars = {} for j, varList in pairs(ench.vars) do					levelVars[#levelVars+1] = varList[i] end dataRow2:tag('td'):wikitext( table.concat(levelVars, ' ') )			end if sourceMap then if sourceMap[i] then dataRow3:tag('td'):attr('colspan', sourceMap[i][1]):addClass('seperator-cell'):wikitext( sourceMap[i][2] ) end elseif i == 1 then dataRow3:tag('td'):attr('colspan', ench.max):addClass('seperator-cell'):wikitext( string.blankCell ) end if not sourceMap and not ench.vars then dataRow2:tag('td'):addClass('seperator-cell') :wikitext( ' '..string.blankCell ) :attr{ rowspan=2 } end end end return table.concat{ tostring(introTable), tostring(dataTable) } end

return p