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

Mod Compatibility 2: Prevent Error from duplicate ids within mod_interactions folder #76983

Merged
merged 15 commits into from
Oct 18, 2024

Conversation

b3brodie
Copy link
Contributor

@b3brodie b3brodie commented Oct 12, 2024

Summary

Infrastructure "Mod Compatibility 2: Prevent Error from duplicate ids within mod_interactions folder"

Purpose of change

Allow mods to redefine their own content within their own overall mod folder, removing the need for authors to edit other mods to add compatibility for their own

Describe the solution

Pass the secondary id through the src field and strip it in locations where it is required

Describe alternatives you've considered

This Monster: #76960
Moving the check_duplicate_entries() method far closer to the initial item load

Testing

Loaded game with custom files within the mod_interactions folder that directly copy from the parent mod's types to check that everything functions.

  • Example: many types of things when examined for information will print the source mod. With this change, the source mod will only read the parent mods name, ie 'Magiclysm', without including the extra #bombastic_perks.
    Checked that the tests are functional
    Looked through the code for uses of the mod source. Most of them are either determining if the source is dda or not, which this will have no change on.

Additional context

@github-actions github-actions bot added the [C++] Changes (can be) made in C++. Previously named `Code` label Oct 12, 2024
@b3brodie b3brodie marked this pull request as ready for review October 12, 2024 00:59
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Oct 12, 2024
@b3brodie b3brodie marked this pull request as draft October 12, 2024 04:02
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 12, 2024
@b3brodie b3brodie marked this pull request as ready for review October 13, 2024 01:29
@github-actions github-actions bot added <Documentation> Design documents, internal info, guides and help. [Markdown] Markdown issues and PRs labels Oct 13, 2024
b3brodie and others added 4 commits October 12, 2024 19:17
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions and removed astyled astyled PR, label is assigned by github actions labels Oct 13, 2024
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 13, 2024
Copy link
Contributor

@ehughsbaird ehughsbaird left a comment

Choose a reason for hiding this comment

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

These need to be handled (the rest by converting them to use the first one):
xedra_evolved#magiclysm is not a valid mod_id and so they'll not be able to find ->name() for it. I suggest in the case that it needs to be split like Xedra Evolved/Magiclysm, having both names are displayed for maximal clarity.

template<typename src_id>
std::string get_origin( const std::vector<std::pair<src_id, mod_id>> &src )
{
std::string origin_str = enumerate_as_string( src.begin(),
src.end(), []( const std::pair<src_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
return string_format( _( "Origin: %s" ), origin_str );
}

Cataclysm-DDA/src/item.cpp

Lines 2403 to 2406 in 1fb836e

info.emplace_back( "BASE", string_format( _( "Origin: %s" ), enumerate_as_string( type->src,
[]( const std::pair<itype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow ) ) );

oss << get_tag_from_color( c_white ) << _( "Origin: " );
oss << enumerate_as_string( type->src.begin(),
type->src.end(), []( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );

std::string mods = enumerate_as_string( type->src.begin(),
type->src.end(),
[]( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
},
enumeration_conjunction::arrow );

const std::string mod_src = enumerate_as_string( sorted_profs[cur_id]->src, [](
const std::pair<profession_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";

const std::string mod_src = enumerate_as_string( current_scenario->src,
[]( const std::pair<string_id<scenario>, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";

const std::string mod_src = enumerate_as_string( oter->get_type_id().obj().src,
[]( const std::pair<oter_type_str_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
format_string += "\n" + string_format( _( "Origin: %s" ), mod_src );

This seems like it should be using the check_duplicate_entries mod_tracker function.

const std::string new_mod_src = enumerate_as_string( r.src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
const std::string old_mod_src = enumerate_as_string( out[ r.ident() ].src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );

doc/MODDING.md Outdated Show resolved Hide resolved
doc/MOD_COMPATABILITY.md Show resolved Hide resolved
src/mod_manager.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 13, 2024
@github-actions github-actions bot added Crafting / Construction / Recipes Includes: Uncrafting / Disassembling and removed astyled astyled PR, label is assigned by github actions labels Oct 13, 2024
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Oct 13, 2024
@b3brodie
Copy link
Contributor Author

These need to be handled (the rest by converting them to use the first one): xedra_evolved#magiclysm is not a valid mod_id and so they'll not be able to find ->name() for it. I suggest in the case that it needs to be split like Xedra Evolved/Magiclysm, having both names are displayed for maximal clarity.

template<typename src_id>
std::string get_origin( const std::vector<std::pair<src_id, mod_id>> &src )
{
std::string origin_str = enumerate_as_string( src.begin(),
src.end(), []( const std::pair<src_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
return string_format( _( "Origin: %s" ), origin_str );
}

Cataclysm-DDA/src/item.cpp

Lines 2403 to 2406 in 1fb836e

info.emplace_back( "BASE", string_format( _( "Origin: %s" ), enumerate_as_string( type->src,
[]( const std::pair<itype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow ) ) );

oss << get_tag_from_color( c_white ) << _( "Origin: " );
oss << enumerate_as_string( type->src.begin(),
type->src.end(), []( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );

std::string mods = enumerate_as_string( type->src.begin(),
type->src.end(),
[]( const std::pair<mtype_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
},
enumeration_conjunction::arrow );

const std::string mod_src = enumerate_as_string( sorted_profs[cur_id]->src, [](
const std::pair<profession_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";

const std::string mod_src = enumerate_as_string( current_scenario->src,
[]( const std::pair<string_id<scenario>, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
assembled += string_format( _( "Origin: %s" ), mod_src ) + "\n";

const std::string mod_src = enumerate_as_string( oter->get_type_id().obj().src,
[]( const std::pair<oter_type_str_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
format_string += "\n" + string_format( _( "Origin: %s" ), mod_src );

This seems like it should be using the check_duplicate_entries mod_tracker function.

const std::string new_mod_src = enumerate_as_string( r.src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );
const std::string old_mod_src = enumerate_as_string( out[ r.ident() ].src, [](
const std::pair<recipe_id, mod_id> &source ) {
return string_format( "'%s'", source.second->name() );
}, enumeration_conjunction::arrow );

Adjusted the recipes function to use the check_duplicate_entries function.

As for the rest of the areas where mod sources are printed, these are actually already working due to the change in "const MOD_INFORMATION &string_id<MOD_INFORMATION>::obj()" function. I added a debugmsg to print this in action:
name is successfully changed
I've had some issues directly tracking how ->name() calls the obj() function before printing the string, but since it does call the obj() function that means that its performing a find from the world mod_map. Since the string printed on ->name() is found via the world mod map which only contains the actual loaded mods, I'm not seeing a good way of printing a pseudo 'Magiclysm/Bombastic Perks" name rather than just "Magiclysm". Ultimately since it is Magiclysm that's the source I don't feel this is too large of an information issue.

@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 13, 2024
@ehughsbaird
Copy link
Contributor

As for the rest of the areas where mod sources are printed, these are actually already working due to the change in "const MOD_INFORMATION &string_id<MOD_INFORMATION>::obj()" function

My bad, I missed the implications of this.

I've had some issues directly tracking how ->name() calls the obj() function before printing the string, but since it does call the obj() function that means that its performing a find from the world mod_map. Since the string printed on...

The operators are defined and the function declared here

/**
* Returns the actual object this id refers to. May show a debug message if the id is invalid.
*/
const T &obj() const;
const T &operator*() const {
return obj();
}
const T *operator->() const {
return &obj();
}

With the ::obj function you modified providing the definition for that function.

If all the places I pointed out are unified to that one function, it's a matter of doing the splitting in that function and then doing a name lookup for each id.

Another approach could be creating a MOD_INFORMATION on demand when loading a mod interaction folder - it's a little gross, but so is what is happening now. For whatever my review is worth, I think this is good now.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Oct 14, 2024
@Maleclypse
Copy link
Member

Is this ready to merge or conversation ongoing?

Copy link
Contributor

@ehughsbaird ehughsbaird left a comment

Choose a reason for hiding this comment

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

LGTM

@Maleclypse Maleclypse merged commit 0764d84 into CleverRaven:master Oct 18, 2024
20 of 26 checks passed
@b3brodie b3brodie deleted the mod_compat_3 branch October 18, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Crafting / Construction / Recipes Includes: Uncrafting / Disassembling <Documentation> Design documents, internal info, guides and help. json-styled JSON lint passed, label assigned by github actions [Markdown] Markdown issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants