Skip to content

Commit e5df55a

Browse files
committed
Add support for automatically adding candidates for POT file generation
1 parent eab19a1 commit e5df55a

File tree

16 files changed

+163
-40
lines changed

16 files changed

+163
-40
lines changed

addons/parley/constants.gd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#region General
66
# TODO: figure out better way of getting this version as it is duplicated
7-
const VERSION: String = "2.0.0"
8-
const AST_VERSION: String = "1.0.0"
7+
const VERSION: String = "2.1.0"
8+
const AST_VERSION: String = "1.1.0"
99
const USER_CONFIG_PATH: String = "user://parley_user_config.json"
1010
#endregion
1111

@@ -27,12 +27,16 @@ const EDITOR_CURRENT_DIALOGUE_SEQUENCE_PATH: String = "parley/editor/current_dia
2727
const DIALOGUE_BALLOON_PATH: String = "parley/dialogue/dialogue_balloon_path"
2828
#endregion
2929

30+
#region Internationalisation
31+
# Project settings
32+
const TRANSLATION_MODE: String = "parley/translations/mode"
33+
const TRANSLATIONS_POT_FILES: String = "internationalization/locale/translations_pot_files"
34+
#endregion
35+
3036
#region Stores
3137
# Project settings
3238
const ACTION_STORE_PATH: String = "parley/stores/action_store_path"
3339
const CHARACTER_STORE_PATH: String = "parley/stores/character_store_path"
34-
const CHARACTER_STORE_PATHS: String = "parley/stores/character_store_paths"
35-
const FACT_STORE_PATHS: String = "parley/stores/fact_store_paths"
3640
const FACT_STORE_PATH: String = "parley/stores/fact_store_path"
3741
#endregion
3842

addons/parley/import_plugin.gd

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ const ParleyConstants = preload('./constants.gd')
1010

1111

1212
const ast_version: String = ParleyConstants.AST_VERSION
13+
var parley_manager: ParleyManager
1314

1415

1516
enum Presets {DEFAULT}
1617

1718

19+
func _init(p_parley_manager: ParleyManager) -> void:
20+
parley_manager = p_parley_manager
21+
22+
1823
func _get_importer_name() -> String:
1924
# NOTE: A change to this forces a re-import of all Dialogue Sequences
2025
return "parley_dialogue_sequence_ast_%s" % ast_version
@@ -69,9 +74,9 @@ func _get_option_visibility(_path: String, _option_name: StringName, _options: D
6974
return true
7075

7176

72-
func _import(source_file: String, save_path: String, _options: Dictionary, _platform_variants: Array[String], _gen_files: Array[String]) -> int:
77+
func _import(source_file_path: String, save_path: String, _options: Dictionary, _platform_variants: Array[String], _gen_files: Array[String]) -> int:
7378
# Serialisation
74-
var file: FileAccess = FileAccess.open(source_file, FileAccess.READ)
79+
var file: FileAccess = FileAccess.open(source_file_path, FileAccess.READ)
7580
if file == null:
7681
return FileAccess.get_open_error()
7782
var raw_text: String = file.get_as_text()
@@ -100,4 +105,8 @@ func _import(source_file: String, save_path: String, _options: Dictionary, _plat
100105

101106
# Compilation
102107
var dialogue_ast: ParleyDialogueSequenceAst = ParleyDialogueSequenceAst.new(title, nodes, edges)
103-
return ResourceSaver.save(dialogue_ast, "%s.%s" % [save_path, _get_save_extension()])
108+
var save_result: int = ResourceSaver.save(dialogue_ast, "%s.%s" % [save_path, _get_save_extension()])
109+
if save_result == OK:
110+
if parley_manager and not source_file_path.begins_with("res://.godot"):
111+
return parley_manager.register_localisation_path(source_file_path)
112+
return save_result

addons/parley/main_panel.gd

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ func _set_node_ast(new_node_ast: ParleyNodeAst) -> void:
175175
_:
176176
push_error(ParleyUtils.log.error_msg("Unsupported Node type: %s for Node with ID: %s" % [ParleyDialogueSequenceAst.get_type_name(selected_node_ast.type), selected_node_ast.id]))
177177
return
178-
179-
180-
# TODO: move to the correct region in this file
181-
func _on_dialogue_ast_changed(new_dialogue_ast: ParleyDialogueSequenceAst) -> void:
182-
if sidebar:
183-
sidebar.current_dialogue_ast = new_dialogue_ast
184178
#endregion
185179

186180

@@ -294,10 +288,15 @@ func _on_new_dialogue_sequence_modal_dialogue_ast_created(new_dialogue_ast: Parl
294288
dialogue_ast = new_dialogue_ast
295289
# TODO: emit as a signal and handle in the plugin
296290
if parley_manager:
297-
var current: Variant = null
291+
var current_path: Variant = null
298292
if dialogue_ast and dialogue_ast.resource_path:
299-
current = dialogue_ast.resource_path
300-
parley_manager.set_current_dialogue_sequence(current)
293+
current_path = dialogue_ast.resource_path
294+
parley_manager.set_current_dialogue_sequence(current_path)
295+
# This is needed to correctly reload upon file saves
296+
if dialogue_ast:
297+
var update_result: int = parley_manager.update_localisations([dialogue_ast])
298+
if update_result != OK:
299+
push_warning(ParleyUtils.log.warn_msg("Unable to update localisations for new Dialogue Sequence (ds:%s): %s" % [dialogue_ast, error_string(update_result)]))
301300
refresh(true)
302301

303302

@@ -317,6 +316,10 @@ func _on_save_pressed() -> void:
317316
# This is needed to reset the Graph and ensure
318317
# that no weirdness is going to happen. For example
319318
# move the group nodes after a save when refresh isn't present
319+
if parley_manager and dialogue_ast:
320+
var update_result: int = parley_manager.update_localisations([dialogue_ast])
321+
if update_result != OK:
322+
push_warning(ParleyUtils.log.warn_msg("Unable to update localisations when saving Dialogue Sequence (ds:%s): %s" % [dialogue_ast, error_string(update_result)]))
320323
await refresh()
321324

322325

@@ -363,6 +366,11 @@ func _on_test_dialogue_from_selected_button_pressed() -> void:
363366

364367

365368
#region SIGNALS
369+
func _on_dialogue_ast_changed(new_dialogue_ast: ParleyDialogueSequenceAst) -> void:
370+
if sidebar:
371+
sidebar.current_dialogue_ast = new_dialogue_ast
372+
373+
366374
func _on_action_store_changed() -> void:
367375
if action_store and dialogue_ast:
368376
var nodes: Array[ParleyNodeAst] = dialogue_ast.find_nodes_by_types([ParleyDialogueSequenceAst.Type.ACTION])

addons/parley/parley_manager.gd

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,58 @@ func get_plugin_version() -> String:
154154
return plugin.get_plugin_version()
155155

156156

157+
## Update localisation for all known Dialogue Sequences
158+
func register_localisation_path(path: String) -> int:
159+
var pot_generation_candidates: PackedStringArray = ProjectSettings.get_setting(ParleyConstants.TRANSLATIONS_POT_FILES, [])
160+
var changed: bool = false
161+
162+
if not pot_generation_candidates.has(path):
163+
var _result: bool = pot_generation_candidates.append(path)
164+
changed = true
165+
166+
if changed:
167+
ProjectSettings.set_setting(ParleyConstants.TRANSLATIONS_POT_FILES, pot_generation_candidates)
168+
var project_settings_save_result: int = ProjectSettings.save()
169+
if project_settings_save_result != OK:
170+
push_error(ParleyUtils.log.error_msg("Unable to save project settings: %d" % [project_settings_save_result]))
171+
return project_settings_save_result
172+
return OK
173+
174+
175+
## Update localisation for all known Dialogue Sequences
176+
func update_localisations(dialogue_sequences_to_register: Array[ParleyDialogueSequenceAst] = [], clean: bool = true) -> int:
177+
var pot_generation_candidates: PackedStringArray = ProjectSettings.get_setting(ParleyConstants.TRANSLATIONS_POT_FILES, [])
178+
var changed: bool = false
179+
180+
# Perform registrations
181+
for dialogue_sequence_to_register: ParleyDialogueSequenceAst in dialogue_sequences_to_register:
182+
if not dialogue_sequence_to_register.resource_path or (clean and not ResourceLoader.exists(dialogue_sequence_to_register.resource_path)):
183+
push_warning(ParleyUtils.log.warn_msg("Unable to register localisation for Dialogue Sequence because it does not exist within the file system (ds:%s)" % dialogue_sequence_to_register))
184+
return ERR_DOES_NOT_EXIST
185+
else:
186+
if not pot_generation_candidates.has(dialogue_sequence_to_register.resource_path):
187+
var _result: bool = pot_generation_candidates.append(dialogue_sequence_to_register.resource_path)
188+
changed = true
189+
190+
# Clean-up any candidates that no longer exist
191+
# Reverse array so that elements are removed from the end and the indices are correct for any subsequence removals
192+
if clean:
193+
for i: int in range(pot_generation_candidates.size() - 1, -1, -1):
194+
var candidate: String = pot_generation_candidates[i]
195+
if candidate.get_extension() == "ds" and not ResourceLoader.exists(candidate):
196+
pot_generation_candidates.remove_at(i)
197+
changed = true
198+
199+
# Update project settings if POT candidates have been changed in any way
200+
if changed:
201+
ProjectSettings.set_setting(ParleyConstants.TRANSLATIONS_POT_FILES, pot_generation_candidates)
202+
var project_settings_save_result: int = ProjectSettings.save()
203+
if project_settings_save_result != OK:
204+
push_error(ParleyUtils.log.error_msg("Unable to save project settings: %d" % [project_settings_save_result]))
205+
return project_settings_save_result
206+
return OK
207+
208+
157209
func set_current_dialogue_sequence(path: Variant) -> void:
158210
if not Engine.is_editor_hint():
159211
return

addons/parley/parley_plugin.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func _enter_tree() -> void:
3838
var parley_manager: ParleyManager = ParleyManager.get_instance()
3939

4040
# Import plugin setup
41-
import_plugin = ParleyImportPlugin.new()
41+
import_plugin = ParleyImportPlugin.new(parley_manager)
4242
add_import_plugin(import_plugin)
4343

4444
# Translation plugin setup

addons/parley/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Parley Dialogue Manager"
44
description="The easy-to-use, writer-first, scalable dialogue management system."
55
author="Bisterix Studio"
6-
version="2.0.0"
6+
version="2.1.0"
77
script="parley_plugin.gd"

addons/parley/settings.gd

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,63 @@ static var DEFAULT_SETTINGS: Dictionary = {
1414
ParleyConstants.CHARACTER_STORE_PATH: "res://characters/character_store.tres",
1515
ParleyConstants.ACTION_STORE_PATH: "res://actions/action_store.tres",
1616
ParleyConstants.FACT_STORE_PATH: "res://facts/fact_store.tres",
17+
# Internationalisation
18+
ParleyConstants.TRANSLATION_MODE: TranslationMode.keys()[TranslationMode.PO],
1719
# Test Dialogue Sequence
1820
# We can't preload this because of circular deps so let's
1921
# hardcode it for now but allow people to edit it in settings
2022
ParleyConstants.TEST_DIALOGUE_SEQUENCE_TEST_SCENE_PATH: "res://addons/parley/views/test_dialogue_sequence_scene.tscn",
2123
}
2224

2325

26+
enum TranslationMode {
27+
PO,
28+
# TODO: add CSV
29+
# CSV,
30+
# TODO: add None
31+
# None,
32+
}
33+
34+
2435
static var TYPES: Dictionary = {
36+
# Dialogue
2537
ParleyConstants.DIALOGUE_BALLOON_PATH: {
2638
"name": ParleyConstants.DIALOGUE_BALLOON_PATH,
39+
"description": "Defines the path to the default Dialogue balloon that is used to render the dialogue when testing and running Dialogue Sequences.",
2740
"type": TYPE_STRING,
2841
"hint": PROPERTY_HINT_FILE,
2942
},
43+
# Stores
3044
ParleyConstants.ACTION_STORE_PATH: {
3145
"name": ParleyConstants.ACTION_STORE_PATH,
46+
"description": "Defines the path to the Action Store resource that is used to store actions.",
3247
"type": TYPE_STRING,
3348
"hint": PROPERTY_HINT_FILE,
3449
},
3550
ParleyConstants.CHARACTER_STORE_PATH: {
3651
"name": ParleyConstants.CHARACTER_STORE_PATH,
52+
"description": "Defines the path to the Character Store resource that is used to store characters.",
3753
"type": TYPE_STRING,
3854
"hint": PROPERTY_HINT_FILE,
3955
},
4056
ParleyConstants.FACT_STORE_PATH: {
4157
"name": ParleyConstants.FACT_STORE_PATH,
58+
"description": "Defines the path to the Fact Store resource that is used to store facts.",
4259
"type": TYPE_STRING,
4360
"hint": PROPERTY_HINT_FILE,
4461
},
62+
# Internationalisation
63+
ParleyConstants.TRANSLATION_MODE: {
64+
"name": ParleyConstants.TRANSLATION_MODE,
65+
"description": "Defines the translation mode to determine how to find and interpret translations.",
66+
"type": TYPE_STRING,
67+
"hint": PROPERTY_HINT_ENUM,
68+
"hint_string": ",".join(TranslationMode.keys())
69+
},
70+
# Testing
4571
ParleyConstants.TEST_DIALOGUE_SEQUENCE_TEST_SCENE_PATH: {
4672
"name": ParleyConstants.TEST_DIALOGUE_SEQUENCE_TEST_SCENE_PATH,
73+
"description": "Defines the path to the default test scene that is rendered when testing Dialogue Sequences.",
4774
"type": TYPE_STRING,
4875
"hint": PROPERTY_HINT_FILE,
4976
}
@@ -58,9 +85,9 @@ static func prepare(save: bool = true) -> void:
5885
if not ProjectSettings.has_setting(setting_name):
5986
set_setting(setting_name, DEFAULT_SETTINGS[setting_name])
6087
ProjectSettings.set_initial_value(setting_name, DEFAULT_SETTINGS[setting_name])
61-
var _info: Variant = TYPES.get(setting_name)
62-
if is_instance_of(_info, TYPE_DICTIONARY):
63-
var info: Dictionary = _info
88+
var info_variant: Variant = TYPES.get(setting_name)
89+
if is_instance_of(info_variant, TYPE_DICTIONARY):
90+
var info: Dictionary = info_variant
6491
ProjectSettings.add_property_info(info)
6592

6693
# Reset some user values upon load that might cause weirdness:

dialogue_sequences/all.ds.import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[remap]
22

3-
importer="parley_dialogue_sequence_ast_1.0.0"
3+
importer="parley_dialogue_sequence_ast_1.1.0"
44
type="Resource"
55
uid="uid://d2883lul36r1d"
66
path="res://.godot/imported/all.ds-d8506930102030864fdc0be22ee21873.tres"

dialogue_sequences/next_dialogue.ds.import

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[remap]
22

3-
importer="parley_dialogue_sequence_ast_1.0.0"
3+
importer="parley_dialogue_sequence_ast_1.1.0"
44
type="Resource"
55
uid="uid://cfaambg2fkgnh"
66
path="res://.godot/imported/next_dialogue.ds-1f2d2ca9751962b670972e838b0d73c3.tres"

docs/latest/dialogue_sequence.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)