2023-02-14 02:48:33 +01:00
|
|
|
#region locale
|
2023-10-08 15:12:20 +02:00
|
|
|
globalvar LOCALE, TEST_LOCALE, LOCALE_USE_DEFAULT;
|
2023-02-14 02:48:33 +01:00
|
|
|
LOCALE = {}
|
2023-09-28 15:10:41 +02:00
|
|
|
TEST_LOCALE = false;
|
2023-10-08 15:12:20 +02:00
|
|
|
LOCALE_USE_DEFAULT = true;
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
function __initLocale() {
|
2023-06-05 18:27:53 +02:00
|
|
|
var lfile = $"data/locale/en.zip";
|
2023-06-04 18:28:29 +02:00
|
|
|
var root = $"{DIRECTORY}Locale";
|
2023-02-14 02:48:33 +01:00
|
|
|
|
|
|
|
if(!directory_exists(root))
|
|
|
|
directory_create(root);
|
2023-06-05 18:27:53 +02:00
|
|
|
zip_unzip(lfile, root);
|
2023-02-14 02:48:33 +01:00
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
loadLocale();
|
|
|
|
}
|
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
function __locale_file(file) {
|
|
|
|
var dirr = $"{DIRECTORY}Locale/{PREF_MAP[? "local"]}";
|
|
|
|
if(!directory_exists(dirr) || !file_exists(dirr + file))
|
|
|
|
dirr = $"{DIRECTORY}Locale/en";
|
|
|
|
return dirr + file;
|
|
|
|
}
|
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
function loadLocale() {
|
2023-06-05 18:27:53 +02:00
|
|
|
LOCALE.word = json_load_struct(__locale_file("/words.json"));
|
|
|
|
LOCALE.ui = json_load_struct(__locale_file("/UI.json"));
|
|
|
|
LOCALE.node = json_load_struct(__locale_file("/nodes.json"));
|
2023-06-05 19:41:01 +02:00
|
|
|
LOCALE.config = json_load_struct(__locale_file("/config.json"));
|
2023-06-05 18:27:53 +02:00
|
|
|
|
|
|
|
var fontDir = $"{DIRECTORY}Locale/{PREF_MAP[? "local"]}/fonts/";
|
|
|
|
LOCALE.fontDir = directory_exists(fontDir)? fontDir : noone;
|
2023-05-07 20:55:13 +02:00
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
print("FONT DIR: " + fontDir);
|
2023-06-04 18:28:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function __txtx(key, def = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return def;
|
|
|
|
|
2023-09-28 13:15:29 +02:00
|
|
|
if(TEST_LOCALE) {
|
2023-09-28 15:10:41 +02:00
|
|
|
if(!struct_has(LOCALE.word, key) && !struct_has(LOCALE.ui, key)) {
|
2023-09-28 13:15:29 +02:00
|
|
|
show_debug_message($"LOCALE: \"{key}\": \"{def}\",");
|
2023-09-28 15:10:41 +02:00
|
|
|
//return def;
|
|
|
|
}
|
2023-09-28 13:15:29 +02:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
return "";
|
2023-09-28 13:15:29 +02:00
|
|
|
}
|
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
if(struct_has(LOCALE.word, key))
|
2023-09-28 13:15:29 +02:00
|
|
|
return LOCALE.word[$ key];
|
2023-06-05 18:27:53 +02:00
|
|
|
if(struct_has(LOCALE.ui, key))
|
2023-09-28 13:15:29 +02:00
|
|
|
return LOCALE.ui[$ key];
|
2023-05-07 20:55:13 +02:00
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
return def;
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
function __txt(txt, prefix = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return txt;
|
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
var key = string_lower(txt);
|
|
|
|
key = string_replace_all(key, " ", "_");
|
|
|
|
|
|
|
|
return __txtx(prefix + key, txt);
|
2023-02-14 02:48:33 +01:00
|
|
|
}
|
2023-06-05 18:27:53 +02:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
function __txta(txt) {
|
|
|
|
var _txt = __txt(txt);
|
|
|
|
for(var i = 1; i < argument_count; i++)
|
|
|
|
_txt = string_replace_all(_txt, "{" + string(i) + "}", string(argument[i]));
|
|
|
|
|
|
|
|
return _txt;
|
|
|
|
}
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
function __txt_node_name(node, def = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return def;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
if(TEST_LOCALE) return "";
|
2023-06-17 14:30:49 +02:00
|
|
|
return def;
|
2023-06-05 18:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function __txt_node_tooltip(node, def = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return def;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
if(TEST_LOCALE) return "";
|
|
|
|
return LOCALE.node[$ node].tooltip;
|
2023-06-05 18:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function __txt_junction_name(node, type, index, def = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return def;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
var nde = LOCALE.node[$ node];
|
|
|
|
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
|
|
|
|
if(index >= array_length(lst)) return def;
|
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(TEST_LOCALE) return "";
|
2023-06-05 18:27:53 +02:00
|
|
|
return lst[index].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
function __txt_junction_tooltip(node, type, index, def = "") {
|
2023-07-28 19:41:57 +02:00
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-08 15:12:20 +02:00
|
|
|
if(LOCALE_USE_DEFAULT) return def;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-06-05 18:27:53 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
var nde = LOCALE.node[$ node];
|
|
|
|
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
|
|
|
|
if(index >= array_length(lst)) return def;
|
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(TEST_LOCALE) return "";
|
2023-06-05 18:27:53 +02:00
|
|
|
return lst[index].tooltip;
|
|
|
|
}
|
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
function __txt_junction_data(node, type, index, def = []) {
|
|
|
|
gml_pragma("forceinline");
|
|
|
|
|
2023-10-07 09:09:18 +02:00
|
|
|
return def;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
2023-09-28 15:10:41 +02:00
|
|
|
if(!struct_has(LOCALE.node, node))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
var nde = LOCALE.node[$ node];
|
|
|
|
var lst = type == JUNCTION_CONNECT.input? nde.inputs : nde.outputs;
|
|
|
|
if(index >= array_length(lst)) return def;
|
|
|
|
|
|
|
|
if(!struct_has(lst[index], "display_data"))
|
|
|
|
return def;
|
|
|
|
|
|
|
|
if(TEST_LOCALE) return [ "" ];
|
|
|
|
return lst[index].display_data;
|
|
|
|
}
|
2023-02-14 02:48:33 +01:00
|
|
|
#endregion
|