@tool
extends Node3D
class_name InfiniteModeScreen

const YELLOW_COLOR = Color("e29f32")

@export var actual_distance : int = 0 :
    set(v):
        actual_distance = v
        update()
@export var best_distance : int = 0  :
    set(v):
        best_distance = v
        update()
@export var colored_distance : bool = false :
    set(v):
        colored_distance = v
        update()

func _ready():
    if not Engine.is_editor_hint():
        fetch_game_values()
    update()

func fetch_game_values() -> void:
    actual_distance = GameInfo.game_data.current_run.level * 100
    best_distance = max(
        GameInfo.game_data.current_run.level * 100,
        GameInfo.game_data.progression_data.best_run * 100
    )
    colored_distance = actual_distance == best_distance

func update():
    if is_node_ready():
        %ActualDistanceValue.text = str(actual_distance)
        %BestDistanceValue.text = str(best_distance)

        %ActualDistanceValue.modulate = YELLOW_COLOR if colored_distance else Color.WHITE
        %BestDistanceValue.modulate = YELLOW_COLOR if colored_distance else Color.WHITE
