global.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. extends Node
  2. var currentScene = null #FIXME: name: currentWorldScene
  3. var loaded_level = null
  4. var w = null
  5. func _ready():
  6. currentScene = get_tree().get_root().get_child(get_tree().get_root().get_child_count() - 1 )
  7. #rename to "change_level"
  8. func loadLevel(scene, level_scene, spawn, save):
  9. print ("global.gd::loadLevel called")
  10. loaded_level = level_scene
  11. if currentScene.has_method("clear_data"):
  12. currentScene.clear_data()
  13. currentScene.queue_free()
  14. currentScene.set_name("World_delete")
  15. w = load(scene)
  16. currentScene = w.instance() #world instance
  17. currentScene.set_name("World")
  18. get_tree().get_root().add_child(currentScene)
  19. currentScene.set_level(level_scene, spawn, save)
  20. print ("global.gd::loadLevel call finished")
  21. func restartLevel():
  22. currentScene.reset_world()
  23. func getCurrentWorld():
  24. return currentScene
  25. #FIXME: crash if given scene path not found / scene not exists
  26. func changeToCustomScene(scenePath):
  27. loaded_level = null
  28. currentScene.queue_free()
  29. var customScene = load(scenePath)
  30. currentScene = customScene.instance()
  31. get_tree().get_root().add_child(currentScene)
  32. Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)