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? 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! ## 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*. 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 card_store = {}
var cards var cards
var card_radius = 1500 var card_radius = 1500
#var lang = "it" # TODO: Make a global variable to setting dir and cards localizations
func _ready(): func _ready():
load_card_store() load_card_store()

View file

@ -1,5 +1,6 @@
extends Node extends Node
var langs = {0: "en_EN", 1: "it_IT"} # Localizations allowed
var lang = OS.get_locale() # Variable for game localization var lang = OS.get_locale() # Variable for game localization
var tmp_prefix = OS.get_user_data_dir() + "/tmp/" var tmp_prefix = OS.get_user_data_dir() + "/tmp/"
@ -20,7 +21,10 @@ var state = {}
var mutex var mutex
func _ready(): func _ready():
print(lang) # Check if present localization language
if not langs.values().has(lang):
lang = langs[0]
mutex = Mutex.new() mutex = Mutex.new()
load_state() load_state()

View file

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

View file

@ -3,6 +3,7 @@ extends Control
onready var popup = $VBoxContainer/Language onready var popup = $VBoxContainer/Language
func _ready(): func _ready():
check_correct_lang_item()
if !OS.has_feature("standalone") and !game.skipped_title: if !OS.has_feature("standalone") and !game.skipped_title:
game.skipped_title = true game.skipped_title = true
get_tree().change_scene("res://scenes/level_select.tscn") get_tree().change_scene("res://scenes/level_select.tscn")
@ -26,28 +27,31 @@ func sandbox():
get_tree().change_scene("res://scenes/main.tscn") 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(): func uncheck_all_item():
# Set all item unchecked for i in game.langs.keys():
var num = popup.get_popup().get_item_count() popup.get_popup().set_item_checked(i, false)
for n in num:
popup.get_popup().set_item_checked(n, false)
pass
# Create popup items width allowed locales
func make_popup_item(): func make_popup_item():
popup.get_popup().add_radio_check_item("en_EN", 0) for i in game.langs.keys():
popup.get_popup().add_radio_check_item(tr("it_IT"), 1) popup.get_popup().add_radio_check_item(game.langs[i], i)
uncheck_all_item() uncheck_all_item()
if game.lang == "en_EN": check_correct_lang_item()
popup.get_popup().set_item_checked(0, true)
elif game.lang == "it_IT":
popup.get_popup().set_item_checked(1, true)
popup.get_popup().connect("id_pressed", self, "_on_item_pressed") 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): func _on_item_pressed(id):
uncheck_all_item() uncheck_all_item()
@ -56,6 +60,4 @@ func _on_item_pressed(id):
TranslationServer.set_locale(game.lang) TranslationServer.set_locale(game.lang)
# DELETE ME
print(popup.get_popup().get_item_text(id))
print(game.lang)