Module:Actions

From Aethermancer Wiki
Jump to navigation Jump to search

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

local p = { }

local actions = mw.loadData("Module:Actions/List");
local parse = require("Module:Parse");
p.errorMsg = "'''Invalid action name. Refer to [[Module:Actions]] for help.'''"

-- Returns true if the given action exists in Module:Actions/List.
function p.isValid (action)
	if (action or "") ~= "" then
		for k, v in pairs(actions) do
			if string.lower(v["name"]) == string.lower(action) then
				return true
	end end end
	return false
end

-- Gets an action's data from Module:Actions/List.
function p.getAction (action)
	for k, v in pairs(actions) do
		if string.lower(v["name"]) == string.lower(action) then
			return v
end end end

-- Gets all actions data from Module:Actions/List.
function p.getAllActions ()
	local actionList = {}
	for k, v in pairs(actions) do
		table.insert(actionList, v)
	end
	return actionList
end

-- Returns the action's description.
p.getDesc = function (action)
	local actionData = p.getAction (action)
	if actionData ~= nil then
		local actionDesc = parse.replaceTerm (actionData["effect"])
		return actionDesc
	end
	return p.errorMsg
end

return p