TextureLoader.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. extends Reference
  2. var filePrexif = "user://colorTiles"
  3. var lat = 0
  4. var lon = 0
  5. # Called when the node enters the scene tree for the first time.
  6. func _ready():
  7. pass # Replace with function body.
  8. # this function essentially checks if the file exists and starts a download if not
  9. func open(latIN, lonIN):
  10. lat = latIN
  11. lon = lonIN
  12. var file = File.new()
  13. var err = file.open(getTexName(), File.READ)
  14. if err == 7:
  15. Downloader.download(getTexName(), "color")
  16. return false
  17. elif err != OK:
  18. print("error opening tex ", err)
  19. return false
  20. else:
  21. file.close()
  22. return true
  23. func loadTexture():
  24. var texName = getTexName()
  25. print("opening texture "+texName)
  26. var image = Image.new()
  27. var err = image.load(texName)
  28. if err != OK:
  29. print("error opening tex ", err)
  30. var tex = ImageTexture.new()
  31. tex.create_from_image(image, 0)
  32. return tex
  33. func getTexName():
  34. return "%s/m-%s-%s.png" % [filePrexif, (int(lat)+90)%180, (int(lon)+180)%360]
  35. #return "res://tex/grid.png"
  36. # Called every frame. 'delta' is the elapsed time since the previous frame.
  37. #func _process(delta):
  38. # pass