Added ability to chain raise_custom_event

This commit is contained in:
badgamernl
2020-02-24 23:35:25 +01:00
parent bcde7943ad
commit 0db5565024

View File

@@ -246,6 +246,7 @@ end
--[[-- Raise the handler which is attached to any event; external use should be limited to custom events --[[-- Raise the handler which is attached to any event; external use should be limited to custom events
@tparam table event the event table bassed to the handler, must include fields: name, element @tparam table event the event table bassed to the handler, must include fields: name, element
@treturn table the element define so more events can be raised
@usage Raising a custom event @usage Raising a custom event
element_define:raise_custom_event{ element_define:raise_custom_event{
@@ -258,20 +259,20 @@ function Gui._prototype_element:raise_custom_event(event)
-- Check the element is valid -- Check the element is valid
local element = event.element local element = event.element
if not element or not element.valid then if not element or not element.valid then
return return self
end end
-- Get the event handler for this element -- Get the event handler for this element
local handler = self[event.name] local handler = self[event.name]
if not handler then if not handler then
return return self
end end
-- Get the player for this event -- Get the player for this event
local player_index = event.player_index or element.player_index local player_index = event.player_index or element.player_index
local player = game.players[player_index] local player = game.players[player_index]
if not player or not player.valid then if not player or not player.valid then
return return self
end end
event.player = player event.player = player
@@ -279,6 +280,7 @@ function Gui._prototype_element:raise_custom_event(event)
if not success then if not success then
error('There as been an error with an event handler for a gui element:\n\t'..err) error('There as been an error with an event handler for a gui element:\n\t'..err)
end end
return self
end end
-- This function is used to register a link between element define events and the events in the factorio api -- This function is used to register a link between element define events and the events in the factorio api