@@ -11,9 +11,23 @@ enum LEVEL {
11
11
12
12
var also_print_to_godot := false ;
13
13
var _js_available := OS .has_feature ("JavaScript" )
14
+ var is_joypad = false
15
+ var joypad_index = - 1
14
16
var GDQUEST : JavaScriptObject
15
17
16
18
19
+ func _init () -> void :
20
+ var _err = Input .connect ("joy_connection_changed" , self , "_on_joy_connection_changed" )
21
+ if not _js_available :
22
+ return
23
+ GDQUEST = JavaScript .get_interface ("GDQUEST" )
24
+ if not GDQUEST :
25
+ _js_available = false
26
+ return
27
+ trim_if_over_limit ()
28
+ log_system_info_if_log_is_empty (get_info ())
29
+
30
+
17
31
func write (level : int , properties : Dictionary , message : String ) -> void :
18
32
if also_print_to_godot and OS .is_debug_build ():
19
33
var level_index := LEVEL .values ().find (level )
@@ -33,9 +47,7 @@ func write(level: int, properties: Dictionary, message: String) -> void:
33
47
print (object )
34
48
if not _js_available :
35
49
return
36
- var props = JavaScript .create_object ("Object" , {})
37
- for key in properties :
38
- props [key ] = properties [key ]
50
+ var props = godot_dict_to_js_obj (properties )
39
51
match (level ):
40
52
LEVEL .FATAL :
41
53
# warning-ignore:unsafe_property_access
@@ -57,16 +69,6 @@ func write(level: int, properties: Dictionary, message: String) -> void:
57
69
GDQUEST .log .trace (props , message )
58
70
59
71
60
- func _init () -> void :
61
- if not _js_available :
62
- return
63
- GDQUEST = JavaScript .get_interface ("GDQUEST" )
64
- if not GDQUEST :
65
- _js_available = false
66
- return
67
- trim_if_over_limit ()
68
-
69
-
70
72
func trace (properties : Dictionary , message : String ) -> void :
71
73
write (LEVEL .TRACE , properties , message )
72
74
@@ -102,8 +104,55 @@ func download() -> void:
102
104
103
105
# Makes sure the log doesn't fill user's localStorage. Safe to call in all
104
106
# environments, will no-op when JS is not available.
105
- func trim_if_over_limit (max_kilo_bytes := 1000 ) -> void :
107
+ func trim_if_over_limit (max_kilo_bytes := 1000 ) -> bool :
106
108
if not _js_available :
107
- return
109
+ return false
108
110
# warning-ignore:unsafe_property_access
109
- GDQUEST .log .trimIfOverLimit (max_kilo_bytes )
111
+ return GDQUEST .log .trimIfOverLimit (max_kilo_bytes )
112
+
113
+
114
+ # Logs system info if the log is empty. Safe to call in all environments, will
115
+ # no-op when JS is not available.
116
+ func log_system_info_if_log_is_empty (additional_data := {}) -> void :
117
+ if not _js_available :
118
+ return
119
+ if additional_data .size () > 0 :
120
+ var props = godot_dict_to_js_obj (additional_data )
121
+ # warning-ignore:unsafe_property_access
122
+ GDQUEST .log .logSystemInfoIfLogIsEmpty (props )
123
+ else :
124
+ # warning-ignore:unsafe_property_access
125
+ GDQUEST .log .logSystemInfoIfLogIsEmpty ()
126
+
127
+
128
+ func godot_dict_to_js_obj (properties : Dictionary ):
129
+ var props = JavaScript .create_object ("Object" , {})
130
+ for key in properties :
131
+ var value = properties [key ]
132
+ if value is Dictionary :
133
+ value = godot_dict_to_js_obj (value )
134
+ elif value is Vector2 or value is Vector3 :
135
+ value = "%s " % [value ]
136
+ props [key ] = value
137
+ return props
138
+
139
+
140
+ func get_info ():
141
+ var info = {
142
+ "OS" : OS .get_name (),
143
+ "datetime" : OS .get_datetime (),
144
+ "video_driver" : OS .get_video_driver_name (OS .get_current_video_driver ()),
145
+ "video_adapter" : VisualServer .get_video_adapter_name (),
146
+ "video_vendor" : VisualServer .get_video_adapter_vendor (),
147
+ "screen_size" : OS .get_screen_size (),
148
+ "screen_dpi" : OS .get_screen_dpi (),
149
+ "cores" : OS .get_processor_count (),
150
+ "locale" : OS .get_locale (),
151
+ "joypad" : Input .get_joy_name (joypad_index ) if is_joypad else ""
152
+ }
153
+ return info
154
+
155
+
156
+ func _on_joy_connection_changed (device_id , connected ):
157
+ is_joypad = connected
158
+ joypad_index = device_id
0 commit comments