Improved language loading and hud

This commit is contained in:
Alex 2021-01-06 04:18:03 -06:00
parent 1c53bee114
commit 2b7dc66280
4 changed files with 3518 additions and 81 deletions

View File

@ -449,13 +449,13 @@ void render_hud_camera_status(void) {
void render_nx_hud(void){
s16 x = GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(40);
s16 y = 212;
s16 w = x + 14;
s16 h = y + 6;
s16 w = x + 12;
s16 h = y + 4;
render_hud_rectangle(x - 1, y - 1, w + 1, h + 1, 57, 57, 57);
render_hud_rectangle(w, y + 1, w + 2, y + 6, 57, 57, 57);
render_hud_rectangle(w, y, w + 2, y + 4, 57, 57, 57);
render_hud_rectangle(x, y, w, h, 194, 194, 194);
render_hud_rectangle(x, y, x + (s16)(14 * getBatteryPercentage()), h, 76, 235, 52);
render_hud_rectangle(x, y, x + (s16)(12 * getBatteryPercentage()), h, 76, 235, 52);
x = GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(20);
y = 207;

View File

@ -9,6 +9,7 @@
#include <dirent.h>
#include "libs/cJSON.h"
#include "pc/configfile.h"
#include "pc/fs/fs.h"
#define MAX_LANG 30
#define SECRET_NULL 24
@ -29,7 +30,7 @@ void load_language(char *jsonTxt, s8 language) {
cJSON *json = cJSON_ParseWithOpts(jsonTxt, &endTxt, 1);
if(*endTxt != 0) {
fprintf(stderr, "Loading File: Error before: %s\n", endTxt);
fprintf(stderr, "Loading File: Error before: %s\n", cJSON_GetErrorPtr());
exit(1);
}
@ -182,68 +183,6 @@ void load_language(char *jsonTxt, s8 language) {
cJSON_Delete(json);
}
void alloc_languages(char *exePath, char *gamedir) {
languages = realloc(languages, sizeof(struct LanguageEntry*) * MAX_LANG);
char *lastSlash = NULL;
char *parent = malloc(FILENAME_MAX * sizeof(char*));
#ifndef WIN32
lastSlash = strrchr(exePath, '/');
#else
lastSlash = strrchr(exePath, '\\');
#endif
strncpy(parent, exePath, strlen(exePath) - strlen(lastSlash));
parent[strlen(exePath) - strlen(lastSlash)] = 0;
char *languagesDir = malloc(FILENAME_MAX * sizeof(char*));
#ifndef WIN32
strcpy(languagesDir, parent);
strcat(languagesDir, "/");
strcat(languagesDir, gamedir);
strcat(languagesDir, "/texts/");
#else
strcpy(languagesDir, parent);
strcat(languagesDir, "\\");
strcat(languagesDir, gamedir);
strcat(languagesDir, "\\texts\\");
#endif
DIR *lf = opendir(languagesDir);
struct dirent *de;
while ((de = readdir(lf)) != NULL) {
const char *extension = get_filename_ext(de->d_name);
if(strcmp(extension, "json") == 0) {
char *file = malloc(FILENAME_MAX * sizeof(char*));
strcpy(file, languagesDir);
strcat(file, de->d_name);
languagesAmount++;
printf("Loading File: %s\n", file);
char *jsonTxt = read_file(file);
if(jsonTxt != NULL) {
load_language(jsonTxt, languagesAmount - 1);
}else{
fprintf(stderr, "Loading File: Error reading '%s'\n", file);
exit(1);
}
free(jsonTxt);
free(file);
}
}
free(languagesDir);
free(parent);
closedir(lf);
if(languagesAmount > 0) {
languages = realloc(languages, sizeof(struct LanguageEntry*) * (languagesAmount));
}else{
fprintf(stderr, "Loading File: No language files found, aborting.\n");
exit(1);
}
}
struct LanguageEntry *get_language_by_name(char *name) {
int id = 0;
@ -285,10 +224,39 @@ u8 *get_key_string(char *id) {
return tmp;
}
void alloc_dialog_pool(char *exePath, char *gamedir) {
languages = malloc(sizeof(struct LanguageEntry*));
static bool alloc_language(void *user, const char *path) {
const char *extension = get_filename_ext(path);
if(strcmp(extension, "json") == 0) {
languagesAmount++;
fprintf(stderr, "Loading File '%s'\n", path);
alloc_languages(exePath, gamedir);
u64 lngSize = 0;
char *jsonTxt = fs_load_file(path, &lngSize);
jsonTxt[lngSize] = '\0';
if(jsonTxt != NULL) {
load_language(jsonTxt, languagesAmount - 1);
}else{
fprintf(stderr, "Loading File: Error reading '%s'\n", path);
exit(1);
}
free(jsonTxt);
}
return true;
}
void alloc_dialog_pool(char *exePath, char *gamedir) {
languages = malloc(sizeof(struct LanguageEntry*) * 50);
fs_walk("texts", alloc_language, NULL, true);
if(languagesAmount > 0) {
languages = realloc(languages, sizeof(struct LanguageEntry*) * (languagesAmount));
}else{
fprintf(stderr, "Loading File: No language files found, aborting.\n");
exit(1);
}
if(configLanguage >= languagesAmount) {
printf("Loading File: Configured language doesn't exist, resetting to defaults.\n");

3469
texts-unconverted/PL_pl.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -145,7 +145,7 @@
"szczytu,",
"gdzie byl Wielki Bob-Omb?",
"Kiedy powiem",
"『Ruszaj,』",
"{12302}Ruszaj,{12303}",
"wyscig sie zacznie!",
"",
"Gotowy....",
@ -528,7 +528,7 @@
"lines": [
"zeby otworzyc dzrwi,",
"ktore prowadza do",
"『nieskonczonych』",
"{12302}nieskonczonych{12303}",
"schodow, potrzebujesz 70",
"Gwiazd.",
"Bwa ha ha!"
@ -683,7 +683,7 @@
"width": 200,
"lines": [
"There are four camera, or",
"『[C],』 Buttons. Press [C]^",
"{12302}[C],{12303} Buttons. Press [C]^",
"to look around using the",
"Control Stick.",
"",
@ -721,7 +721,7 @@
"Press [R] again to switch",
"to Lakitu's camera.",
"Pause the game and",
"switch the mode to 『fix』",
"switch the mode to {12302}fix{12303}",
"the camera in place while",
"holding [R]. Give it a try!"
]
@ -1357,7 +1357,7 @@
"Just stop, stand still,",
"press Start to pause the",
"game, then select",
"『Exit Course.』",
"{12302}Exit Course.{12303}",
"",
"You don't have to collect",
"all Power Stars in one",
@ -1731,7 +1731,7 @@
"You've stepped right into",
"my trap, just as I knew",
"you would! I warn you,",
"『Friend,』 watch your",
"{12302}Friend,{12303} watch your",
"step!"
]
},
@ -1933,8 +1933,8 @@
"width": 200,
"lines": [
"The shadowy star in front",
"of you is a Star",
"Marker. When you collect",
"of you is a {12302}Star",
"Marker.{12303} When you collect",
"all 8 Red Coins, the Star",
"will appear here."
]
@ -2503,7 +2503,7 @@
"",
"Be careful, though.",
"Bowser and his band",
"wrote the book on 『bad.』",
"wrote the book on {12302}bad.{12303}",
"Take my advice: When you",
"need to recover from",
"injuries, collect coins.",
@ -2985,13 +2985,13 @@
"Wiedzialem, ze dasz rade!",
"Mam dla ciebie bardzo",
"specjalna wiadomosc.",
"Dziekujemy za granie",
"{12302}Dziekujemy za granie",
"w Mario 64! To koniec",
"gry, ale nie",
"koniec zabawy. Chcemy, zebys",
"dalej gral, wiec mamy",
"cos dla ciebie.",
"Baw sie dobrze! ",
"Baw sie dobrze! {12303}",
"",
"Zespol Mario 64",
"i DAGzex"