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.
 
 

78 rivejä
2.0 KiB

  1. extends BaseLevel
  2. class_name TestLevel
  3. export var init_yarn_script : Resource
  4. func _ready():
  5. yarnRunner.add_command("Spawn", funcref(self, "spawn"))
  6. yarnRunner.add_command("EnableTrigger", funcref(self, "enable_trigger"))
  7. yarnRunner.add_command("Scene", funcref(self, "scene"))
  8. EventDispatcher.connect("trigger_script", self, "trigger_script")
  9. Controller.hud.show()
  10. Controller.player_infos.reset()
  11. trigger_script(init_yarn_script)
  12. func spawn(args):
  13. yield(get_tree(), "idle_frame")
  14. if args.size() < 1:
  15. printerr("Spawn command take at least one parameter for target")
  16. return
  17. var spawner = get_node("Spawners/" + args[0])
  18. if spawner != null and spawner.has_method("spawn"):
  19. spawner.spawn()
  20. else:
  21. print("spawner " + args[0] + " not found or not compatible")
  22. func enable_trigger(args):
  23. yield(get_tree(), "idle_frame")
  24. if args.size() < 1:
  25. printerr("EnableTrigger command take at least one parameter for target")
  26. return
  27. var trigger = get_node("Triggers/" + args[0])
  28. if trigger != null and trigger.has_method("enable"):
  29. trigger.enable()
  30. print("trigger " + args[0] + " enabled")
  31. else:
  32. print("trigger " + args[0] + " not found or not compatible")
  33. func trigger_script(yarn_script):
  34. print("script triggered")
  35. yarnRunner.say_func = funcref(Controller.speech_panel.text, "on_new_line")
  36. yarnRunner.choices_func = funcref(Controller.speech_panel.choices, "on_choices")
  37. Controller.speech_panel.show()
  38. Controller.player_input_enabled = false
  39. yarnRunner.yarnScript = yarn_script
  40. yield(yarnRunner.run_all(), "completed")
  41. Controller.speech_panel.hide()
  42. Controller.player_input_enabled = true
  43. func scene(args):
  44. yield(get_tree(), "idle_frame")
  45. if args.size() < 1:
  46. printerr("Scene command take at least one parameter for target")
  47. return
  48. print("Request new scene : " + args[0])
  49. emit_signal("request_new_scene", args[0])
  50. func _exit_tree():
  51. Controller.hud.hide()
  52. Controller.speech_panel.hide()
  53. func _on_Switch_switch(activated):
  54. $DirectionalLight.light_energy = activated if 1 else 0