extends Reference


var filePrexif = "user://colorTiles"

var lat = 0
var lon = 0

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

# this function essentially checks if the file exists and starts a download if not
func open(latIN, lonIN):
	lat = latIN
	lon = lonIN
	var file = File.new()
	var err = file.open(getTexName(), File.READ)
	if err == 7:
		Downloader.download(getTexName(), "color")
		return false
	elif err != OK:
		print("error opening tex ", err)
		return false
	else:
		file.close()
		return true

func loadTexture():
	var texName = getTexName()
	print("opening texture "+texName)
	var image = Image.new()
	var err = image.load(texName)
	if err != OK:
		print("error opening tex ", err)
	var tex = ImageTexture.new()
	tex.create_from_image(image, 0)
	return tex
	
func getTexName():
	return "%s/m-%s-%s.png" % [filePrexif, (int(lat)+90)%180, (int(lon)+180)%360]
	#return "res://tex/grid.png"



# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
