education-apps/podbooker/time_script.gd

103 lines
2.2 KiB
GDScript

extends Node
@onready var important_vars = $"/root/MainStartScreen/impvars"
var time = Time.get_datetime_dict_from_system()
var dayofweek = time["weekday"]
var day_number = time["day"]
var month_number = time["month"]
var year_number = time["year"]
var dayofweek_word
var month_word
var clock = Time.get_time_dict_from_system()
var refresh_timer = 0
var waiting_timer = 10000
signal timer_beat
# Called when the node enters the scene tree for the first time.
func _ready():
# warning-ignore:return_value_discarded
connect("timer_beat",Callable(self,"on_timer_beat"))
# Give the day a unique number
important_vars.day_uid = str(day_number) + str(month_number) + str(year_number)
important_vars.day_uid2 = str(day_number) + str(month_number) + str(year_number)
# A really long-winded way to convert an array. There is a better way to map it. Will update
# once I know.
if dayofweek == 0:
dayofweek_word = "Sunday"
if dayofweek == 1:
dayofweek_word = "Monday"
if dayofweek == 2:
dayofweek_word = "Tuesday"
if dayofweek == 3:
dayofweek_word = "Wednesday"
if dayofweek == 4:
dayofweek_word = "Thursday"
if dayofweek == 5:
dayofweek_word = "Friday"
if dayofweek == 6:
dayofweek_word = "Saturday"
if month_number == 1:
month_word = "January"
if month_number == 2:
month_word = "February"
if month_number == 3:
month_word = "March"
if month_number == 4:
month_word = "April"
if month_number == 5:
month_word = "May"
if month_number == 6:
month_word = "June"
if month_number == 7:
month_word = "July"
if month_number == 8:
month_word = "August"
if month_number == 9:
month_word = "September"
if month_number == 10:
month_word = "October"
if month_number == 11:
month_word = "November"
if month_number == 12:
month_word = "December"
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
refresh_timer += 1
if refresh_timer > waiting_timer:
refresh_timer = 0
emit_signal("timer_beat")
print("Beat!")
func on_timer_beat():
important_vars.day_uid2 = str(day_number) + str(month_number) + str(year_number)
print("Yup! We're changing days if we need to")
if important_vars.day_uid != important_vars.day_uid2:
get_tree().reload_current_scene()