Skip to content

Implement in game menu for loading mods #512

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BrickPi
Copy link
Contributor

@BrickPi BrickPi commented Jul 8, 2025

Implements an in game menu that allows for the selection and loading of available mods.

Comment on lines +137 to +143
#define loaded_mods game_manager.get_mod_manager().get_loaded_mods()
if (std::find(loaded_mods.begin(), loaded_mods.end(), &mod) != loaded_mods.end()) {
mod_info_dictionary[mod_info_loaded_key] = true;
} else {
mod_info_dictionary[mod_info_loaded_key] = false;
}
#undef loaded_mods
Copy link
Member

Choose a reason for hiding this comment

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

Please do not use macros for this.

Copy link
Contributor

@wvpm wvpm Jul 9, 2025

Choose a reason for hiding this comment

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

Just store it in a local variable.

When using methods to get a value, do not assume the method returns the exact same value each invocation.
Also the method might be costly.

}

ERR_FAIL_COND_V_MSG(!game_manager.set_roots(roots, replace), FAILED, "Failed to set dataloader roots!");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the error macro?


if (!game_manager.load_mod_descriptors()) {
UtilityFunctions::push_error("Failed to load mod descriptors!");
err = FAILED;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's best to return failed here. No point continuing with a broken state.
Also this can be done using ERR_FAIL_COND_V_MSG(!game_manager.load_mod_descriptors(), FAILED, "Failed to load mod descriptors!");

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 think it could be better to load the base game if mods are broken or unavailable rather than crashing the whole game. Open to doing it either way, that was my thought process.


if (!game_manager.load_mods(roots, replace_paths, converted_mods)) {
UtilityFunctions::push_error("Failed to load mods!");
err = FAILED;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as comment L667, better to return here and use error macro.

err = FAILED;
}

auto add_message = std::bind_front(&LoadLocalisation::add_message, LoadLocalisation::get_singleton());
if (!game_manager.load_definitions(add_message)) {
UtilityFunctions::push_error("Failed to load defines!");
err = FAILED;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you update the above 2 cases, please also update this for consistency.

func _ready():
mod_info = GameSingleton.get_mod_info()
var mod_status_file := ConfigFile.new()
mod_status_file.load("user://mods.cfg")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like ModMenu & MainMenu sharing this magic string.
Shouldn't this be part of mod manager or some class?

Copy link
Contributor

@wvpm wvpm Jul 9, 2025

Choose a reason for hiding this comment

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

This file generally feels like a lot of logic and very little UI.
Consider using a cpp class similar to the BudgetMenu to do the logic.

Copy link
Contributor

@wvpm wvpm left a comment

Choose a reason for hiding this comment

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

Define "user://mods.cfg" once instead of thrice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants