Public repository for MUR pre alpha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

  1. extends Node
  2. export(float) var frames_per_second = 5.0
  3. var is_active:bool = false
  4. var is_saving:bool = false
  5. var _frametick = 1.0/frames_per_second
  6. var _thread:Thread
  7. var images = []
  8. func _ready():
  9. _thread = Thread.new()
  10. func _process(delta):
  11. if Input.is_action_just_pressed("controls_capture") && not is_saving:
  12. is_active = not is_active
  13. find_node("recording").set_visible(is_active)
  14. if not is_active:
  15. is_saving = true
  16. find_node("saving").set_visible(true)
  17. _thread.start(self, "save_images")
  18. if is_active:
  19. _frametick += delta
  20. if (_frametick > 1.0/frames_per_second):
  21. get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
  22. var img = get_viewport().get_texture().get_data()
  23. img.flip_y()
  24. images.append(img)
  25. func save_images(userdata):
  26. var dir = Directory.new()
  27. var timestamp = OS.get_unix_time()
  28. if dir.open("user://capture/") != OK:
  29. dir.open("user://")
  30. dir.make_dir("capture")
  31. dir.open("user://capture/")
  32. dir.make_dir(str(timestamp))
  33. for img in images:
  34. img.save_png("user://capture/" + str(timestamp) + "/" + str(img) + ".png")
  35. images = []
  36. is_saving = false
  37. find_node("saving").set_visible(false)
  38. if(_thread.is_active()):
  39. _thread.wait_to_finish()