Module:Reward/Maps

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

Displays and defines rewards for a given map.

This is used by the reward parameter of Template:Battle Infobox; see that documentation page for details.

local Reward = require 'Module:Reward'
local RewardText = require 'Module:RewardText'
local parseArgs = require 'Module:ObjectArg'.parse
local toboolean = require 'Module:Bool'.toboolean

local main = function (args, frame)
	local allRewards, err = parseArgs(args[1] or '')
	if err or type(allRewards) ~= 'table' then
		mw.log('ObjectArg.parse failed: ' .. err)
		mw.log('Reward parameter: ' .. tostring(args[1] or ''))
		mw.log('Using reward parameter verbatim.')
		return args[1]
	end

	local rewardTexts = {}
	local noCargo = toboolean(args['no cargo'])

	for dif, rewards in pairs(allRewards) do
		rewards, err = Reward.normalize(rewards)
		if err then
			mw.log('ObjectArg.parse failed: ' .. err)
			mw.log('Reward string: ' .. tostring(args[1] or ''))
			mw.log('Using reward parameter verbatim.')
			return args[1]
		end

		rewardTexts[dif] = RewardText._main({rewards, iconfirst = '1'}, frame)
		if not noCargo then
			Reward.define(rewards, 'Maps', {tabname = dif}, frame)
		end
	end

	return require 'Module:DifficultyTexts'._main(rewardTexts)
end

return require 'Module:MakeMWModule'.makeMWModule {main = main}