extends HBoxContainer
tool

export var show_celsius := true setget set_show_celsius
export var show_fahrenheit := true setget set_show_fahrenheit
export var degrees_celsius := 0.0 setget set_degrees_celsius
export var degrees_fahrenheit := 0.0 setget set_degrees_fahrenheit
export var temperature_unknown := true setget set_temperature_unknown

func _ready():
	_check_slash()
	_update_text()

func set_temperature_unknown(new:bool):
	temperature_unknown = new
	_update_text()

func set_show_celsius(new:bool):
	show_celsius = new
	$celsius.visible = new
	$degrees.visible = new
	_check_slash()

func set_show_fahrenheit(new:bool):
	show_fahrenheit = new
	$fahrenheit.visible = new
	$degrees2.visible = new
	_check_slash()

func set_degrees_celsius(new:float):
	degrees_celsius = new
	degrees_fahrenheit = Constants.celsius_to_fahrenheit(degrees_celsius) 
	_update_text()

func set_degrees_fahrenheit(new:float):
	degrees_fahrenheit = new
	degrees_celsius = Constants.fahrenheit_to_celsius(degrees_fahrenheit)
	_update_text()



func _update_text():
	if !$celsius:
		return
	if temperature_unknown:
		$celsius.text = '?'
		$fahrenheit.text = '?'
	else:
		$celsius.text = str(stepify(degrees_celsius, 1))
		$fahrenheit.text = str(stepify(degrees_fahrenheit, 1))

func _check_slash():
	if !$slash:
		return
	$slash.visible = show_celsius and show_fahrenheit
