Skip to content

Commit

Permalink
console/cmd: simplify config-related options code
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 19, 2024
1 parent fa078e0 commit 651ba88
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 116 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- fixed config JSON not sanitizing some numeric values (#1515)
- fixed potential crashes in custom levels if hybrid creature objects are not present in the level (#1444)
- changed `/tp` console command to look for the closest place to teleport to when targeting items (#1484)
- changed `/set` console command output to always use fully-qualified option names
- changed `/fps`, `/vsync`, `/wireframe`, `/braid` and `/cheats` console commands output to be in line with `/set` console command output
- changed the door cheat to also target drawbridges
- improved appearance of textures around edges when bilinear filter is off (#1483)
Since this removes the seams on pushblocks, this was made optional.
Expand Down
8 changes: 0 additions & 8 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,6 @@
"MISC_EMPTY_SLOT_FMT": "- EMPTY SLOT %d -",
"MISC_OFF": "Off",
"MISC_ON": "On",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_BRAID_ON": "Braid enabled",
"OSD_CHEATS_OFF": "Cheats disabled",
"OSD_CHEATS_ON": "Cheats enabled",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_COMPLETE_LEVEL": "Level complete!",
Expand Down Expand Up @@ -752,10 +748,6 @@
"OSD_TEXTURE_FILTER_NN": "nearest-neighbor",
"OSD_TEXTURE_FILTER_SET": "Texture filter set to %s",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"PASSPORT_EXIT_GAME": "Exit Game",
"PASSPORT_EXIT_TO_TITLE": "Exit to Title",
"PASSPORT_LEGACY_SELECT_LEVEL_1": "Legacy saves do not",
Expand Down
8 changes: 0 additions & 8 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@
"MISC_EMPTY_SLOT_FMT": "- EMPTY SLOT %d -",
"MISC_OFF": "Off",
"MISC_ON": "On",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_BRAID_ON": "Braid enabled",
"OSD_CHEATS_OFF": "Cheats disabled",
"OSD_CHEATS_ON": "Cheats enabled",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_COMPLETE_LEVEL": "Level complete!",
Expand Down Expand Up @@ -247,10 +243,6 @@
"OSD_TEXTURE_FILTER_NN": "nearest-neighbor",
"OSD_TEXTURE_FILTER_SET": "Texture filter set to %s",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"PASSPORT_EXIT_GAME": "Exit Game",
"PASSPORT_EXIT_TO_TITLE": "Exit to Title",
"PASSPORT_LEGACY_SELECT_LEVEL_1": "Legacy saves do not",
Expand Down
8 changes: 0 additions & 8 deletions data/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@
"MISC_EMPTY_SLOT_FMT": "- EMPTY SLOT %d -",
"MISC_OFF": "Off",
"MISC_ON": "On",
"OSD_BRAID_OFF": "Braid disabled",
"OSD_BRAID_ON": "Braid enabled",
"OSD_CHEATS_OFF": "Cheats disabled",
"OSD_CHEATS_ON": "Cheats enabled",
"OSD_COMMAND_BAD_INVOCATION": "Invalid invocation: %s",
"OSD_COMMAND_UNAVAILABLE": "This command is not currently available",
"OSD_COMPLETE_LEVEL": "Level complete!",
Expand Down Expand Up @@ -319,10 +315,6 @@
"OSD_TEXTURE_FILTER_NN": "nearest-neighbor",
"OSD_TEXTURE_FILTER_SET": "Texture filter set to %s",
"OSD_UNKNOWN_COMMAND": "Unknown command: %s",
"OSD_VSYNC_OFF": "VSync disabled",
"OSD_VSYNC_ON": "VSync enabled",
"OSD_WIREFRAME_OFF": "Wireframe disabled",
"OSD_WIREFRAME_ON": "Wireframe enabled",
"PASSPORT_EXIT_GAME": "Exit Game",
"PASSPORT_EXIT_TO_TITLE": "Exit to Title",
"PASSPORT_LEGACY_SELECT_LEVEL_1": "Legacy saves do not",
Expand Down
118 changes: 35 additions & 83 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

static bool Console_Cmd_IsFloatRound(const float num);
static COMMAND_RESULT Console_Cmd_Fps(const char *const args);
static COMMAND_RESULT Console_Cmd_VSync(const char *const args);
static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args);
static COMMAND_RESULT Console_Cmd_Braid(const char *const args);
static COMMAND_RESULT Console_Cmd_Cheats(const char *const args);
static COMMAND_RESULT Console_Cmd_Teleport(const char *const args);
static COMMAND_RESULT Console_Cmd_Heal(const char *const args);
static COMMAND_RESULT Console_Cmd_Fly(const char *const args);
static COMMAND_RESULT Console_Cmd_Speed(const char *const args);
static COMMAND_RESULT Console_Cmd_VSync(const char *const args);
static COMMAND_RESULT Console_Cmd_Braid(const char *const args);
static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args);
static COMMAND_RESULT Console_Cmd_Cheats(const char *const args);
static COMMAND_RESULT Console_Cmd_GiveItem(const char *args);
static COMMAND_RESULT Console_Cmd_FlipMap(const char *args);
static COMMAND_RESULT Console_Cmd_Kill(const char *args);
Expand All @@ -63,28 +63,36 @@ static inline bool Console_Cmd_IsFloatRound(const float num)

static COMMAND_RESULT Console_Cmd_Fps(const char *const args)
{
if (String_Equivalent(args, "60")) {
g_Config.rendering.fps = 60;
Config_Write();
Config_ApplyChanges();
Console_Log(GS(OSD_FPS_SET), g_Config.rendering.fps);
return CR_SUCCESS;
}
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.rendering.fps), args);
}

if (String_Equivalent(args, "30")) {
g_Config.rendering.fps = 30;
Config_Write();
Config_ApplyChanges();
Console_Log(GS(OSD_FPS_SET), g_Config.rendering.fps);
return CR_SUCCESS;
}
static COMMAND_RESULT Console_Cmd_VSync(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(
&g_Config.rendering.enable_vsync),
args);
}

if (String_Equivalent(args, "")) {
Console_Log(GS(OSD_FPS_GET), g_Config.rendering.fps);
return CR_SUCCESS;
}
static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(
&g_Config.rendering.enable_wireframe),
args);
}

return CR_BAD_INVOCATION;
static COMMAND_RESULT Console_Cmd_Braid(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.enable_braid), args);
}

static COMMAND_RESULT Console_Cmd_Cheats(const char *const args)
{
return Console_Cmd_Config_Helper(
Console_Cmd_Config_GetOptionFromTarget(&g_Config.enable_cheats), args);
}

static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
Expand Down Expand Up @@ -266,62 +274,6 @@ static COMMAND_RESULT Console_Cmd_Speed(const char *const args)
return CR_BAD_INVOCATION;
}

static COMMAND_RESULT Console_Cmd_VSync(const char *const args)
{
bool enable;
if (!String_ParseBool(args, &enable)) {
return CR_BAD_INVOCATION;
}

g_Config.rendering.enable_vsync = enable;
Config_Write();
Config_ApplyChanges();
Console_Log(enable ? GS(OSD_VSYNC_ON) : GS(OSD_VSYNC_OFF));
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Braid(const char *const args)
{
bool enable;
if (!String_ParseBool(args, &enable)) {
return CR_BAD_INVOCATION;
}

g_Config.enable_braid = enable;
Config_Write();
Config_ApplyChanges();
Console_Log(enable ? GS(OSD_BRAID_ON) : GS(OSD_BRAID_OFF));
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Wireframe(const char *const args)
{
bool enable;
if (!String_ParseBool(args, &enable)) {
return CR_BAD_INVOCATION;
}

g_Config.rendering.enable_wireframe = enable;
Config_Write();
Config_ApplyChanges();
Console_Log(enable ? GS(OSD_WIREFRAME_ON) : GS(OSD_WIREFRAME_OFF));
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_Cheats(const char *const args)
{
bool enable;
if (!String_ParseBool(args, &enable)) {
return CR_BAD_INVOCATION;
}

g_Config.enable_cheats = enable;
Config_Write();
Config_ApplyChanges();
Console_Log(enable ? GS(OSD_CHEATS_ON) : GS(OSD_CHEATS_OFF));
return CR_SUCCESS;
}

static COMMAND_RESULT Console_Cmd_GiveItem(const char *args)
{
if (g_GameInfo.current_level_type == GFL_TITLE
Expand Down Expand Up @@ -647,14 +599,14 @@ static COMMAND_RESULT Console_Cmd_Abortion(const char *args)

CONSOLE_COMMAND *g_ConsoleCommands[] = {
&(CONSOLE_COMMAND) { .prefix = "fps", .proc = Console_Cmd_Fps },
&(CONSOLE_COMMAND) { .prefix = "vsync", .proc = Console_Cmd_VSync },
&(CONSOLE_COMMAND) { .prefix = "wireframe", .proc = Console_Cmd_Wireframe },
&(CONSOLE_COMMAND) { .prefix = "braid", .proc = Console_Cmd_Braid },
&(CONSOLE_COMMAND) { .prefix = "cheats", .proc = Console_Cmd_Cheats },
&(CONSOLE_COMMAND) { .prefix = "tp", .proc = Console_Cmd_Teleport },
&(CONSOLE_COMMAND) { .prefix = "heal", .proc = Console_Cmd_Heal },
&(CONSOLE_COMMAND) { .prefix = "fly", .proc = Console_Cmd_Fly },
&(CONSOLE_COMMAND) { .prefix = "speed", .proc = Console_Cmd_Speed },
&(CONSOLE_COMMAND) { .prefix = "vsync", .proc = Console_Cmd_VSync },
&(CONSOLE_COMMAND) { .prefix = "braid", .proc = Console_Cmd_Braid },
&(CONSOLE_COMMAND) { .prefix = "wireframe", .proc = Console_Cmd_Wireframe },
&(CONSOLE_COMMAND) { .prefix = "cheats", .proc = Console_Cmd_Cheats },
&(CONSOLE_COMMAND) { .prefix = "give", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "gimme", .proc = Console_Cmd_GiveItem },
&(CONSOLE_COMMAND) { .prefix = "flip", .proc = Console_Cmd_FlipMap },
Expand Down
8 changes: 0 additions & 8 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ GS_DEFINE(OSD_POS_SET_ITEM, "Teleported to object: %s")
GS_DEFINE(OSD_POS_SET_ITEM_FAIL, "Failed to teleport to object: %s")
GS_DEFINE(OSD_SPEED_GET, "Current speed: %d")
GS_DEFINE(OSD_SPEED_SET, "Speed set to %d")
GS_DEFINE(OSD_BRAID_ON, "Braid enabled")
GS_DEFINE(OSD_BRAID_OFF, "Braid disabled")
GS_DEFINE(OSD_WIREFRAME_ON, "Wireframe enabled")
GS_DEFINE(OSD_WIREFRAME_OFF, "Wireframe disabled")
GS_DEFINE(OSD_VSYNC_ON, "VSync enabled")
GS_DEFINE(OSD_VSYNC_OFF, "VSync disabled")
GS_DEFINE(OSD_CHEATS_ON, "Cheats enabled")
GS_DEFINE(OSD_CHEATS_OFF, "Cheats disabled")
GS_DEFINE(OSD_GIVE_ITEM, "Added %s to Lara's inventory")
GS_DEFINE(OSD_GIVE_ITEM_ALL_KEYS, "Surprise! Every key item Lara needs is now in her backpack.")
GS_DEFINE(OSD_GIVE_ITEM_ALL_GUNS, "Lock'n'load - Lara's armed to the teeth!")
Expand Down
2 changes: 1 addition & 1 deletion subprojects/libtrx

0 comments on commit 651ba88

Please sign in to comment.