voxeltycoon-community / voxel-tycoon-open-library

Community-made open-source library of functions made for making mods for the game Voxel Tycoon
GNU Affero General Public License v3.0
3 stars 2 forks source link

Settings Mod Helper initial push #39

Open KyleRokuKyu opened 2 years ago

KyleRokuKyu commented 2 years ago

Added the SettingsModHelper. It's a script with 2 very useful SettingsMod tweaks. It was more functions but it's been optimized for uploading

First, public static void SetSetting<T, TSettingsMod>(string name, T value, WorldSettings worldSettings) where TSettingsMod : SettingsMod, new() This function sets and saves a setting of type T for the SettingsMod TSettingsMod. It saves via Unity PlayerPrefs. I'd prefer a different way but this works just fine for now. I will be making a function that runs after all mods have loaded which cleans out the player prefs of mods which are no longer installed.

Second, public static T GetSetting<T, TSettingsMod>(string name, T defaultValue) This function gets a setting of type T for the SettingsMod TSettingsMod It attempts to load it from the PlayerPrefs. If it fails to load or can't find a setting of the key name at all, it creates a PlayerPref with the key of the name parameter returns the defaultValue parameter.