From ae219f257d2e28e3050488395df0efd4da5dacd6 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 30 Jan 2023 20:45:03 -0500 Subject: [PATCH] repl: support game-specific `startup.gc` files (#2176) --- common/repl/util.cpp | 17 +++++++++++++---- common/repl/util.h | 2 +- goalc/main.cpp | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/repl/util.cpp b/common/repl/util.cpp index 9fc926bba4..bddd44aea9 100644 --- a/common/repl/util.cpp +++ b/common/repl/util.cpp @@ -171,7 +171,7 @@ void Wrapper::init_settings() { // TODO - command to print out keybinds void Wrapper::reload_startup_file() { - startup_file = load_user_startup_file(username); + startup_file = load_user_startup_file(username, repl_config.game_version); } std::string find_repl_username() { @@ -197,10 +197,19 @@ std::string find_repl_username() { return "#f"; } -StartupFile load_user_startup_file(const std::string& username) { +fs::path get_startup_file_path(const std::string& username, const GameVersion game_version) { + // - first check to see if there is a game version specific startup file to prefer + auto game_specific_path = file_util::get_jak_project_dir() / "goal_src" / "user" / username / + fmt::format("startup-{}.gc", version_to_game_name(game_version)); + if (file_util::file_exists(game_specific_path.string())) { + return game_specific_path; + } + return file_util::get_jak_project_dir() / "goal_src" / "user" / username / "startup.gc"; +} + +StartupFile load_user_startup_file(const std::string& username, const GameVersion game_version) { // Check for a `startup.gc` file, each line will be executed on the REPL on startup - auto startup_file_path = - file_util::get_jak_project_dir() / "goal_src" / "user" / username / "startup.gc"; + auto startup_file_path = get_startup_file_path(username, game_version); StartupFile startup_file; if (file_util::file_exists(startup_file_path.string())) { auto data = file_util::read_text_file(startup_file_path); diff --git a/common/repl/util.h b/common/repl/util.h index df2528ba3c..0f2510466a 100644 --- a/common/repl/util.h +++ b/common/repl/util.h @@ -52,6 +52,6 @@ class Wrapper { }; std::string find_repl_username(); -StartupFile load_user_startup_file(const std::string& username); +StartupFile load_user_startup_file(const std::string& username, const GameVersion game_version); REPL::Config load_repl_config(const std::string& username, const GameVersion game_version); } // namespace REPL diff --git a/goalc/main.cpp b/goalc/main.cpp index 91996157ad..c1af2bbd7f 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -87,7 +87,7 @@ int main(int argc, char** argv) { username = REPL::find_repl_username(); } // Load the user's startup file - auto startup_file = REPL::load_user_startup_file(username); + auto startup_file = REPL::load_user_startup_file(username, game_version); // TODO - deprecate these two flags if (startup_file.run_before_listen.empty() && (auto_debug || auto_listen)) { startup_file.run_before_listen.push_back("(lt)");