-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.gd
41 lines (31 loc) · 1.63 KB
/
example.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
32
33
34
35
36
37
38
39
40
41
extends Node2D
@export var pyco_event: PycoEvent
func _physics_process(_delta: float) -> void:
# PycoLog.log_event will merge the incoming event with the default event,
# and override its values with non-empty fields from pyco_event.
# We are logging an event every frame here only for demonstration purposes.
PycoLog.log_event(pyco_event)
func _process(delta: float) -> void:
# The simplest way to log an event.
PycoLog.log_event_by_type("process_event", {"delta": delta})
func _ready() -> void:
# Setting up graceful shutdown (see also the comments in _input() below):
# Set auto_accept_quit to false, so PycoLog has time to send logging events.
get_tree().set_auto_accept_quit(false)
# You can trigger get_tree().quit() any time after shutdown_request_sent is emitted.
# Events logged after NOTIFICATION_WM_CLOSE_REQUEST is recieved are not sent to the server.
PycoLog.shutdown_event_sent.connect(get_tree().quit)
# Customizing the startup event:
# Setting a startup_callable (returning a PycoEvent) before the
# end of the first frame lets you customize the startup event.
PycoLog.startup_callable = func() -> PycoEvent:
var e := PycoEvent.copy_default()
e.event_type = "startup"
e.value = {"custom_startup_message": 42}
return e
func _input(event: InputEvent) -> void:
if event.is_action(&"ui_cancel"):
# Make sure to trigger NOTIFICATION_WM_CLOSE_REQUEST instead of quitting
# This is neccesary to send shutdown notifications
# See https://docs.godotengine.org/en/stable/tutorials/inputs/handling_quit_requests.html#sending-your-own-quit-notification
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)