actionToCommands
Definition
-- @/lua/ge/extensions/core/input/actions.lua:202
-- TLDR: actionCache only needs to be used when the caller is inside getActions
-- NTLDR: actionCache allows to avoid an infinite recursion loop when the caller is getActions (while the cache is being generated, before it's been made public, but we have this particular action's cache internally computed already)
local function actionToCommands(actionName, actionCache)
-- retrieve the code/parameters that will be used by GameEngine when a binding triggers this action
local actionMap = "Normal"
local actsOnChange = false
local onChange = ""
local actsOnDown = false
local onDown = ""
local actsOnUp = false
local onUp = ""
local isRelative = false
local ctx = ActionMapCommandContext()
ctx.type = COMMAND_CONTEXT_TLUA
local isCentered = false
local ctxStr = 'tlua'
local c = actionCache or getActions(true)[actionName]
if c["cat"] =='menu' then actionMap = "Menu" end
if c["ctx"] =='vlua' then actionMap = "VehicleCommon" end
if c["actionMap"] ~= nil then actionMap = c["actionMap"]; end
if actionMap == "MenuIndependent" then actionMap = M.menuIndependentPrefix..actionName end
if c["vehicle"] ~= nil then actionMap = "VehicleSpecific" end
if c["onChange"] ~= nil then onChange = c["onChange"]; actsOnChange = true; end
if c["onRelative"] ~= nil then onChange = c["onRelative"]; actsOnChange = true; isRelative = true; end
if c["onDown"] ~= nil then onDown = c["onDown"]; actsOnDown = true; end
if c["onUp"] ~= nil then onUp = c["onUp"]; actsOnUp = true; end
if c["isCentered"] ~= nil then isCentered= c["isCentered"]; end
if c["ctx"] ~= nil then ctxStr = c["ctx"]; end
if core_input_categories[c.cat] == nil then
log('W', 'bindings', 'Invalid category '..dumps(c.cat)..' defined for '..dumps(actionName).."' action. Suggested fix: modify the 'cat' action field to a valid category, or add the category to categories.lua")
end
if ctxStr == 'slua' then
ctxStr = 'elua'
log('E', 'bindings', 'Replacing deprecated "slua" context with "elua", for action: '..dumps(actionName))
end
if ctxStr == 'ts' then
log("E", "", "The 'ts' context is deprecated. please use tlua. Action: "..dumps(actionName))
ctx.type = COMMAND_CONTEXT_TS
elseif ctxStr == 'ui' then
log("E", "", "The ui context is deprecated. please use tlua and guihooks. Action: "..dumps(actionName))
elseif ctxStr == 'vlua' then ctx.type = COMMAND_CONTEXT_VLUA
elseif ctxStr == 'elua' then ctx.type = COMMAND_CONTEXT_ELUA
elseif ctxStr == 'tlua' then ctx.type = COMMAND_CONTEXT_TLUA
elseif ctxStr == 'bvlua' then ctx.type = COMMAND_CONTEXT_BVLUA
end
if actsOnUp and not actsOnDown then
log("W", "", "Action "..dumps(actionName).." uses 'onUp' instead of 'onDown', which adds input lag. If you're the author of this action, please double check and see if you can switch to 'onDown' instead.")
end
return true, actionMap, actsOnChange, onChange, actsOnDown, onDown, actsOnUp, onUp, isRelative, ctx, isCentered
end
Callers
@/lua/ge/extensions/core/input/bindings.lua
local success, actionMap, actsOnChange, onChange, actsOnDown, onDown, actsOnUp, onUp, isRelative, ctx, isCentered = core_input_actions.actionToCommands(b["action"])
if not success then
@/lua/ge/extensions/core/input/actions.lua
for actionName, action in pairs(result) do
local success, actionMap = M.actionToCommands(actionName, action)
if not success then goto continue end