Code refactor and adding, in the README file, the instructions to add the localizations of levels and cards

This commit is contained in:
Luca Canali 2021-09-15 16:26:41 +02:00
parent 086922d0c9
commit 216db5c506
5 changed files with 34 additions and 16 deletions

View file

@ -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*.

View file

@ -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()

View file

@ -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()

View file

@ -3,6 +3,7 @@ extends Node
var chapters
func _ready():
var lang = game.lang
reload()
func reload():

View file

@ -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)