CORE/events.gd

96 lines
3.8 KiB
GDScript3
Raw Normal View History

######################################
# THE CORE FRAMEWORK #
# MADE BY THE STAROPENSOURCE PROJECT #
# AND CONTRIBUTERS (THANK YOU!) #
# #
# COPYRIGHT 2023 THE STAROPENSOURCE #
# PROJECT AND CONTRIBUTERS #
# #
# LICENSED UNDER THE GNU GENERAL #
# PUBLIC LICENSE VERSION 3 (ONLY) #
######################################
extends Node
# CORE modules
var core: Node = null
var logger: Node = null
# Used for checking if any values have changed
var prev_window_title: String = ""
var prev_window_size_x: int = 0
var prev_window_size_y: int = 0
var prev_window_pos_x: int = 0
var prev_window_pos_y: int = 0
# Event signals
signal window_title
signal window_size
signal window_pos
signal logger_all
signal logger_diag
signal logger_info
signal logger_warn
signal logger_error
# Set up connection between logger's logevent and logger_update()
func initialize() -> void:
if core.protection_mode: return
# logevent (signal) -> logger_update()
logger.connect("logevent",Callable(self,"logger_update"))
func logger_update(type:String,script:String,message:String,_logmessage:String) -> void:
if core.protection_mode: return
# Emit signal logger_all for all log messages
emit_signal("logger_all",type,script,message)
# Check for log type and emit the right signal
if type == "DIAG":
emit_signal("logger_diag",script,message)
elif type == "INFO":
emit_signal("logger_info",script,message)
elif type == "WARN":
emit_signal("logger_warn",script,message)
elif type == "ERR!":
emit_signal("logger_error",script,message)
else:
core.exception("events","The log type \"" + type + "\" is not known to events.gd")
# Check various variables and emit signals if they changed
func _process(_delta:float) -> void:
process_window_title()
process_window_size()
process_window_pos()
func process_window_title() -> void:
var new_window_title: String = get_tree().root.title
if prev_window_title != new_window_title:
emit_signal("window_title",new_window_title,prev_window_title)
prev_window_title = new_window_title
func process_window_size() -> void:
var new_window_size_x: int = DisplayServer.window_get_size().x
var new_window_size_y: int = DisplayServer.window_get_size().y
if new_window_size_x != prev_window_size_x and new_window_size_y != prev_window_size_y:
emit_signal("window_size","BOTH",Vector2i(new_window_size_x,new_window_size_y),Vector2i(prev_window_size_x,prev_window_size_y))
prev_window_size_x = new_window_size_x
prev_window_size_y = new_window_size_y
elif new_window_size_x != prev_window_size_x:
emit_signal("window_size","X",Vector2i(new_window_size_x,new_window_size_y),Vector2i(prev_window_size_x,prev_window_size_y))
prev_window_size_x = new_window_size_x
elif new_window_size_y != prev_window_size_y:
emit_signal("window_size","Y",Vector2i(new_window_size_x,new_window_size_y),Vector2i(prev_window_size_x,prev_window_size_y))
prev_window_size_y = new_window_size_y
func process_window_pos() -> void:
var new_window_pos_x: int = DisplayServer.window_get_position().x
var new_window_pos_y: int = DisplayServer.window_get_position().y
if new_window_pos_x != prev_window_pos_x and new_window_pos_y != prev_window_pos_y:
emit_signal("window_pos","BOTH",Vector2i(new_window_pos_x,new_window_pos_y),Vector2i(prev_window_pos_x,prev_window_pos_y))
prev_window_pos_x = new_window_pos_x
prev_window_pos_y = new_window_pos_y
elif new_window_pos_x != prev_window_pos_x:
emit_signal("window_pos","X",Vector2i(new_window_pos_x,new_window_pos_y),Vector2i(prev_window_pos_x,prev_window_pos_y))
prev_window_pos_x = new_window_pos_x
elif new_window_pos_y != prev_window_pos_y:
emit_signal("window_pos","Y",Vector2i(new_window_pos_x,new_window_pos_y),Vector2i(prev_window_pos_x,prev_window_pos_y))
prev_window_pos_y = new_window_pos_y