Skip to content

Commit

Permalink
Fix #16: support changing mainmenu profile from in-game
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Jul 15, 2024
1 parent 86616eb commit f4dbd2f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/TexturesUnlimitedFXLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class TexturesUnlimitedFXLoader : MonoBehaviour

public class Configuration
{
public const string NODE_NAME = "TUFX_CONFIGURATION";

[Persistent] public string MainMenuProfile = "Default-MainMenu";
[Persistent] public string SpaceCenterSceneProfile = "Default-KSC";
[Persistent] public string EditorSceneProfile = "Default-Editor";
Expand All @@ -48,6 +50,7 @@ public class Configuration
[Persistent] public bool ShowToolbarButton = true;
}

internal static UrlDir.UrlConfig defaultConfigUrl = null;
internal static readonly Configuration defaultConfiguration = new Configuration();

private PostProcessVolume mainVolume;
Expand Down Expand Up @@ -357,10 +360,10 @@ private void loadProfiles()
" a duplicate name; please check your configurations and remove any duplicates. Only the first configuration parsed for any one name will be loaded.");
}
}
ConfigNode config = GameDatabase.Instance.GetConfigNodes("TUFX_CONFIGURATION").FirstOrDefault(m => m.GetValue("name") == "Default");
if (config != null)
defaultConfigUrl = GameDatabase.Instance.GetConfigs(Configuration.NODE_NAME).FirstOrDefault();
if (defaultConfigUrl != null)
{
ConfigNode.LoadObjectFromConfig(defaultConfiguration, config);
ConfigNode.LoadObjectFromConfig(defaultConfiguration, defaultConfigUrl.config);
}
}

Expand Down Expand Up @@ -438,7 +441,13 @@ internal void setProfileForScene(string profile, GameScenes scene, bool enableNo
switch (scene)
{
case GameScenes.MAINMENU:
Log.error("The main menu profile must be set via config!");
defaultConfiguration.MainMenuProfile = profile;
if (defaultConfigUrl != null)
{
defaultConfigUrl.config = new ConfigNode(Configuration.NODE_NAME);
ConfigNode.WriteObject(defaultConfiguration, defaultConfigUrl.config, 0);
defaultConfigUrl.parent.SaveConfigs();
}
break;
case GameScenes.SPACECENTER:
HighLogic.CurrentGame.Parameters.CustomParams<TUFXGameSettings>().SpaceCenterSceneProfile = profile;
Expand Down

0 comments on commit f4dbd2f

Please sign in to comment.