scene_manager.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. extends Node
  2. var game_scene_path = "res://Game.tscn"
  3. var level_to_set
  4. var game_scene
  5. func load_scene(path):
  6. var scene = load(path).instantiate()
  7. get_tree().get_current_scene().set_name("deleted_game_scene")
  8. get_tree().get_current_scene().queue_free()
  9. get_tree().get_root().add_child(scene)
  10. get_tree().set_current_scene(scene)
  11. game_scene = scene
  12. func restart_level():
  13. if level_to_set != null:
  14. print (level_to_set)
  15. load_level(level_to_set)
  16. else:
  17. print("error loading level")
  18. func load_level(level):
  19. if not ResourceLoader.exists(level):
  20. return
  21. load_scene(game_scene_path)
  22. var current_scene = get_tree().get_current_scene()
  23. if current_scene.has_node("Timer"):
  24. var timer = current_scene.get_node("Timer")
  25. timer.timeout.connect(Callable(self, "_on_timer_timeout"))
  26. level_to_set = level
  27. timer.start()
  28. func _on_timer_timeout():
  29. _set_level(level_to_set)
  30. func _set_level(level):
  31. var current_scene = get_tree().get_current_scene()
  32. print ("-- loading level --")
  33. current_scene.load_level(level)
  34. #if current_scene.has_node("LevelHolder"):
  35. # print ("set level...")
  36. # current_scene.get_node("LevelHolder").load_level(level)
  37. #else:
  38. # print ("oops...")
  39. # call_deferred("_set_level", level)