選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

narration.gd 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. extends RichTextLabel
  2. @onready var message_timer = $MessageTimer
  3. @onready var json_content: Dictionary
  4. @onready var message_lines: Dictionary
  5. @onready var messages_seen: Array
  6. @onready var lines_file_path = "res://text/message_lines.json"
  7. @export var lines_displayed = []
  8. signal end_introduction
  9. # Called when the node enters the scene tree for the first time.
  10. func _ready():
  11. set_scroll_follow(true)
  12. # Called every frame. 'delta' is the elapsed time since the previous frame.
  13. func _process(_delta):
  14. pass
  15. func show_message_by_id(section: String, idnum: int):
  16. var unique_id = section + str(idnum)
  17. if unique_id not in messages_seen:
  18. show_message(message_lines[section][idnum])
  19. messages_seen.append(unique_id)
  20. func show_message(msg):
  21. lines_displayed.append(_centered_message(msg))
  22. #var new_text = _nl_append(message.text, _centered_message(msg))
  23. text = ("\n").join(lines_displayed)
  24. show()
  25. func _nl_append(msg1, msg2):
  26. return msg1 + "\n" + msg2
  27. func _centered_message(msg):
  28. return "[center]" + msg + "[/center]"
  29. func display_introduction():
  30. print("Displaying introduction.")
  31. show_message_by_id("introduction", 0)
  32. await get_tree().create_timer(1.0).timeout
  33. show_message_by_id("introduction", 1)
  34. await get_tree().create_timer(0.5).timeout
  35. end_introduction.emit()
  36. func _on_interface_ready():
  37. print("Narration received interface_ready signal.")
  38. var main_sequence_messages = json_content["main_sequence_messages"]
  39. print("Got JSON content keys " + ", ".join(main_sequence_messages.keys()))
  40. for section in main_sequence_messages.keys():
  41. message_lines[section] = []
  42. var section_lines = main_sequence_messages[section]
  43. section_lines.sort_custom(func(a,b): return a["id"] < b["id"])
  44. for line in section_lines:
  45. message_lines[section].append(line["text"])
  46. display_introduction()