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 API registration for mods that want to use game's built-in saving and loading of data stored in the save game files #270

Merged
merged 3 commits into from
Nov 7, 2023

Conversation

Falki-git
Copy link
Contributor

This adds 3 API methods for mods to:

  • Register their mods for save/load events
  • Unregister
  • Reregister

Usage is:

SpaceWarp.API.SaveGameManager.ModSaves.RegisterSaveLoadGameData(
            "my.mod.guid",
            MySaveDataObject,
            (savedData) =>
            {
                // This function will be called when a SAVE event is triggered.
                // If you don't need to do anything on save events, pass null instead of this function.
            },
            (loadedData) =>
            {
                // This function will be called when a LOAD event is triggered and BEFORE data is loaded to your saveData object.
                // You don't need to manually update your data. It will be updated after this function.
                // If you don't need to do anything on load events, pass null instead of this function.
            }
        );

MySaveDataObject can be any kind of object.

I'll keep this as a draft for a while to get comments and so I could test it in real scenarios more thoroughly.

… and loading of data stored in the save game files
@cheese3660
Copy link
Member

Would it be possible to change the API to instead be a generic T RegisterSaveLoadGameData<T>(string key, Action<...> onSave, Action<...> onLoad, T defaultValue = null) where it returns a default constructed object (Via Activator.CreateInstance(typeof(T))), or the default value if one was passed, that represents the saved data

@Falki-git
Copy link
Contributor Author

Like so?

@Falki-git Falki-git marked this pull request as ready for review November 6, 2023 20:47
@cheese3660
Copy link
Member

Yep, exactly like so

@cheese3660 cheese3660 merged commit ea55371 into SpaceWarpDev:dev Nov 7, 2023
@Falki-git Falki-git deleted the plugin-data-in-save-files branch December 20, 2023 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants