Created
October 2, 2019 22:52
-
-
Save mattmccray/5068bf71642a7eaba241e99c1384e283 to your computer and use it in GitHub Desktop.
KISS Event Bus for Godot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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