Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

52 строки
1.3 KiB

  1. extends Node
  2. var YarnScript = preload("yarn_script.gd")
  3. export (Resource) var yarnScript
  4. var say_func : FuncRef = null
  5. func run_all():
  6. var next_node = yarnScript.nodes["Start"]
  7. while next_node != null:
  8. print("-> Jump to " + next_node["title"])
  9. var next_node_key = run_body(next_node["body"])
  10. if (yarnScript.nodes.has(next_node_key)):
  11. next_node = yarnScript.nodes[next_node_key]
  12. else:
  13. next_node = null
  14. func run_body(body):
  15. for element in body:
  16. if element["type"] == "jump":
  17. return element["node"]
  18. elif element["type"] == "choice_blocks":
  19. var block = decide_choice_block(element["blocks"])
  20. return block["node"] # todo change later with "-> choices"
  21. elif element["type"] == "condition_blocks":
  22. var block = decide_condition_block(element["blocks"])
  23. var next_node_key = run_body(block["body"])
  24. if next_node_key != "":
  25. return next_node_key
  26. else:
  27. if say_func == null or !say_func.is_valid():
  28. print(element)
  29. else:
  30. say_func.call_func(element)
  31. return ""
  32. export var choice = 0
  33. func decide_choice_block(blocks):
  34. return blocks[choice]
  35. func decide_condition_block(blocks):
  36. for block in blocks:
  37. var expr := Expression.new()
  38. var err := expr.parse(block["condition"])
  39. if err == OK and expr.execute():
  40. return block
  41. return null