Added ingame language switch and spanish translation

This commit is contained in:
NoHomoBoi 2020-09-12 19:46:17 -05:00
parent 3c3fd8c62d
commit 73e97f841d
23 changed files with 64 additions and 43 deletions

1
.gitignore vendored
View File

@ -66,6 +66,7 @@ sm64config.txt
/assets/**/*.bin
/sound/**/*.m64
/sound/**/*.aiff
!/textures/special/*.png
!/levels/**/*custom*.png
!/levels/**/*custom*/**/*.png
!/actors/**/*custom*.png

View File

@ -982,10 +982,11 @@ const u8 *const main_font_lut[] = {
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, texture_font_char_us_comma,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
// SPECIAL CHARS: Start ID - 112:0x70
texture_font_char_accent_a, texture_font_char_accent_e, texture_font_char_accent_i, texture_font_char_accent_o,
texture_font_char_accent_u, texture_font_char_mayus_accent_a, texture_font_char_mayus_accent_e, texture_font_char_mayus_accent_i,
texture_font_char_mayus_accent_o, texture_font_char_mayus_accent_u, texture_font_char_enye, texture_font_char_mayus_enye,
texture_font_char_umlaut, texture_font_char_mayus_umlaut, texture_font_char_question, texture_font_char_exclamation,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
@ -1018,11 +1019,6 @@ const u8 *const main_font_lut[] = {
texture_font_char_us_question, texture_font_char_us_double_quote_open, texture_font_char_us_double_quote_close, texture_font_char_us_tilde,
0x0, texture_font_char_us_coin, texture_font_char_us_star_filled, texture_font_char_us_multiply,
texture_font_char_us_interpunct, texture_font_char_us_star_hollow, 0x0, 0x0,
texture_font_char_mayus_accent_a, texture_font_char_mayus_accent_e, texture_font_char_mayus_accent_i, texture_font_char_mayus_accent_o,
texture_font_char_mayus_accent_u, texture_font_char_mayus_umlaut, texture_font_char_exclamation, texture_font_char_mayus_enye,
texture_font_char_accent_a, texture_font_char_accent_e, texture_font_char_accent_i, texture_font_char_accent_o, texture_font_char_accent_u,
texture_font_char_question, texture_font_char_umlaut, texture_font_char_enye,
};
// credits font LUT 0x02008738-0x020087CB

View File

@ -429,7 +429,6 @@ static void optmenu_opt_change(struct Option *opt, s32 val) {
"Spanish",
"English"
};
printf("SWITCH LANGUAGE: %s\n", languages[configLanguage]);
set_language(get_language_by_name(languages[configLanguage]));
break;

View File

@ -174,17 +174,18 @@ static void on_anim_frame(double time) {
}
#endif
void main_func(void) {
void main_func(char *argv[]) {
static u64 pool[0x165000/8 / 4 * sizeof(void *)];
main_pool_init(pool, pool + sizeof(pool) / sizeof(pool[0]));
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);
const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR;
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path();
fs_init(sys_ropaths, gamedir, userpath);
alloc_dialog_pool();
configfile_load(configfile_name());
alloc_dialog_pool(argv[0], gamedir);
if (gCLIOpts.FullScreen == 1)
configWindow.fullscreen = true;
else if (gCLIOpts.FullScreen == 2)
@ -237,8 +238,7 @@ void main_func(void) {
audio_init();
sound_init();
thread5_game_loop(NULL);
thread5_game_loop(NULL);
inited = true;
// precache data if needed
@ -267,6 +267,6 @@ void main_func(void) {
int main(int argc, char *argv[]) {
parse_cli_opts(argc, argv);
main_func();
main_func(argv);
return 0;
}

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include <dirent.h>
#include "libs/cJSON.h"
#include "pc/configfile.h"
#define PLACEHOLDER "You are not supposed\nto be here.\n\nKeep this as a secret\n\n- Render96 Team"
@ -163,31 +164,37 @@ void load_language(char* jsonTxt, s8 language){
cJSON_free(json);
}
void alloc_languages(void){
void alloc_languages(char* exePath, char* gamedir){
languages = realloc(languages, sizeof(struct LanguageEntry*) * 30);
char * languagesDir = "./res/texts/";
char *lastSlash = NULL;
char *parent = NULL;
#ifndef WIN32
lastSlash = strrchr(exePath, '/');
#else
lastSlash = strrchr(exePath, '\\');
#endif
parent = strndup(exePath, strlen(exePath) - strlen(lastSlash));
char * languagesDir = malloc(FILENAME_MAX * sizeof(char*));
strcpy(languagesDir, parent);
strcat(languagesDir, "/");
strcat(languagesDir, gamedir);
strcat(languagesDir, "/texts/");
DIR *lf = opendir(languagesDir);
struct dirent *de;
while ((de = readdir(lf)) != NULL){
const char* extension = get_filename_ext(de->d_name);
char * file = malloc(99 * sizeof(char*));
if(strcmp(extension, "json") == 0){
strcpy(file, "");
strcat(file, "./res/texts/");
char * file = malloc(FILENAME_MAX * sizeof(char*));
if(strcmp(extension, "json") == 0){
strcpy(file, languagesDir);
strcat(file, de->d_name);
#ifndef WIN32
char * language_file = realpath(file, NULL);
#else
char * language_file = malloc(_MAX_PATH * sizeof(char));
_fullpath(language_file, file, _MAX_PATH );
#endif
languagesAmount++;
printf("Loading File: %s\n", language_file);
printf("Loading File: %s\n", file);
char * jsonTxt = read_file(language_file);
char * jsonTxt = read_file(file);
load_language(jsonTxt, languagesAmount - 1);
}
}
@ -236,7 +243,7 @@ u8* get_key_string(char* id){
return tmp;
}
void alloc_dialog_pool(void){
void alloc_dialog_pool(char* exePath, char* gamedir){
languages = malloc(sizeof(struct LanguageEntry*));
languages[0] = malloc (sizeof (struct LanguageEntry));
@ -256,8 +263,12 @@ void alloc_dialog_pool(void){
languages[0]->dialogs[i] = entry;
}
alloc_languages();
set_language(get_language_by_name("English"));
alloc_languages(exePath, gamedir);
static const char * languages[] = {
"Spanish",
"English"
};
set_language(get_language_by_name(languages[configLanguage]));
}
void dealloc_dialog_pool(void){

View File

@ -31,6 +31,6 @@ extern u8* get_key_string(char* id);
extern struct LanguageEntry* get_language_by_name(char* name);
extern struct LanguageEntry* get_language();
extern void set_language(struct LanguageEntry* new_language);
extern void alloc_dialog_pool(void);
extern void alloc_dialog_pool(char* exePath, char* gamedir);
extern void dealloc_dialog_pool(void);
#endif

View File

@ -1,11 +1,11 @@
#include "txtconv.h"
struct Character charmap[348] = {
struct Character charmap[356] = {
{"0", {0x0, NULL}}, {"1", {0x1, NULL}}, {"{65297}", {0x1, NULL}}, {"2", {0x2, NULL}}, {"{65298}", {0x2, NULL}}, {"3", {0x3, NULL}}, {"{65299}", {0x3, NULL}}, {"4", {0x4, NULL}}, {"{65300}", {0x4, NULL}}, {"5", {0x5, NULL}},
{"{65301}", {0x5, NULL}}, {"6", {0x6, NULL}}, {"{65302}", {0x6, NULL}}, {"7", {0x7, NULL}}, {"{65303}", {0x7, NULL}}, {"8", {0x8, NULL}}, {"{65304}", {0x8, NULL}}, {"9", {0x9, NULL}}, {"{65305}", {0x9, NULL}},
{"A", {0xa, NULL}}, {"{65313}", {0xa, NULL}}, {"B", {0xb, NULL}}, {"{65314}", {0xb, NULL}}, {"C", {0xc, NULL}}, {"{65315}", {0xc, NULL}}, {"D", {0xd, NULL}}, {"{65316}", {0xd, NULL}}, {"E", {0xe, NULL}},
{"{65317}", {0xe, NULL}}, {"F", {0xf, NULL}}, {"{65318}", {0xf, NULL}}, {"G", {0x10, NULL}}, {"{65319}", {0x10, NULL}}, {"H", {0x11, NULL}}, {"{65320}", {0x11, NULL}}, {"I", {0x12, NULL}}, {"{65321}", {0x12, NULL}},
{"J", {0x13, NULL}}, {"{65322}", {0x13, NULL}}, {"K", {0x14, NULL}}, {"{65323}", {0x14, NULL}}, {"L", {0x15, NULL}}, {"{65324}", {0x15, NULL}}, {"M", {0x20, NULL}}, {"{65325}", {0x16, NULL}}, {"N", {0x17, NULL}},
{"J", {0x13, NULL}}, {"{65322}", {0x13, NULL}}, {"K", {0x14, NULL}}, {"{65323}", {0x14, NULL}}, {"L", {0x15, NULL}}, {"{65324}", {0x15, NULL}}, {"M", {0x16, NULL}}, {"{65325}", {0x16, NULL}}, {"N", {0x17, NULL}},
{"{65326}", {0x17, NULL}}, {"O", {0x18, NULL}}, {"{65327}", {0x18, NULL}}, {"P", {0x19, NULL}}, {"{65328}", {0x19, NULL}}, {"Q", {0x1a, NULL}}, {"{65329}", {0x1a, NULL}}, {"R", {0x1b, NULL}}, {"{65330}", {0x1b, NULL}},
{"S", {0x1c, NULL}}, {"{65331}", {0x1c, NULL}}, {"T", {0x1d, NULL}}, {"{65332}", {0x1d, NULL}}, {"U", {0x1e, NULL}}, {"{65333}", {0x1e, NULL}}, {"V", {0x1f, NULL}}, {"{65334}", {0x1f, NULL}}, {"W", {0x20, NULL}},
{"{65335}", {0x20, NULL}}, {"X", {0x21, NULL}}, {"{65336}", {0x21, NULL}}, {"Y", {0x22, NULL}}, {"{65337}", {0x22, NULL}}, {"Z", {0x23, NULL}}, {"{65338}", {0x23, NULL}}, {"a", {0x24, NULL}}, {"b", {0x25, NULL}},
@ -41,13 +41,27 @@ struct Character charmap[348] = {
{"{00239}", {0xa2, NULL}}, {"{00223}", {0xec, NULL}}, {"{00199}", {0xed, NULL}}, {"{00231}", {0xee, NULL}}, {"{08222}", {0xf0, NULL}},
// SPECIAL CHARACTERS
{"{00161}", {0x95, NULL}}, {"{00237}", {0x95, NULL}}, {"{00225}", {0x95, NULL}}, {"{00243}", {0x95, NULL}}, {"{00201}", {0x95, NULL}}, {"{00233}", {0x95, NULL}},
{"{00241}", {0x95, NULL}}, {"{00250}", {0x95, NULL}}, {"{00218}", {0x95, NULL}}, {"{00211}", {0x95, NULL}}, {"{00252}", {0x95, NULL}}
{"{00225}", {112, NULL}},
{"{00233}", {113, NULL}},
{"{00237}", {114, NULL}},
{"{00243}", {115, NULL}},
{"{00250}", {116, NULL}},
{"{00193}", {117, NULL}},
{"{00201}", {118, NULL}},
{"{00205}", {119, NULL}},
{"{00211}", {120, NULL}},
{"{00218}", {121, NULL}},
{"{00241}", {122, NULL}},
{"{00209}", {123, NULL}},
{"{00252}", {124, NULL}},
{"{00220}", {125, NULL}},
{"{00191}", {126, NULL}},
{"{00161}", {127, NULL}}
};
struct Character getCharacter(char* ch){
struct Character tmp = {NULL, {NULL, NULL}};
for(s32 cmid = 0; cmid < 340; cmid++){
for(s32 cmid = 0; cmid < sizeof(charmap) / sizeof(struct Character); cmid++){
if(charmap[cmid].txt != NULL){
if(strncmp(charmap[cmid].txt, ch, strlen(charmap[cmid].txt)) == 0) {
tmp = charmap[cmid];
@ -103,8 +117,8 @@ u8 * getTranslatedText(char * txt){
struct Character ctm = getCharacter(tmpSpecialChar);
if(ctm.txt != NULL){
shiftArr += 6;
cid += 6;
shiftArr += 5;
cid += 5;
for(int cl = 0; cl < 2; cl++){
if(ctm.value[cl] != NULL){
tmp[cid - shiftArr + cl] = ctm.value[cl];

BIN
textures/special/accent_a.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
textures/special/accent_e.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
textures/special/accent_i.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
textures/special/accent_o.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
textures/special/accent_u.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
textures/special/enye.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
textures/special/exclamation.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

BIN
textures/special/mayus_enye.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

BIN
textures/special/mayus_umlaut.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

BIN
textures/special/question.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

BIN
textures/special/umlaut.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB