Jump to content
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 03:07, 6 November 2026 by Admin (talk | contribs) (tools/wiki/push.py)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Cube recipe/doc

-- A table line of the Horadric Cube page (Template:Cube recipe) and its row in the Cargo table CubeRecipes.
local p = {}

local function lines(text)
	local out = {}
	for line in mw.text.gsplit(text or '', '\n', true) do
		line = mw.text.trim(line)
		if line ~= '' then
			table.insert(out, line)
		end
	end
	return out
end

-- "+[10-20] to Strength": the rolled range gets its own colour, as in Template:Item
local function stat_line(line)
	return (line:gsub('%[(%-?%d+%-%-?%d+)%]', '<span class="d2-range">[%1]</span>'))
end

-- the output cell: an item per line, its modifiers on the lines below it that start with ":"
local function output(text)
	local out = {}
	for _, line in ipairs(lines(text)) do
		if line:sub(1, 1) == ':' then
			table.insert(out, '<div class="cube-mod">' .. stat_line(mw.text.trim(line:sub(2))) .. '</div>')
		else
			table.insert(out, '<div class="cube-item">' .. line .. '</div>')
		end
	end
	return table.concat(out)
end

-- the item names of the inputs for queries: "2 x Arcane Crystal" -> "Arcane Crystal", "any Weapon (unique)" -> "any Weapon"
local function names(text)
	local out = {}
	for _, line in ipairs(lines(text)) do
		line = line:gsub('^%d+ x ', ''):gsub(' %([^()]*%)$', '')
		table.insert(out, (line:gsub(';', ',')))
	end
	return table.concat(out, ';')
end

function p.row(frame)
	local a = frame:getParent().args
	local inputs = table.concat(lines(a.inputs), '<br>')
	local out = output(a.output)
	local notes = a.notes or ''
	local cells = {
		'|-',
		'| ' .. (a.recipe or ''),
		'| ' .. inputs,
		'| ' .. out,
		'| ' .. notes,
		'| <span class="cube-rows">' .. (a.rows or '') .. '</span>',
	}
	local text = table.concat(cells, '\n')
	if mw.title.getCurrentTitle().namespace == 0 and (a.store or '') == '' then
		frame:callParserFunction('#cargo_store:', {
			_table = 'CubeRecipes',
			section = a.section or '',
			recipe = a.recipe or '',
			inputs = inputs,
			items = names(a.inputs),
			output = out,
			notes = notes,
			rows = a.rows or '',
		})
	end
	return text
end

return p