tests_menu.gd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. extends OptionMenu
  2. class TestData:
  3. var id
  4. var scene_path
  5. var _test_list = []
  6. var _current_test = null
  7. var _current_test_scene: Node = null
  8. func _ready():
  9. option_selected.connect(self._on_option_selected)
  10. func _process(_delta):
  11. if Input.is_action_just_pressed(&"restart_test"):
  12. if _current_test:
  13. _start_test(_current_test)
  14. func add_test(id, scene_path):
  15. var test_data = TestData.new()
  16. test_data.id = id
  17. test_data.scene_path = scene_path
  18. _test_list.append(test_data)
  19. add_menu_item(id)
  20. func _on_option_selected(item_path):
  21. for test in _test_list:
  22. if test.id == item_path:
  23. _start_test(test)
  24. func _start_test(test):
  25. _current_test = test
  26. if _current_test_scene:
  27. _current_test_scene.queue_free()
  28. _current_test_scene = null
  29. Log.print_log("*** STARTING TEST: " + test.id)
  30. var scene = load(test.scene_path)
  31. _current_test_scene = scene.instantiate()
  32. get_tree().root.add_child(_current_test_scene)
  33. get_tree().root.move_child(_current_test_scene, 0)
  34. var label_test = get_node(^"../LabelTest")
  35. label_test.test_name = test.id