From 216db5c5067177086d8552a5362556bca39ac0a2 Mon Sep 17 00:00:00 2001 From: Luca Canali Date: Wed, 15 Sep 2021 16:26:41 +0200 Subject: [PATCH] Code refactor and adding, in the README file, the instructions to add the localizations of levels and cards --- README.md | 12 ++++++++++++ scenes/cards.gd | 1 - scenes/game.gd | 6 +++++- scenes/levels.gd | 1 + scenes/title.gd | 30 ++++++++++++++++-------------- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0f7ee77..5c47bf5 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,18 @@ A level can consist of multiple repositories. To have more than one, you can use At this stage, we're still exploring ourselves which kind of levels would be fun! So feel free to try new things: basic introductions with a little story? Really hard puzzles? Levels where you have to find information? Levels where you need to fix a problem? Levels with three remotes? +## Add localizations +1. Add the localization text into the section "description" in the file ./resource/cards.json + Example: + "description": { + "en_EN": "Drag this card into the empty space above to initialize the time machine!", + "it_IT": "Trascina questa carta nell'area vuota sopra per inizializzare la macchina del tempo", + "es_ES": "" + } +2. Add, into the directory *levels*, the directory with the levels to you want to adding (es. ./levels/fr_FR/LIVELLI ) +1. Add, the localization into the dictionary game.langs (es. var langs = {0: "en_EN", 1: "it_IT", 2: "es_ES"} the first and default localization it must be en_EN + + ## Contribute code! To open the game in the [Godot editor](https://godotengine.org), run `godot project.godot`. You can then run the game using *F5*. diff --git a/scenes/cards.gd b/scenes/cards.gd index ee03e89..aed300e 100644 --- a/scenes/cards.gd +++ b/scenes/cards.gd @@ -3,7 +3,6 @@ extends Control var card_store = {} var cards var card_radius = 1500 -#var lang = "it" # TODO: Make a global variable to setting dir and cards localizations func _ready(): load_card_store() diff --git a/scenes/game.gd b/scenes/game.gd index e8d689e..9cd9f92 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -1,5 +1,6 @@ extends Node +var langs = {0: "en_EN", 1: "it_IT"} # Localizations allowed var lang = OS.get_locale() # Variable for game localization var tmp_prefix = OS.get_user_data_dir() + "/tmp/" @@ -20,7 +21,10 @@ var state = {} var mutex func _ready(): - print(lang) + # Check if present localization language + if not langs.values().has(lang): + lang = langs[0] + mutex = Mutex.new() load_state() diff --git a/scenes/levels.gd b/scenes/levels.gd index 25593f7..5a3d9f9 100644 --- a/scenes/levels.gd +++ b/scenes/levels.gd @@ -3,6 +3,7 @@ extends Node var chapters func _ready(): + var lang = game.lang reload() func reload(): diff --git a/scenes/title.gd b/scenes/title.gd index b79d977..cf99a2d 100644 --- a/scenes/title.gd +++ b/scenes/title.gd @@ -3,6 +3,7 @@ extends Control onready var popup = $VBoxContainer/Language func _ready(): + check_correct_lang_item() if !OS.has_feature("standalone") and !game.skipped_title: game.skipped_title = true get_tree().change_scene("res://scenes/level_select.tscn") @@ -26,28 +27,31 @@ func sandbox(): get_tree().change_scene("res://scenes/main.tscn") +# Check the apropriate locale +func check_correct_lang_item(): + for i in game.langs.keys(): + if game.lang == game.langs[i]: + popup.get_popup().set_item_checked(i, true) + +# Set all items to unchecked func uncheck_all_item(): - # Set all item unchecked - var num = popup.get_popup().get_item_count() - for n in num: - popup.get_popup().set_item_checked(n, false) - pass + for i in game.langs.keys(): + popup.get_popup().set_item_checked(i, false) +# Create popup items width allowed locales func make_popup_item(): - popup.get_popup().add_radio_check_item("en_EN", 0) - popup.get_popup().add_radio_check_item(tr("it_IT"), 1) + for i in game.langs.keys(): + popup.get_popup().add_radio_check_item(game.langs[i], i) uncheck_all_item() - if game.lang == "en_EN": - popup.get_popup().set_item_checked(0, true) - elif game.lang == "it_IT": - popup.get_popup().set_item_checked(1, true) + check_correct_lang_item() popup.get_popup().connect("id_pressed", self, "_on_item_pressed") +# Change the translations and localizations of the cards and strings func _on_item_pressed(id): uncheck_all_item() @@ -56,6 +60,4 @@ func _on_item_pressed(id): TranslationServer.set_locale(game.lang) - # DELETE ME - print(popup.get_popup().get_item_text(id)) - print(game.lang) +