Module:Necropolis packs/sandbox: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
No edit summary
Tag: Manual revert
No edit summary
Line 7: Line 7:


local function _expand_template(data)
local function _expand_template(data)
return mw.getCurrentFrame():expandTemplate{
return m_util.string.strip(mw.getCurrentFrame():expandTemplate{
title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
args = {
args = {
Line 14: Line 14:
leader = data.leader
leader = data.leader
}
}
}
})
end
end



Revision as of 11:35, 8 April 2024

This is the module sandbox page for Module:Necropolis packs (diff).

Module documentation[view] [edit] [history] [purge]


Renders pack data for Template:Necropolis pack.

Usage

{{#invoke:Necropolis packs|function_name}}


require('Module:No globals')
local m_util = require('Module:Util')

local use_sandbox = m_util.misc.maybe_sandbox('Necropolis_packs')
local m_data = mw.loadData('Module:Necropolis_packs/data')
local m_lookup = mw.loadData('Module:Necropolis_pack_lookup/data')

local function _expand_template(data)
	return m_util.string.strip(mw.getCurrentFrame():expandTemplate{
		title = use_sandbox and 'Template:Necropolis pack/display/sandbox' or 'Template:Necropolis pack/display',
		args = {
			name = data.name,
			description = data.description,
			leader = data.leader
		}
	})
end

local function _render_pack(tpl_args)
	local ember = tpl_args and tpl_args.item_name
	local pack_id = tpl_args and tpl_args.pack_id
	if ember and not pack_id then
		local found = m_lookup[ember]
		if not found then
			return
		end
		pack_id = found.pack_id
	end
	if pack_id then
		local data = m_data[pack_id]
		return mw.getCurrentFrame():preprocess(_expand_template(data))
	else
		local all = "==All known packs==\n"
		for _, data in pairs(m_data) do
			if data.name and data.name ~= '' then
				all = all .. "\n===" .. data.name .. "===\n" .. _expand_template(data)
			end
		end
		return mw.getCurrentFrame():preprocess(all)
	end
end

local p = {}

p.render_pack = m_util.misc.invoker_factory(_render_pack)

return p