Further langauge loading improvements:

0) add more error logging and NULL checking
1) changed missing characters to lower ascii for now
This commit is contained in:
GammaTendonNine 2020-10-23 01:10:04 -05:00
parent 7874550d10
commit 3ecd6bd027
2 changed files with 17 additions and 10 deletions

View File

@ -29,7 +29,7 @@ void load_language(char *jsonTxt, s8 language){
cJSON *json = cJSON_ParseWithOpts(jsonTxt, &endTxt, 1);
if(*endTxt != 0) {
fprintf(stderr, "Error before: %s\n", endTxt);
fprintf(stderr, "Loading File: Error before: %s\n", endTxt);
exit(1);
}
@ -60,9 +60,9 @@ void load_language(char *jsonTxt, s8 language){
int eid = 0;
cJSON_ArrayForEach(dialog, dialogs) {
int id = cJSON_GetObjectItemCaseSensitive(dialog, "ID")->valueint;
struct DialogEntry *entry = malloc(sizeof(struct DialogEntry));
entry->unused = 1;
entry->linesPerBox = cJSON_GetObjectItemCaseSensitive(dialog, "linesPerBox")->valueint;
entry->leftOffset = cJSON_GetObjectItemCaseSensitive(dialog, "leftOffset")->valueint;
@ -221,7 +221,12 @@ void alloc_languages(char *exePath, char *gamedir){
printf("Loading File: %s\n", file);
char *jsonTxt = read_file(file);
load_language(jsonTxt, languagesAmount - 1);
if(jsonTxt != NULL){
load_language(jsonTxt, languagesAmount - 1);
}else{
fprintf(stderr, "Loading File: Error reading '%s'\n", file);
exit(1);
}
free(jsonTxt);
free(file);
}
@ -230,11 +235,11 @@ void alloc_languages(char *exePath, char *gamedir){
free(languagesDir);
free(parent);
closedir(lf);
if(languagesAmount > 0){
languages = realloc(languages, sizeof(struct LanguageEntry*) * (languagesAmount));
}else{
printf("Loading File: No language files found, aborting.\n");
fprintf(stderr, "Loading File: No language files found, aborting.\n");
exit(1);
}
}

View File

@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "txtconv.h"
struct Character charmap[358] = {
@ -62,10 +64,10 @@ struct Character charmap[358] = {
// *MISSING* SPECIAL CHARACTERS WITH SUBSTITIONS
// *NOTE: when adding characters here, don't forget to increment charmap size
// (value is number of '}}' in this file minus 1)
{"{00227}", {0x61, NULL}}, // latin small letter a with tilde (PT_br)
{"{00195}", {0x65, NULL}}, // latin capital letter A with tilde (PT_br)
{"{00245}", {0x91, NULL}}, // latin small letter o with tilde (PT_br)
{"{00213}", {0x95, NULL}}, // latin capital letter O with tilde (PT_br)
{"{00227}", {0x24, NULL}}, // latin small letter a with tilde (PT_br)
{"{00195}", {0x0a, NULL}}, // latin capital letter A with tilde (PT_br)
{"{00245}", {0x32, NULL}}, // latin small letter o with tilde (PT_br)
{"{00213}", {0x18, NULL}}, // latin capital letter O with tilde (PT_br)
{"{00236}", {0x2c, NULL}}, // latin small letter i with grave (ES_es)
{"{07765}", {0x33, NULL}} // latin small letter p with acute (ES_la)
};