From 3dc779311ce6cfe6aeb2e056a2af2977c13b10fa Mon Sep 17 00:00:00 2001 From: Dennis Ploeger Date: Mon, 30 Aug 2021 20:57:25 +0200 Subject: [PATCH] Issue 336 (#380) Co-authored-by: Dennis Ploeger Co-authored-by: dploeger --- .../esc/_test/test_esc_compiler.gd | 18 +- .../game/core-scripts/esc/commands/say.gd | 17 +- .../core-scripts/esc/types/esc_command.gd | 3 + .../esc/types/esc_dialog_option.gd | 20 ++- docs/api/ESCDialogOption.md | 10 +- docs/api/SayCommand.md | 9 +- docs/esc.md | 30 ++-- game/rooms/room01/esc/wall_item.esc | 8 +- .../room01/esc/wall_item_popupdialog.esc | 8 +- game/rooms/room06/esc/worker.esc | 4 +- game/translations/game.csv | 12 +- game/translations/game.de.translation | Bin 0 -> 732 bytes game/translations/game.en.translation | Bin 386 -> 681 bytes game/translations/game.fr.translation | Bin 406 -> 724 bytes game/translations/main_menu.csv | 36 ++-- game/translations/main_menu.de.translation | Bin 0 -> 1056 bytes game/translations/main_menu.en.translation | Bin 921 -> 989 bytes game/translations/main_menu.fr.translation | Bin 956 -> 1032 bytes game/ui/commons/load/load_game.gd | 10 +- game/ui/commons/load/load_game.tscn | 50 +++--- game/ui/commons/main_menu/flags/en_EN.png | Bin 9746 -> 0 bytes game/ui/commons/main_menu/flags/fr_FR.png | Bin 2981 -> 0 bytes game/ui/commons/main_menu/main.tscn | 1 + game/ui/commons/main_menu/main_menu.gd | 10 +- game/ui/commons/main_menu/main_menu.tscn | 53 ++++-- game/ui/commons/options/flags/de.png | Bin 0 -> 2245 bytes .../en_EN_small.png => options/flags/en.png} | Bin .../fr_FR_small.png => options/flags/fr.png} | Bin game/ui/commons/options/options.gd | 34 +++- game/ui/commons/options/options.tscn | 154 +++++++++--------- game/ui/commons/pause_menu/pause_menu.gd | 8 +- game/ui/commons/pause_menu/pause_menu.tscn | 81 ++++----- game/ui/commons/save/save_game.gd | 9 +- game/ui/commons/save/save_game.tscn | 53 +++--- project.godot | 5 +- 35 files changed, 389 insertions(+), 254 deletions(-) create mode 100644 game/translations/game.de.translation create mode 100644 game/translations/main_menu.de.translation delete mode 100644 game/ui/commons/main_menu/flags/en_EN.png delete mode 100644 game/ui/commons/main_menu/flags/fr_FR.png create mode 100644 game/ui/commons/options/flags/de.png rename game/ui/commons/{main_menu/flags/en_EN_small.png => options/flags/en.png} (100%) rename game/ui/commons/{main_menu/flags/fr_FR_small.png => options/flags/fr.png} (100%) diff --git a/addons/escoria-core/game/core-scripts/esc/_test/test_esc_compiler.gd b/addons/escoria-core/game/core-scripts/esc/_test/test_esc_compiler.gd index 89702c15..4c69d8a4 100644 --- a/addons/escoria-core/game/core-scripts/esc/_test/test_esc_compiler.gd +++ b/addons/escoria-core/game/core-scripts/esc/_test/test_esc_compiler.gd @@ -18,6 +18,7 @@ func _test_basic() -> bool: > say player "Test5" say player "Test 6" + say player TEST:"Test 7" """ var script = escoria.esc_compiler.compile(esc.split("\n")) @@ -70,12 +71,17 @@ func _test_basic() -> bool: subject = script.events["test"].statements[1] assert(subject is ESCGroup) - assert(subject.statements.size() == 2) + assert(subject.statements.size() == 3) subject = script.events["test"].statements[1].statements[1] assert(subject is ESCCommand) assert(subject.name == "say") - assert(subject.parameters[1] == "Test 6") + assert(subject.parameters[1] == "Test 6") + + subject = script.events["test"].statements[1].statements[2] + assert(subject is ESCCommand) + assert(subject.name == "say") + assert(subject.parameters[1] == "TEST:Test 7") return true @@ -222,6 +228,8 @@ func _test_dialog() -> bool: - "Option 3" > say player "test3" + - TEST:"Option 4" + say player "test4" ! """ var script = escoria.esc_compiler.compile(esc.split("\n")) @@ -230,7 +238,7 @@ func _test_dialog() -> bool: assert(subject.size() == 1) assert(subject[0] is ESCDialog) - assert(subject[0].options.size() == 3) + assert(subject[0].options.size() == 4) subject = script.events["test"].statements[0].options[0] assert(subject is ESCDialogOption) @@ -276,6 +284,10 @@ func _test_dialog() -> bool: assert(subject[0].statements[0] is ESCCommand) assert(subject[0].statements[0].parameters.size() == 2) + subject = script.events["test"].statements[0].options[3] + assert(subject is ESCDialogOption) + assert(subject.option == "TEST:Option 4") + return true diff --git a/addons/escoria-core/game/core-scripts/esc/commands/say.gd b/addons/escoria-core/game/core-scripts/esc/commands/say.gd index 32273aaa..6f8fe4c0 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/say.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/say.gd @@ -1,7 +1,14 @@ # `say object text [type] [avatar]` # # Runs the specified string as a dialog said by the object. Blocks execution -# until the dialog finishes playing. Optional parameters: +# until the dialog finishes playing. +# +# The text supports translation keys by prepending the key and separating +# it with a `:` from the text. +# +# Example: `say player ROOM1_PICTURE:"Picture's looking good."` +# +# Optional parameters: # # * "type" determines the type of dialog UI to use. Default value is "default" # * "avatar" determines the avatar to use for the dialog. Default value is @@ -64,11 +71,15 @@ func run(command_params: Array) -> int: ] ) return ESCExecution.RC_ERROR - + + var _line = command_params[1] + if ":" in _line: + _line = tr(_line.split(":")[0]) + escoria.dialog_player.say( command_params[0], dialog_scene_name, - command_params[1] + _line ) yield(escoria.dialog_player, "dialog_line_finished") return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd index 68ba9f88..c063a8a3 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd @@ -46,6 +46,9 @@ func _init(command_string): parameters.append( parameter.substr(1, parameter.length() - 2) ) + elif ":" in parameter and '"' in parameter: + quote_open = true + parameter_values.append(parameter.replace('"', '')) elif parameter.begins_with('"'): quote_open = true parameter_values.append(parameter.substr(1)) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd index f481be2b..1cc5599a 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd @@ -5,11 +5,12 @@ class_name ESCDialogOption # Regex that matches dialog option lines const REGEX = \ - '^[^-]*- "(?