68 lines
1.6 KiB
GDScript
68 lines
1.6 KiB
GDScript
extends MarginContainer
|
|
|
|
var alarm: Alarm
|
|
var playing := false
|
|
|
|
@onready var time_talker = $"../time talker"
|
|
@onready var weather_api_node = $"../WeatherAPINode"
|
|
@onready var snooze_timer = $"snooze timer"
|
|
@onready var snooze_button = $VBoxContainer/HBoxContainer/snooze
|
|
@onready var sleep_mode = $"../sleep_mode"
|
|
|
|
var _weather
|
|
|
|
func popup(alarm_in: Alarm):
|
|
if !alarm_in.active:
|
|
return
|
|
self.alarm = alarm_in
|
|
|
|
sleep_mode.prevent_sleep = true
|
|
snooze_button.visible = alarm_in.snooze
|
|
snooze_timer.stop()
|
|
time_talker.stop()
|
|
|
|
_weather = Constants.WEATHER.UNKNOWN
|
|
var json = await weather_api_node.get_forecast()
|
|
if json is Dictionary:
|
|
_weather = Constants.code_to_weather(json['current']['condition']['code'])
|
|
show()
|
|
_play()
|
|
|
|
|
|
func _play():
|
|
playing = true
|
|
if !time_talker.is_playing():
|
|
var moment = Constants.current_moment()
|
|
var day = Time.get_date_dict_from_system()['weekday']
|
|
time_talker.play(moment, day, _weather, alarm.weather_music if alarm.override_weather_music else null, alarm.play_music, alarm.speak_time)
|
|
|
|
func _on_snooze_timer_timeout():
|
|
if alarm != null and !alarm.active:
|
|
_on_stop_pressed()
|
|
return
|
|
show()
|
|
sleep_mode.prevent_sleep = true
|
|
if alarm != null:
|
|
_play()
|
|
|
|
func _on_stop_pressed():
|
|
sleep_mode.prevent_sleep = false
|
|
playing = false
|
|
alarm = null
|
|
time_talker.stop(1.5)
|
|
snooze_timer.stop()
|
|
self.hide()
|
|
|
|
func _on_snooze_pressed():
|
|
sleep_mode.prevent_sleep = false
|
|
print("Ya snooze...")
|
|
playing = false
|
|
time_talker.stop(2.5)
|
|
snooze_timer.start(5 * 60)
|
|
self.hide()
|
|
|
|
|
|
func _on_time_talker_finished():
|
|
if playing and alarm != null:
|
|
_play()
|