repl: separate history by game version (#2805)

This commit is contained in:
Hat Kid 2023-07-05 20:15:46 +02:00 committed by GitHub
parent 8806a0006e
commit d24fb965d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View File

@ -11,6 +11,7 @@ void to_json(json& j, const Config& obj) {
{"numConnectToTargetAttempts", obj.target_connect_attempts},
{"asmFileSearchDirs", obj.asm_file_search_dirs},
{"keybinds", obj.keybinds},
{"perGameHistory", obj.per_game_history},
};
}
@ -51,6 +52,9 @@ void from_json(const json& j, Config& obj) {
obj.keybinds = keybinds;
}
}
if (j.contains("perGameHistory")) {
j.at("perGameHistory").get_to(obj.per_game_history);
}
// if there is game specific configuration, override any values we just set
if (j.contains(version_to_game_name(obj.game_version))) {
from_json(j.at(version_to_game_name(obj.game_version)), obj);

View File

@ -44,6 +44,7 @@ struct Config {
{KeyBind::Modifier::CTRL, "G", "Attach the debugger to the process", "(dbgc)"},
{KeyBind::Modifier::CTRL, "B", "Displays the most recently caught backtrace", "(:di)"},
{KeyBind::Modifier::CTRL, "N", "Full build of the game", "(mi)"}};
bool per_game_history = true;
};
void to_json(json& j, const Config& obj);
void from_json(const json& j, Config& obj);

View File

@ -57,13 +57,25 @@ void Wrapper::add_to_history(const std::string& line) {
}
void Wrapper::save_history() {
fs::path path = file_util::get_user_config_dir() / ".opengoal.repl.history";
fs::path path;
if (repl_config.per_game_history) {
path = file_util::get_user_config_dir() / game_version_names[repl_config.game_version] /
".opengoal.repl.history";
} else {
path = file_util::get_user_config_dir() / ".opengoal.repl.history";
}
file_util::create_dir_if_needed_for_file(path.string());
repl.history_save(path.string());
}
void Wrapper::load_history() {
fs::path path = file_util::get_user_config_dir() / ".opengoal.repl.history";
fs::path path;
if (repl_config.per_game_history) {
path = file_util::get_user_config_dir() / game_version_names[repl_config.game_version] /
".opengoal.repl.history";
} else {
path = file_util::get_user_config_dir() / ".opengoal.repl.history";
}
if (fs::exists(path)) {
repl.history_load(path.string());
} else {

View File

@ -39,7 +39,8 @@ Additionally, you can provide a `repl-config.json` to set various REPL settings,
"description": "Test Bind",
"command": "(format 0 \"hello world\")"
}
]
],
"perGameHistory": false // do not use separate history files for each game version
}
```