Pixel-Composer/scripts/locale_data/locale_data.gml

98 lines
2.3 KiB
Plaintext
Raw Normal View History

2023-02-14 02:48:33 +01:00
#region locale
globalvar LOCALE;
LOCALE = {}
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-06-05 18:27:53 +02:00
if(struct_has(LOCALE.word, key))
return LOCALE.word[$ key]
if(struct_has(LOCALE.ui, key))
return LOCALE.ui[$ key]
2023-05-07 20:55:13 +02:00
2023-06-05 19:41:01 +02:00
//print($"LOCAL \"{key}\": \"{def}\",");
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-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-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-06-05 18:27:53 +02:00
if(struct_has(LOCALE.node, node))
return LOCALE.node[$ node].name;
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-06-05 18:27:53 +02:00
if(struct_has(LOCALE.node, node))
return LOCALE.node[$ node].tooltip;
return def;
}
function __txt_junction_name(node, type, index, def = "") {
2023-07-28 19:41:57 +02:00
gml_pragma("forceinline");
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;
return lst[index].name;
}
function __txt_junction_tooltip(node, type, index, def = "") {
2023-07-28 19:41:57 +02:00
gml_pragma("forceinline");
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;
return lst[index].tooltip;
}
2023-02-14 02:48:33 +01:00
#endregion