Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created October 2, 2019 22:52
Show Gist options
  • Save mattmccray/5068bf71642a7eaba241e99c1384e283 to your computer and use it in GitHub Desktop.
Save mattmccray/5068bf71642a7eaba241e99c1384e283 to your computer and use it in GitHub Desktop.
KISS Event Bus for Godot.
extends Node
# Be sure to AutoLoad me as a singleton
# Enumerate all your game events here...
enum {
GAME_STARTED,
GAME_OVER
}
var _event_names= [
"GAME_STARTED",
"GAME_OVER"
]
signal on_message(type, payload)
func dispatch(type, payload = {}):
print_debug(" » ", _event_names[type], " ", payload)
emit_signal("on_message", type, payload)
func get_event_name(type):
return _event_names[type]
extends Node
func _ready():
## Subscribe to game events:
Events.connect("on_message", self, "_on_game_event")
## Dispatch game events
Events.dispatch(Events.GAME_STARTED)
func _on_game_event(type, payload):
match type:
Events.GAME_STARTED:
print("Game has started!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment