No Description
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.

DialogicClass.gd 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. extends Node
  2. ## Exposed and safe to use methods for Dialogic
  3. ## See documentation here:
  4. ## https://github.com/coppolaemilio/dialogic
  5. ## ### /!\ ###
  6. ## Do not use methods from other classes as it could break the plugin's integrity
  7. ## ### /!\ ###
  8. ##
  9. ## Trying to follow this documentation convention: https://github.com/godotengine/godot/pull/41095
  10. class_name Dialogic
  11. ## Starts the dialog for the given timeline and returns a Dialog node.
  12. ## You must then add it manually to the scene to display the dialog.
  13. ##
  14. ## Example:
  15. ## var new_dialog = Dialogic.start('Your Timeline Name Here')
  16. ## add_child(new_dialog)
  17. ##
  18. ## This is exactly the same as using the editor:
  19. ## you can drag and drop the scene located at /addons/dialogic/Dialog.tscn
  20. ## and set the current timeline via the inspector.
  21. ##
  22. ## @param timeline The timeline to load. You can provide the timeline name or the filename.
  23. ## @param reset_saves True to reset dialogic saved data such as definitions.
  24. ## @param dialog_scene_path If you made a custom Dialog scene or moved it from its default path, you can specify its new path here.
  25. ## @param debug_mode Debug is disabled by default but can be enabled if needed.
  26. ## @returns A Dialog node to be added into the scene tree.
  27. static func start(timeline: String, reset_saves: bool=true, dialog_scene_path: String="res://addons/dialogic/Dialog.tscn", debug_mode: bool=false):
  28. var dialog: = load(dialog_scene_path)
  29. var d = dialog.instance()
  30. d.reset_saves = reset_saves
  31. d.debug_mode = debug_mode
  32. if not timeline.empty():
  33. for t in DialogicUtil.get_timeline_list():
  34. if t['name'] == timeline or t['file'] == timeline:
  35. d.timeline = t['file']
  36. return d
  37. d.dialog_script = {
  38. "events":[{"character":"","portrait":"",
  39. "text":"[Dialogic Error] Loading dialog [color=red]" + timeline + "[/color]. It seems like the timeline doesn't exists. Maybe the name is wrong?"}]
  40. }
  41. return d
  42. ## Same as the start method above, but using the last timeline saved.
  43. ##
  44. ## @param initial_timeline The timeline to load in case no save is found.
  45. ## @param dialog_scene_path If you made a custom Dialog scene or moved it from its default path, you can specify its new path here.
  46. ## @param debug_mode Debug is disabled by default but can be enabled if needed.
  47. ## @returns A Dialog node to be added into the scene tree.
  48. static func start_from_save(initial_timeline: String, dialog_scene_path: String="res://addons/dialogic/Dialog.tscn", debug_mode: bool=false):
  49. var current := get_current_timeline()
  50. if current.empty():
  51. current = initial_timeline
  52. return start(current, false, dialog_scene_path, debug_mode)
  53. ## Gets default values for definitions.
  54. ##
  55. ## @returns Dictionary in the format {'variables': [], 'glossary': []}
  56. static func get_default_definitions() -> Dictionary:
  57. return DialogicSingleton.get_default_definitions()
  58. ## Gets currently saved values for definitions.
  59. ##
  60. ## @returns Dictionary in the format {'variables': [], 'glossary': []}
  61. static func get_definitions() -> Dictionary:
  62. return DialogicSingleton.get_definitions()
  63. ## Save current definitions to the filesystem.
  64. ## Definitions are automatically saved on timeline start/end
  65. ##
  66. ## @returns Error status, OK if all went well
  67. func save_definitions():
  68. return DialogicSingleton.save_definitions()
  69. ## Resets data to default values. This is the same as calling start with reset_saves to true
  70. func reset_saves():
  71. DialogicSingleton.init(true)
  72. ## Gets the value for the variable with the given name.
  73. ## The returned value is a String but can be easily converted into a number
  74. ## using Godot built-in methods:
  75. ## [`is_valid_float`](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-is-valid-float)
  76. ## [`float()`](https://docs.godotengine.org/en/stable/classes/class_float.html#class-float-method-float).
  77. ##
  78. ## @param name The name of the variable to find.
  79. ## @returns The variable's value as string, or an empty string if not found.
  80. static func get_variable(name: String) -> String:
  81. return DialogicSingleton.get_variable(name)
  82. ## Sets the value for the variable with the given name.
  83. ## The given value will be converted to string using the
  84. ## [`str()`](https://docs.godotengine.org/en/stable/classes/class_string.html) function.
  85. ##
  86. ## @param name The name of the variable to edit.
  87. ## @param value The value to set the variable to.
  88. static func set_variable(name: String, value) -> void:
  89. DialogicSingleton.set_variable(name, value)
  90. ## Gets the glossary data for the definition with the given name.
  91. ## Returned format:
  92. ## { title': '', 'text' : '', 'extra': '' }
  93. ##
  94. ## @param name The name of the glossary to find.
  95. ## @returns The glossary data as a Dictionary.
  96. ## A structure with empty strings is returned if the glossary was not found.
  97. static func get_glossary(name: String) -> Dictionary:
  98. return DialogicSingleton.get_glossary(name)
  99. ## Sets the data for the glossary of the given name.
  100. ##
  101. ## @param name The name of the glossary to edit.
  102. ## @param title The title to show in the information box.
  103. ## @param text The text to show in the information box.
  104. ## @param extra The extra information at the bottom of the box.
  105. static func set_glossary(name: String, title: String, text: String, extra: String) -> void:
  106. DialogicSingleton.set_glossary(name, title, text, extra)
  107. ## Gets the currently saved timeline.
  108. ## Timeline saves are set on timeline start, and cleared on end.
  109. ## This means you can keep track of timeline changes and detect when the dialog ends.
  110. ##
  111. ## @returns The current timeline filename, or an empty string if none was saved.
  112. static func get_current_timeline() -> String:
  113. return DialogicSingleton.get_current_timeline()