extends Control const PREFIX_LABELS := "[color=black]%s" @export var images:Dictionary[StringName, Texture2D] = { &"rest": preload("res://assets/lemon_rest.tres"), &"longrest": preload("res://assets/lemon_rest.tres"), &"run": preload("res://assets/lemon_run.tres") } @export var time_label:RichTextLabel @export var realtime_label:RichTextLabel @export var rest_label:RichTextLabel @export var timer:Timer @export var image:TextureRect var context:PomodoroContext var realtime_since_start:float = 0.0 @onready var sfx:AudioStreamPlayer = $SFX @export var edits:Dictionary[StringName,TextEdit] = {} class PomodoroContext: var current_state := &"run" var workmins:float = 25.0 var restmins:float = 10.0 var longrestmins:float = 30.0 var remaining_rests := 0 var initial_rests := 4 func _init(_rests:=4, _workmins:=25, _rest_mins:=10, _longrestmins:=30)->void: self.workmins = _workmins self.restmins = _rest_mins self.longrestmins = _longrestmins self.remaining_rests = _rests self.initial_rests = _rests self.current_state = &"run" func get_state_timer(state:StringName)->float: match(state): &"run": return workmins * 60.0 &"rest": return restmins * 60.0 &"longrest": return longrestmins * 60.0 push_error("What did you even do.") return 0.0 # you fucked up. func increment_phase()->void: match(current_state): &"run": remaining_rests -= 1 current_state = &"rest" \ if remaining_rests > 0 \ else &"longrest" &"longrest": # reset remaining_rests = initial_rests current_state = &"run" &"rest": current_state = &"run" var state_id:StringName = &"rest" func _process(delta: float) -> void: if not context: return time_label.text = PREFIX_LABELS % get_clock_string() rest_label.text = PREFIX_LABELS % str(context.remaining_rests) realtime_since_start += delta realtime_label.text = "[color=red]%s" % \ Time.get_time_string_from_unix_time(realtime_since_start) func get_from_menus()->PomodoroContext: return PomodoroContext.new( 4, int(edits[&"run"].text), int(edits[&"rest"].text), int(edits[&"longrest"].text)) func on_clock_start()->void: realtime_since_start = 0.0 context = get_from_menus() timer.start(context.get_state_timer(context.current_state)) image.texture = images[context.current_state] func get_clock_string()->String: return Time.get_time_string_from_unix_time(timer.time_left) func _on_timeout() -> void: context.increment_phase() timer.start(context.get_state_timer(context.current_state)) image.texture = images[context.current_state] sfx.play()