mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-05-02 22:57:59 +03:00
read level titles
This commit is contained in:
parent
7ec31708b6
commit
aa4786a43b
4 changed files with 109 additions and 30 deletions
|
@ -263,7 +263,7 @@ void LevelStats(int32_t level_num)
|
|||
T_InitPrint();
|
||||
|
||||
// heading
|
||||
sprintf(string, "%s", LevelTitles[level_num]);
|
||||
sprintf(string, "%s", GF_LevelTitles[level_num]);
|
||||
txt = T_Print(0, -50, 0, string);
|
||||
T_CentreH(txt, 1);
|
||||
T_CentreV(txt, 1);
|
||||
|
@ -475,7 +475,7 @@ int32_t S_SaveGame(void *data, int32_t size, int32_t slot)
|
|||
return 0;
|
||||
}
|
||||
|
||||
sprintf(filename, "%s", LevelTitles[SaveGame[0].current_level]);
|
||||
sprintf(filename, "%s", GF_LevelTitles[SaveGame[0].current_level]);
|
||||
fwrite(filename, sizeof(char), 75, fp);
|
||||
fwrite(&SaveCounter, sizeof(int32_t), 1, fp);
|
||||
fwrite(data, size, 1, fp);
|
||||
|
|
|
@ -112,6 +112,85 @@ static GAME_STRING_ID StringToGameStringID(const char *str)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static void GF_LoadGameStrings(struct json_value_s *json)
|
||||
{
|
||||
struct json_value_s *strings = JSONGetField(json, "strings");
|
||||
if (!strings) {
|
||||
TRACE("missing 'strings' entry");
|
||||
return;
|
||||
}
|
||||
if (strings->type != json_type_object) {
|
||||
TRACE("'strings' must be a dictionary");
|
||||
return;
|
||||
}
|
||||
|
||||
struct json_object_s *object = json_value_as_object(strings);
|
||||
struct json_object_element_s *item = object->start;
|
||||
while (item) {
|
||||
GAME_STRING_ID key = StringToGameStringID(item->name->string);
|
||||
struct json_string_s *value = json_value_as_string(item->value);
|
||||
if (!value) {
|
||||
TRACE("invalid string key %s", item->name->string);
|
||||
item = item->next;
|
||||
continue;
|
||||
}
|
||||
if (key < 0 || key >= GSI_NUMBER_OF) {
|
||||
TRACE("invalid string key %s", item->name->string);
|
||||
item = item->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
GF_GameStringTable[key] = malloc(strlen(value->string) + 1);
|
||||
strcpy(GF_GameStringTable[key], value->string);
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
static void GF_LoadLevels(struct json_value_s *json)
|
||||
{
|
||||
struct json_value_s *levels = JSONGetField(json, "levels");
|
||||
if (!levels) {
|
||||
TRACE("missing 'levels' entry");
|
||||
return;
|
||||
}
|
||||
if (levels->type != json_type_array) {
|
||||
TRACE("'levels' must be a list");
|
||||
}
|
||||
|
||||
struct json_array_s *arr = json_value_as_array(levels);
|
||||
int32_t level_count = arr->length;
|
||||
if (level_count != LV_NUMBER_OF) {
|
||||
TRACE(
|
||||
"currently only fixed number of levels is supported! got "
|
||||
"%d, expected %d.",
|
||||
level_count, LV_NUMBER_OF);
|
||||
return;
|
||||
}
|
||||
|
||||
// GF_LevelTitles = malloc(sizeof(char *) * level_count);
|
||||
|
||||
struct json_array_element_s *item = arr->start;
|
||||
int level_num = 0;
|
||||
|
||||
while (item) {
|
||||
struct json_value_s *level_title = JSONGetField(item->value, "title");
|
||||
if (!level_title) {
|
||||
TRACE("level %d is missing title", level_num);
|
||||
} else {
|
||||
struct json_string_s *value = json_value_as_string(level_title);
|
||||
if (!value) {
|
||||
TRACE("'title' must be a string", level_num);
|
||||
} else {
|
||||
GF_LevelTitles[level_num] = malloc(strlen(value->string) + 1);
|
||||
strcpy(GF_LevelTitles[level_num], value->string);
|
||||
}
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
level_num++;
|
||||
}
|
||||
}
|
||||
|
||||
static int8_t S_LoadGameFlow(const char *file_name)
|
||||
{
|
||||
int8_t result = 0;
|
||||
|
@ -154,33 +233,8 @@ static int8_t S_LoadGameFlow(const char *file_name)
|
|||
|
||||
result = 1;
|
||||
|
||||
{
|
||||
struct json_value_s *strings = JSONGetField(json, "strings");
|
||||
if (strings && strings->type == json_type_object) {
|
||||
struct json_object_s *object = json_value_as_object(strings);
|
||||
struct json_object_element_s *item = object->start;
|
||||
while (item) {
|
||||
GAME_STRING_ID key = StringToGameStringID(item->name->string);
|
||||
struct json_string_s *value = json_value_as_string(item->value);
|
||||
if (!value) {
|
||||
TRACE("invalid gamestring value for key %d", key);
|
||||
item = item->next;
|
||||
continue;
|
||||
}
|
||||
if (key < 0 || key >= GSI_NUMBER_OF) {
|
||||
TRACE("invalid gamestring key %s", item->value);
|
||||
item = item->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
TRACE("setting %d to %s", key, value->string);
|
||||
GF_GameStringTable[key] = malloc(strlen(value->string) + 1);
|
||||
strcpy(GF_GameStringTable[key], value->string);
|
||||
GF_GameStringTable[key][strlen(value->string)] = '\0';
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
GF_LoadGameStrings(json);
|
||||
GF_LoadLevels(json);
|
||||
|
||||
cleanup:
|
||||
if (fp) {
|
||||
|
|
|
@ -8,6 +8,31 @@ int16_t StoredLaraHealth = 0;
|
|||
int16_t BarOffsetY[6];
|
||||
#endif
|
||||
|
||||
char *GF_LevelTitles[LV_NUMBER_OF] = {
|
||||
"Lara's Home",
|
||||
"Caves",
|
||||
"City of Vilcabamba",
|
||||
"Lost Valley",
|
||||
"Tomb of Qualopec",
|
||||
"St. Francis' Folly",
|
||||
"Colosseum",
|
||||
"Palace Midas",
|
||||
"The Cistern",
|
||||
"Tomb of Tihocan",
|
||||
"City of Khamoon",
|
||||
"Obelisk of Khamoon",
|
||||
"Sanctuary of the Scion",
|
||||
"Natla's Mines",
|
||||
"Atlantis",
|
||||
"The Great Pyramid",
|
||||
"Cut Scene 1",
|
||||
"Cut Scene 2",
|
||||
"Cut Scene 3",
|
||||
"Cut Scene 4",
|
||||
"Title",
|
||||
"Current Position",
|
||||
};
|
||||
|
||||
char *GF_GameStringTable[GSI_NUMBER_OF] = {
|
||||
[GSI_HEADING_INVENTORY] = "INVENTORY",
|
||||
[GSI_HEADING_GAME_OVER] = "GAME OVER",
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#define LaraItem VAR_U_(0x0045EE6C, ITEM_INFO*)
|
||||
#define PierreItem VAR_U_(0x0045E328, int16_t)
|
||||
#define LevelNames ARRAY_(0x00453648, const char*, [LV_NUMBER_OF])
|
||||
#define LevelTitles ARRAY_(0x00453DF8, const char*, [LV_NUMBER_OF])
|
||||
#define LevelMusic ARRAY_(0x00456A18, int16_t, [LV_NUMBER_OF])
|
||||
#define SecretTotals ARRAY_(0x00453CB0, int8_t, [MAX_SECRETS])
|
||||
#define ResetFlag VAR_I_(0x00459F50, int32_t, 0)
|
||||
|
@ -262,6 +261,7 @@
|
|||
|
||||
// clang-format on
|
||||
|
||||
extern char *GF_LevelTitles[LV_NUMBER_OF];
|
||||
// NOTE: missing in original code
|
||||
extern char *GF_GameStringTable[GSI_NUMBER_OF];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue