-
Notifications
You must be signed in to change notification settings - Fork 3
/
notification_center.gd
32 lines (26 loc) · 1.01 KB
/
notification_center.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
extends Node
var notifications
func _ready():
notifications = {};
func post_notification(notificationName,notificationData):
if notifications.has(notificationName):
var currentObservers=notifications[notificationName].observers
for i in currentObservers:
var anObserver = currentObservers[i]
if anObserver.object.has_method(anObserver.action):
anObserver.object.call(anObserver.action,anObserver.object,notificationName,notificationData)
func add_observer(observer,notificationName,action):
if not notifications.has(notificationName):
notifications[notificationName]={
"observers":{}
}
var currentObservers=notifications[notificationName].observers
currentObservers[observer.get_instance_id()]={
"object":observer,
"action":action
}
func remove_observer(observer, notificationName):
if notifications.has(notificationName):
var currentObservers=notifications[notificationName].observers
if currentObservers.has(observer.get_instance_id()):
currentObservers.erase(observer.get_instance_id())