Pixel-Composer/scripts/locale_data/locale_data.gml

197 lines
4.6 KiB
Text
Raw Normal View History

2023-02-14 02:48:33 +01:00
#region locale
globalvar LOCALE, TEST_LOCALE, LOCALE_DEF;
2023-12-11 09:59:58 +01:00
LOCALE = {
fontDir: "",
config: { per_character_line_break: false },
};
TEST_LOCALE = false;
LOCALE_DEF = true;
2023-02-14 02:48:33 +01:00
function __initLocale() { #region
2023-12-08 10:11:48 +01: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
directory_verify(root);
if(check_version($"{root}/version"))
zip_unzip(lfile, root);
2023-02-14 02:48:33 +01:00
2023-12-11 09:59:58 +01:00
if(LOCALE_DEF) return;
2023-06-04 18:28:29 +02:00
loadLocale();
} #endregion
2023-06-04 18:28:29 +02:00
function __locale_file(file) { #region
2023-10-31 05:30:42 +01:00
var dirr = $"{DIRECTORY}Locale/{PREFERENCES.local}";
2023-12-08 03:50:09 +01:00
if(!directory_exists(dirr) || !file_exists_empty(dirr + file))
2023-06-05 18:27:53 +02:00
dirr = $"{DIRECTORY}Locale/en";
return dirr + file;
} #endregion
2023-06-05 18:27:53 +02:00
function loadLocale() { #region
2023-12-11 09:59:58 +01: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
2023-10-31 05:30:42 +01:00
var fontDir = $"{DIRECTORY}Locale/{PREFERENCES.local}/fonts/";
2023-06-05 18:27:53 +02:00
LOCALE.fontDir = directory_exists(fontDir)? fontDir : noone;
} #endregion
2023-06-04 18:28:29 +02:00
function __txtx(key, def = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(key == "") return "";
2023-09-28 13:15:29 +02:00
if(TEST_LOCALE) {
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}\",");
return def;
}
return "";
2023-09-28 13:15:29 +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 18:27:53 +02:00
return def;
} #endregion
2023-02-14 02:48:33 +01:00
function __txt(txt, prefix = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return txt;
if(txt == "") return "";
2023-06-04 18:28:29 +02:00
var key = string_lower(txt);
key = string_replace_all(key, " ", "_");
if(TEST_LOCALE) {
if(!struct_has(LOCALE.word, key) && !struct_has(LOCALE.ui, key)) {
show_debug_message($"LOCALE: \"{key}\": \"{txt}\",");
return txt;
}
return "";
}
2023-12-11 05:45:12 +01:00
2023-06-04 18:28:29 +02:00
return __txtx(prefix + key, txt);
} #endregion
2023-06-05 18:27:53 +02:00
function __txta(txt) { #region
var _txt = __txt(txt);
for(var i = 1; i < argument_count; i++)
_txt = string_replace_all(_txt, "{" + string(i) + "}", string(argument[i]));
return _txt;
} #endregion
function __txt_node_name(node, def = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(TEST_LOCALE) {
if(!struct_has(LOCALE.node, node)) {
show_debug_message($"LOCALE [NODE]: \"{node}\": \"{def}\",");
return def;
}
return "";
}
if(!struct_has(LOCALE.node, node))
return def;
return LOCALE.node[$ node].name;
} #endregion
2023-06-05 18:27:53 +02:00
function __txt_node_tooltip(node, def = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(TEST_LOCALE) {
if(!struct_has(LOCALE.node, node)) {
show_debug_message($"LOCALE [TIP]: \"{node}\": \"{def}\",");
return def;
}
return "";
}
2023-07-28 19:41:57 +02:00
if(!struct_has(LOCALE.node, node))
return def;
return LOCALE.node[$ node].tooltip;
} #endregion
2023-06-05 18:27:53 +02:00
function __txt_junction_name(node, type, index, def = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(TEST_LOCALE) {
if(!struct_has(LOCALE.node, node)) {
show_debug_message($"LOCALE [JNAME]: \"{node}\": \"{def}\",");
return def;
}
return "";
}
if(!struct_has(LOCALE.node, node))
2023-06-05 18:27:53 +02:00
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;
} #endregion
2023-06-05 18:27:53 +02:00
function __txt_junction_tooltip(node, type, index, def = "") { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-07-28 19:41:57 +02:00
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(TEST_LOCALE) {
if(!struct_has(LOCALE.node, node)) {
show_debug_message($"LOCALE [JTIP]: \"{node}\": \"{def}\",");
return def;
}
return "";
}
if(!struct_has(LOCALE.node, node))
2023-06-05 18:27:53 +02:00
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;
} #endregion
2023-06-05 18:27:53 +02:00
function __txt_junction_data(node, type, index, def = []) { #region
2023-11-08 08:38:04 +01:00
INLINE
2023-12-11 05:45:12 +01:00
if(LOCALE_DEF) return def;
if(TEST_LOCALE) {
if(!struct_has(LOCALE.node, node)) {
show_debug_message($"LOCALE [DDATA]: \"{node}\": \"{def}\",");
return def;
}
return [ "" ];
}
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;
return lst[index].display_data;
} #endregion
2023-02-14 02:48:33 +01:00
#endregion