Add default star system override option

This commit is contained in:
Nick 2022-05-13 16:30:37 -04:00
parent 87c859728e
commit d5ee5ff33a

View File

@ -35,9 +35,10 @@ namespace NewHorizons
public static Main Instance { get; private set; }
// Settings
public static bool Debug;
public static bool Debug { get; private set; }
private static bool _useCustomTitleScreen;
private static bool _wasConfigured = false;
private static string _defaultSystemOverride;
public static Dictionary<string, NewHorizonsSystem> SystemDict = new Dictionary<string, NewHorizonsSystem>();
public static Dictionary<string, List<NewHorizonsBody>> BodyDict = new Dictionary<string, List<NewHorizonsBody>>();
@ -84,6 +85,8 @@ namespace NewHorizons
DebugReload.UpdateReloadButton();
Logger.UpdateLogLevel(Debug ? Logger.LogType.Log : Logger.LogType.Error);
_defaultSystemOverride = config.GetSettingsValue<string>("Default System Override");
var wasUsingCustomTitleScreen = _useCustomTitleScreen;
_useCustomTitleScreen = config.GetSettingsValue<bool>("Custom title screen");
// Reload the title screen if this was updated on it
@ -111,11 +114,14 @@ namespace NewHorizons
destroyStockPlanets = false
}
};
foreach (AssetBundle bundle in AssetBundles.Values)
foreach (var pair in AssetBundles)
{
bundle.Unload(true);
if (pair.Value == null) Logger.LogError($"The asset bundle for {pair.Key} was null when trying to unload");
else pair.Value.Unload(true);
}
AssetBundles.Clear();
if (!resetTranslation) return;
TranslationHandler.ClearTables();
TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage());
@ -274,9 +280,18 @@ namespace NewHorizons
else
{
// Reset back to original solar system after going to main menu.
// If the override is a valid system then we go there
if (SystemDict.Keys.Contains(_defaultSystemOverride))
{
_currentStarSystem = _defaultSystemOverride;
IsWarping = true; // always do this else sometimes the spawn gets messed up
}
else
{
_currentStarSystem = _defaultStarSystem;
}
}
}
public void EnableWarpDrive()
{
@ -309,6 +324,12 @@ namespace NewHorizons
var relativePath = file.Replace(folder, "");
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>(relativePath);
if (starSystemConfig.startHere)
{
// We always want to allow mods to overwrite setting the main SolarSystem as default but not the other way around
if (name != "SolarSystem") SetDefaultSystem(name);
}
var system = new NewHorizonsSystem(name, starSystemConfig, mod);
SystemDict[name] = system;
}
@ -380,15 +401,13 @@ namespace NewHorizons
if (config.Base.CenterOfSolarSystem) config.Orbit.IsStatic = true;
if (!SystemDict.ContainsKey(config.StarSystem))
{
// See if theres a star system config
// Since we didn't load it earlier there shouldn't be a star system config
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>($"systems/{config.StarSystem}.json");
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(null);
else Logger.Log($"Loaded system config for {config.StarSystem}");
else Logger.LogWarning($"Loaded system config for {config.StarSystem}. Why wasn't this loaded earlier?");
var system = new NewHorizonsSystem(config.StarSystem, starSystemConfig, mod);
if (system.Config.startHere) SetDefaultSystem(system.Name);
SystemDict.Add(config.StarSystem, system);
BodyDict.Add(config.StarSystem, new List<NewHorizonsBody>());
@ -445,8 +464,18 @@ namespace NewHorizons
{
// We reset the solar system on death (unless we just killed the player)
if (!_isChangingStarSystem)
{
// If the override is a valid system then we go there
if (SystemDict.Keys.Contains(_defaultSystemOverride))
{
_currentStarSystem = _defaultSystemOverride;
IsWarping = true; // always do this else sometimes the spawn gets messed up
}
else
{
_currentStarSystem = _defaultStarSystem;
}
IsWarping = false;
}
}