TextureLoader.gd 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. var dl = Downloader.Download.new()
  17. while not dl._file_name == getTexName():
  18. dl = yield(Messenger, "fileDownloaded")
  19. file.open(getTexName(), File.READ)
  20. Messenger.emit_signal("textureReady", Vector2(latIN, lonIN))
  21. return Vector2(latIN, lonIN)
  22. elif err != OK:
  23. print("error opening tex ", err)
  24. return false
  25. else:
  26. file.close()
  27. return Vector2(latIN, lonIN)
  28. func loadTexture():
  29. var texName = getTexName()
  30. print("opening texture "+texName)
  31. var image = Image.new()
  32. var err = image.load(texName)
  33. if err != OK:
  34. print("error opening tex ", err)
  35. var tex = ImageTexture.new()
  36. tex.create_from_image(image, 0)
  37. return tex
  38. func getTexName():
  39. return "%s/m-%s-%s.png" % [filePrexif, (int(lat)+90)%180, (int(lon)+180)%360]
  40. #return "res://tex/grid.png"
  41. # Called every frame. 'delta' is the elapsed time since the previous frame.
  42. #func _process(delta):
  43. # pass