breaking events

master
Beha 2020-03-30 10:58:18 -04:00
parent f78dc816ff
commit c3b0ad01ba
2 changed files with 8 additions and 1 deletions

View File

@ -5,5 +5,5 @@ function gemai.register_action(name, value)
end
gemai.register_action("gemai:always", function(self)
self:fire_event("gemai:always")
self:fire_event("always")
end)

View File

@ -85,6 +85,10 @@ function gemai.context:step(dtime)
-- Run all state actions.
for _,action in ipairs(self:state().actions) do
self:assert(gemai.actions[action], "gemai action does not exist: " .. action)(self)
-- If the action inserted a breaking event, don't process any more actions.
if self.data.events[1] and self.data.events[#self.data.events].break_state then
break
end
end
end
@ -94,6 +98,8 @@ function gemai.context:fire_event(event, params, options)
clear = false,
-- No events added after this one will propagate.
terminate = true,
-- This event will stop action processing.
break_state = true,
}, options)
-- If this is a clearing event, clear the previous queued events.
@ -105,6 +111,7 @@ function gemai.context:fire_event(event, params, options)
name = event,
params = params or {},
terminate = options.terminate,
break_state = options.break_state,
})
end