Optionally disable map per system (#123)

Closes #123
This commit is contained in:
Nick 2022-05-19 17:34:11 -04:00
parent ef24245c60
commit 7c396602f7
4 changed files with 32 additions and 16 deletions

View File

@ -7,6 +7,7 @@
public bool destroyStockPlanets = true;
public string factRequiredForWarp;
public bool enableTimeLoop = true;
public bool mapRestricted;
public NomaiCoordinates coords;
public SkyboxConfig skybox;

View File

@ -228,8 +228,6 @@ namespace NewHorizons
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);
LoadTranslations(ModHelper.Manifest.ModFolderPath + "AssetBundle/", this);
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
// Warp drive
StarChartHandler.Init(SystemDict.Values.ToArray());
HasWarpDrive = StarChartHandler.CanWarp();
@ -237,20 +235,9 @@ namespace NewHorizons
_shipWarpController.Init();
if (HasWarpDrive == true) EnableWarpDrive();
if (IsWarping && _shipWarpController)
{
Instance.ModHelper.Events.Unity.RunWhen(
() => IsSystemReady,
() => _shipWarpController.WarpIn(WearingSuit)
);
}
else
{
Instance.ModHelper.Events.Unity.RunWhen(
() => IsSystemReady,
() => FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint)
);
}
var shouldWarpIn = IsWarping && _shipWarpController != null;
Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpIn));
IsWarping = false;
var map = GameObject.FindObjectOfType<MapController>();
@ -275,6 +262,15 @@ namespace NewHorizons
}
}
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
private void OnSystemReady(bool shouldWarpIn)
{
Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
if (shouldWarpIn) _shipWarpController.WarpIn(WearingSuit);
else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint);
}
public void EnableWarpDrive()
{
Logger.Log("Setting up warp drive");

View File

@ -21,5 +21,19 @@ namespace NewHorizons.Patches
{
__instance._isLockedOntoMapSatellite = true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MapController), nameof(MapController.MapInoperable))]
public static bool MapController_MapInoperable(MapController __instance, ref bool __result)
{
if(Main.SystemDict[Main.Instance.CurrentStarSystem]?.Config?.mapRestricted ?? false)
{
__instance._playerMapRestricted = true;
__result = true;
return false;
}
return true;
}
}
}

View File

@ -25,6 +25,11 @@
"description": "Should the player be sent back in time after 22 minutes?",
"default": true
},
"mapRestricted": {
"type": "bool",
"description": "Should the player be unable to use their map in this system?",
"default": false
},
"skybox": {
"type": "object",
"description": "Options for the skybox of your system",