25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

54 satır
1.5 KiB

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