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: Only load files within "mod_interactions" if requisite mod is loaded #76632

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

Conversation

b3brodie
Copy link
Contributor

@b3brodie b3brodie commented Sep 23, 2024

Summary

Infrastructure "Mod Compatibility: Only load files within "mod_interactions" if requisite mod is loaded"

Purpose of change

Allow mods to dynamically load / unload content based on if other mods are loaded.
Fixes #71761

Describe the solution

When loading mod json files, first ignore any file within the mod_interactions folder. Then, read the directories within the mod_interactions directory. Compare these directories to the active mod ids, and if there is a match, load the files within that specific directory.

Style Scheme:

  • "mod_interactions" folder
  • sub-directories must be named after the mod_id for them to be loaded

Renames all existing mod interactions folders to meet this standard

Programmatic Explanation

load_mod_data_from_dir()

  • wrapper method for add_mod_data_from_path().
  • Used in the load_world_modfiles() and load_packs() methods

add_mod_data_from_path()

  • Implements the new functionality of only loading folders in mod_interactions if the requisite mod is loaded
  • Does so by calling the new get_files_from_path_with_exclusion() method to ignore mod_interactions, and then reading all directories within the mod interactions file and only loading them if the requisite mod is loaded.

get_directories()

  • returns every directory within the given directory. Made because the existing directory methods with a blank pattern input return an empty vector.

get_files_from_path_with_path_exclusion()

  • similar to get_files_from_path, but with an extra parameter that reads the full path of each file and rejects it if it matches.

name_contains()

  • added parameter to allow reading from full path rather than just the filename.

Describe alternatives you've considered

Currently, this solution does not support multi-mod interaction folders. IE, a folder named "magiclysm,aftershock" or similar that is only loaded if both Magiclysm and Aftershock are loaded.

Testing

Did the following with custom edits to mods such as copy-from'ing mutations.

Tested that mods without mod_interactions folders don't crash / throw errors
Tested that content within mod_interactions directory is hidden by default unless correct mod is loaded.
Tested that mod_interaction folder content is after every mod is loaded. Mod_interaction folder content is still loaded in the same order as the mods they're from in comparison with eachother.

Additional context

Does Not Do:
Allow extra definitions of the same id within the mod_interactions file. IE: tool id named "tool_a" within the main mod folder with a redefinition of "tool_a" in "mod_interactions/aftershock" folder. The logic preventing this is separate but I may adjust it in another PR.

@github-actions github-actions bot added NPC / Factions NPCs, AI, Speech, Factions, Ownership [JSON] Changes (can be) made in JSON Mods Issues related to mods or modding Map / Mapgen Overmap, Mapgen, Map extras, Map display Spawn Creatures, items, vehicles, locations appearing on map [C++] Changes (can be) made in C++. Previously named `Code` Monsters Monsters both friendly and unfriendly. Scenarios New Scenarios, balancing, bugs with scenarios Mods: Magiclysm Anything to do with the Magiclysm mod Mods: Aftershock Anything to do with the Aftershock mod Mods: Defense Mode Anything to do with the Defense Mode mod EOC: Effects On Condition Anything concerning Effects On Condition Mods: Xedra Evolved Anything to do with Xedra Evolved Mods: Mind Over Matter Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style json-styled JSON lint passed, label assigned by github actions labels Sep 23, 2024
@Standing-Storm
Copy link
Contributor

What happens if I put in a copy-from in one mod on a mutation only found in a second mod, but due to load order, the copy-from is loaded first (like, if I make an XE interaction in MoM where Ierde are immune to telepathy, but XE loads after MoM)? Is the copy-from ignored and the original trait wins?

@b3brodie
Copy link
Contributor Author

What happens if I put in a copy-from in one mod on a mutation only found in a second mod, but due to load order, the copy-from is loaded first (like, if I make an XE interaction in MoM where Ierde are immune to telepathy, but XE loads after MoM)? Is the copy-from ignored and the original trait wins?

The goal is for the copy from to load last regardless of load order. Right now this is still in the testing / dev stage so I'm not sure if that part works. Currently I've just confirmed that the files are / are not loaded

@github-actions github-actions bot added <Bugfix> This is a fix for a bug (or closes open issue) BasicBuildPassed This PR builds correctly, label assigned by github actions labels Sep 23, 2024
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Sep 25, 2024
@b3brodie b3brodie marked this pull request as ready for review September 25, 2024 02:28
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 27, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 27, 2024
@github-actions github-actions bot removed the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 29, 2024
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Sep 30, 2024
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 <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style EOC: Effects On Condition Anything concerning Effects On Condition [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Map / Mapgen Overmap, Mapgen, Map extras, Map display Mods: Aftershock Anything to do with the Aftershock mod Mods: Bombastic Perks Mods: Defense Mode Anything to do with the Defense Mode mod Mods: Magiclysm Anything to do with the Magiclysm mod Mods: Mind Over Matter Mods: Xedra Evolved Anything to do with Xedra Evolved Mods Issues related to mods or modding Monsters Monsters both friendly and unfriendly. NPC / Factions NPCs, AI, Speech, Factions, Ownership Scenarios New Scenarios, balancing, bugs with scenarios Spawn Creatures, items, vehicles, locations appearing on map
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mod compatibility stuff
2 participants