Module:ContractChainRewards

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

Module:ContractChainRewards

Renders the rewards of each Contract in a Contract Chain, for use by Template:QuestInfobox/ContractChain.

This module should not be invoked directly. To display Contract rewards on a Contract Chain page, use Template:QuestInfobox/ContractChain.

This module provides the following function(s):

  • main - looks up each listed Contract's rewards field via DPL3 and returns a linked, bolded Contract name followed by its rewards.

Usage

Render rewards for a chain

{{#invoke:ContractChainRewards|main|chain=Scrap Mettle|contracts=Copper Required~Wrecking Crew~Testing Limits}}

Include a cross-chain Contract

A name containing / is treated as a fully qualified title and is not prefixed with the chain.

{{#invoke:ContractChainRewards|main|chain=Scrap Mettle|contracts=Copper Required~Tradepost - The Anvil/Digging Deeper}}

Parameters

main

chain
string
The Contract Chain name. Prefixed to every Contract name that does not already contain a /.
contracts
string
One or more Contract names, separated by tildes ~. Empty items are skipped.
Returns an error message if not specified.

Notes

  • Each Contract is checked for existence before its rewards are queried. Missing Contracts render an error message in place of their rewards, so typos are visible on the page.
  • Rewards are pulled from each Contract's rewards field using DPL3, so the list is rendered exactly as written in the Contract's own infobox.
  • Each entry is rendered as a bolded link to the Contract, followed by its rewards on the next line. Entries are joined with
    .

local p = {}

local common = require("Module:Common")

-- ---------- Data ----------

local DPL_QUERY = '{{ #dpl: title = %s | include = {QuestInfobox/Contract}:rewards | format = ,,, }}'

-- ---------- Interface ----------

function p.main(frame)
    local args = frame.args

    local contractsArg = common.trim(args.contracts or "")
    if contractsArg == "" then
        return common.renderError("No contracts specified")
    end

    local out = {}
    for name in mw.text.gsplit(contractsArg, "~") do
        name = mw.text.trim(name)

        if name ~= "" then
            -- bare name = subpage of this chain; already contains "/" = fully qualified (cross-chain)
            local fullTitle = name:find("/") and name or (args.chain .. "/" .. name)
            local title = mw.title.new(fullTitle)

            if not title or not title.exists then
                if title then
                    out[#out + 1] = common.renderError("Unknown contract: [[" .. fullTitle .. "|" .. mw.text.encode(name) .. "]]")
                else
                    out[#out + 1] = common.renderError("Unknown contract: %s", name)
                end
            else
                local dplCall = string.format(DPL_QUERY, fullTitle)
                local rewards = mw.text.trim(frame:preprocess(dplCall))

                out[#out + 1] = "'''[[" .. fullTitle .. "|" .. name .. "]]'''\n" .. (rewards ~= "" and rewards or "''No rewards found''")
            end
        end
    end

    return table.concat(out, "<br>\n")
end

return p