Jump to content
Menü aufrufen
Toggle preferences menu
Persönliches Menü aufrufen
Nicht angemeldet
Ihre IP-Adresse wird öffentlich sichtbar sein, wenn Sie Änderungen vornehmen.

Die Dokumentation für dieses Modul kann unter Modul:Entity/Rewards/doc erstellt werden

require('strict')

local Data = require('Module:Entity/Data')
local TableLua = require('Module:TableLua')
local Lines = require('Module:Entity/Rewards/Lines')
local emptyState = require('Module:Entity/EmptyState')
local format = require('Module:Entity/Format')
local msg = require('Module:Entity/Message').msg

local function processBlueprints(groups)
	local data = {}

	for i, group in ipairs(groups) do
		local info = msg('POOL $1', { format.formatNum(i) })
		if group.drop_chance_percent ~= nil then
			info =
				msg('POOL $1 - Drop chance $2%', { format.formatNum(i), format.formatNum(group.drop_chance_percent) })
		end
		local blueprints = {}

		for _, blueprint in ipairs(group.items) do
			-- The cell's word order localizes at this seam: Lines.blueprintLine
			-- stays the English line the structured-data path routes and checks
			-- (Bucket puts, SMW raw-context match), and Lines stays require-free.
			table.insert(blueprints, { msg('$1 blueprint', { Lines.blueprintLink(blueprint) }) })
		end

		table.insert(data, { info = info, values = blueprints })
	end

	return data
end

local function processItems(groups)
	local data = {}

	for _, group in ipairs(groups) do
		local info = msg('Awarded to all contract members.')
		if group.award_only_to_mission_owner then
			info = msg('Awarded ONLY to contract owner.')
		end

		local items = {}

		for _, item in ipairs(group.items) do
			table.insert(items, { Lines.itemLine(item) })
		end

		table.insert(data, { info = info, values = items })
	end

	return data
end

local function renderSection(data)
	local t = {}

	for _, x in ipairs(data) do
		table.insert(
			t,
			TableLua.render({
				caption = x.info,
				class = 'wikitable--fluid t-entity-rewards-table',
				columns = {
					{ id = 'name', label = msg('Name'), textAlign = 'start' },
				},
				data = x.values,
			})
		)
	end

	return table.concat(t)
end

local p = {}

--- @param apiData table
--- @return string|nil
function p.main(frame)
	local args = Data.parseArgs(frame)
	local result = Data.get(args)

	local styles = mw.getCurrentFrame():extensionTag({
		name = 'templatestyles',
		args = { src = 'Module:Entity/Rewards/styles.css' },
	})

	local root = mw.html.create(nil)

	if result.hasApiError then
		root:tag('h3'):wikitext(msg('Items'))
		root:wikitext(emptyState.failed(msg("Couldn't load awarded items.")))

		root:tag('h3'):wikitext(msg('Blueprints'))
		root:wikitext(emptyState.failed(msg("Couldn't load awarded blueprints.")))

		return styles .. tostring(root)
	end

	local rewardGroups = result.apiData.reward_groups
	local blueprintGroups = result.apiData.blueprints

	root:tag('h3'):wikitext(msg('Items'))
	if not rewardGroups or #rewardGroups == 0 then
		root:wikitext(emptyState.none(msg('No items awarded.')))
	else
		root:wikitext(renderSection(processItems(rewardGroups)))
	end

	root:tag('h3'):wikitext(msg('Blueprints'))
	if not blueprintGroups or #blueprintGroups == 0 then
		root:wikitext(emptyState.none(msg('No blueprints awarded.')))
	else
		root:wikitext(renderSection(processBlueprints(blueprintGroups)))
	end

	return styles .. tostring(root)
end

return p
Zuletzt geändert
Urheberrecht
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.