Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique mem card dir for each mod #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"comments": true,
"strings": true
},
"editor.wordBasedSuggestions": true,
"editor.wordBasedSuggestions": "matchingDocuments",
"editor.snippetSuggestions": "top"
},
"python.formatting.provider": "black",
Expand Down Expand Up @@ -101,5 +101,6 @@
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
},
"C_Cpp.errorSquiggles": "disabled"
}
21 changes: 16 additions & 5 deletions common/util/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ fs::path get_user_settings_dir(GameVersion game_version) {
return get_user_config_dir() / game_version_name / "settings";
}

fs::path get_user_memcard_dir(GameVersion game_version) {
auto game_version_name = game_version_names[game_version];
return get_user_config_dir() / game_version_name / "saves";
}


fs::path get_user_misc_dir(GameVersion game_version) {
auto game_version_name = game_version_names[game_version];
Expand Down Expand Up @@ -130,6 +127,17 @@ std::string get_current_executable_path() {
#endif
}

std::string get_mod_name() {
//Returns the name of the folder that gk is in, useful for detecting name of mod for unique saves and other implmentations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in development though the binary will be like out/build/Release/bin/gk.exe, so won't you end up with bin as the mod name? not the end of the world but maybe a bit confusing... I'm not sure what's the best way to avoid having some sort of MOD_NAME_PLEASE_CHANGE_THIS somewhere...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in development source everything would still share saves like it currently does in the bin folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what's the best way to avoid having some sort of MOD_NAME_PLEASE_CHANGE_THIS somewhere...

imo, this isn't a bad thing -- but you obviously want it somewhere sensible. It's far better for a mod to provide a name than for the tooling to just try to assume or figure it out.

The most obvious reasons that comes to mind are imagine if two mods have the same name / if the folder structures of the mods change / etc.

  • In the short-term, this could just be a CLI arg that the launcher(s) provide.
  • In the long-term, mods would have their own project file that could set metadata like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda liked it just being dependent on the name of the folder myself, but yeah we could add some metadata somewhere I guess. I mostly just named this function badly. Its more get_folder_name() and not mod_name for certain things and having one source of truth yeah falling back to a json/metadata in ONE spot is good.

std::string executablePath = get_current_executable_path();
size_t lastSeparator = executablePath.find_last_of("/\\");
if (lastSeparator != std::string::npos) {
return executablePath.substr(0, lastSeparator);
} else {
return "error_unknown_mod";
}
}

std::string get_parent_directory(const std::string& path) {
// Find the last occurrence of ".github" in the path.
size_t github_index = path.rfind(".github");
Expand All @@ -145,7 +153,10 @@ std::string get_parent_directory(const std::string& path) {
return parent_directory;
}


fs::path get_user_memcard_dir(GameVersion game_version) {
auto game_version_name = game_version_names[game_version];
return get_user_config_dir() / game_version_name / "saves" / get_mod_name();
}

std::optional<std::string> try_get_project_path_from_path(const std::string& path) {
// std::string::size_type pos =
Expand Down
Binary file modified out/build/Release/bin/decompiler.exe
Binary file not shown.
Binary file modified out/build/Release/bin/extractor.exe
Binary file not shown.
Binary file modified out/build/Release/bin/gk.exe
Binary file not shown.
Binary file modified out/build/Release/bin/goalc.exe
Binary file not shown.