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 gameid aliases #14543

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

nauta-turbidus
Copy link

@nauta-turbidus nauta-turbidus commented Apr 14, 2024

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

  • update docs

How to test

  1. Create a world under a game.
  2. Rename the folder of the game.
  3. Define the old folder name as aliases in the game.conf file.
  4. Restart Minetest.
  5. Verify if you can still see the world under the renamed game.
  6. Verify if you can still enter the world.

@wsor4035 wsor4035 added Feature ✨ PRs that add or enhance a feature @ Content / PkgMgr labels Apr 14, 2024
@nauta-turbidus nauta-turbidus marked this pull request as ready for review April 14, 2024 23:42
src/content/subgames.cpp Outdated Show resolved Hide resolved
@sfan5 sfan5 added the WIP The PR is still being worked on by its author and not ready yet. label Apr 15, 2024
@rubenwardy
Copy link
Member

rubenwardy commented Apr 15, 2024

@rubenwardy rubenwardy self-assigned this Apr 15, 2024
@rubenwardy rubenwardy added the Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR label Apr 15, 2024
@rubenwardy rubenwardy marked this pull request as draft April 15, 2024 23:11
@rubenwardy rubenwardy added Action / change needed Code still needs changes (PR) / more information requested (Issues) and removed Action / change needed Code still needs changes (PR) / more information requested (Issues) labels Apr 17, 2024
src/content/subgames.cpp Outdated Show resolved Hide resolved
src/content/subgames.cpp Outdated Show resolved Hide resolved
@nauta-turbidus nauta-turbidus marked this pull request as ready for review April 17, 2024 19:08
@rubenwardy rubenwardy changed the title WIP: Add gameid aliases Add gameid aliases Apr 17, 2024
@rubenwardy rubenwardy removed the WIP The PR is still being worked on by its author and not ready yet. label Apr 17, 2024
@rubenwardy rubenwardy self-requested a review April 17, 2024 19:29
Copy link
Contributor

@appgurueu appgurueu left a 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.

builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
src/content/subgames.cpp Outdated Show resolved Hide resolved
src/content/subgames.h Outdated Show resolved Hide resolved
src/script/lua_api/l_mainmenu.cpp Outdated Show resolved Hide resolved
Copy link
Member

@rubenwardy rubenwardy left a comment

Choose a reason for hiding this comment

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

Partial review

builtin/mainmenu/content/contentdb.lua Show resolved Hide resolved
doc/lua_api.md Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
builtin/mainmenu/init.lua Outdated Show resolved Hide resolved
builtin/mainmenu/init.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
src/content/subgames.h Outdated Show resolved Hide resolved
builtin/mainmenu/content/contentdb.lua Outdated Show resolved Hide resolved
@@ -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)
Copy link
Member

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?

Copy link
Member

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)

Copy link
Contributor

@appgurueu appgurueu left a 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){
Copy link
Contributor

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;
Copy link
Contributor

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");
Copy link
Contributor

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"))
{
Copy link
Contributor

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;
Copy link
Contributor

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Content / PkgMgr Feature ✨ PRs that add or enhance a feature Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support game rebranding
7 participants