-
Notifications
You must be signed in to change notification settings - Fork 2k
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 gameid aliases #14543
base: master
Are you sure you want to change the base?
Add gameid aliases #14543
Conversation
|
7dc075d
to
3e76d71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Gave the code a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review
d96d51c
to
627db36
Compare
@@ -93,6 +93,10 @@ The game directory can contain the following files: | |||
an internal ID used to track versions. | |||
* `textdomain`: Textdomain used to translate description. Defaults to game id. | |||
See [Translating content meta](#translating-content-meta). | |||
* `aliases = <comma-separated aliases>` | |||
e.g. `aliases = aa,bb` (game has been named "aa" and then "bb" before) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes it sound like the order is relevant. is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also clarify that it's the technical game name, gameid
. For example:
* `aliases = <comma-separated gameid aliases>`
e.g. `aliases = foo, bar` (where "foo" and "bar" are the legacy names)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Also tested with void game, works for worlds.)
@@ -101,6 +101,15 @@ SubgameSpec findSubgame(const std::string &id) | |||
std::string share = porting::path_share; | |||
std::string user = porting::path_user; | |||
|
|||
auto normalize_game_id = [&](std::string_view name){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make this lambda return a std::string
so you don't need to cast or construct for every usage, and don't need to worry about lifetimes either. Game names are short and few, this is absolutely irrelevant in terms of performance.
return SubgameSpec(); | ||
// Failed to find the game, try to find aliased game | ||
if (game_path.empty()) { | ||
std::vector<GameFindPath> gamespaths; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nitpick: You could use a list-initialization rather than emplacing the two paths.
@@ -332,6 +332,18 @@ int ModApiMainMenu::l_get_games(lua_State *L) | |||
lua_pushstring(L, game.menuicon_path.c_str()); | |||
lua_settable(L, top_lvl2); | |||
|
|||
lua_pushstring(L, "aliases"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting nitpick: Odd argument list spacing. Surrounding code does this in an attempt to align the calls. I'd say just don't.
@@ -170,14 +224,22 @@ SubgameSpec findSubgame(const std::string &id) | |||
if (conf.exists("release")) | |||
game_release = conf.getS32("release"); | |||
|
|||
std::unordered_set<std::string> aliases; | |||
if (conf.exists("aliases")) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt nitpick: if (...) {
std::string conf_path = path + DIR_DELIM + dln.name + | ||
DIR_DELIM + "game.conf"; | ||
if (!conf.readConfigFile(conf_path.c_str())) | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code up to this point - the code for finding games with conf files - should be mostly identical to the code in getAvailableGameIds
. Why not extract it into a common function? (Very roughly, I'm imagining something like findGames(std::function<void(Settings)> cb)
or std::vector<Settings> findConfFiles
or similar)
(Going through all other games for every game to determine aliases also doesn't feel quite right to me, though it's most probably fine in practice.)
Allows defining gameid aliases, so that a game can be completely renamed.
Fixes #13662
Roadmap: 2.2 (refactoring), sort of.
To do
This PR is Ready for Review
How to test
aliases
in the game.conf file.