Made newly revealed facts stored in NewHorizonsData

This commit is contained in:
Ben C 2022-03-27 15:11:42 -04:00
parent 8199e3f491
commit f0ac3a0573
5 changed files with 95 additions and 15 deletions

View File

@ -305,15 +305,15 @@ namespace NewHorizons.Builder.ShipLog
public List<MapModeObject> children;
public MapModeObject parent;
public MapModeObject lastSibling;
public void Increment_width()
public void IncrementWidth()
{
branch_width++;
parent?.Increment_width();
parent?.IncrementWidth();
}
public void Increment_height()
public void IncrementHeight()
{
branch_height++;
parent?.Increment_height();
parent?.IncrementHeight();
}
}
@ -416,12 +416,12 @@ namespace NewHorizons.Builder.ShipLog
if (even)
{
newY += newNode.branch_height;
parent.Increment_height();
parent.IncrementHeight();
}
else
{
newX += newNode.branch_width;
parent.Increment_width();
parent.IncrementWidth();
}
lastSibling = newNode;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewHorizons.Handlers;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.External
@ -59,12 +60,14 @@ namespace NewHorizons.External
{
Load();
}
Logger.Log($"Reseting save data for {_activeProfileName}");
Logger.Log($"Resetting save data for {_activeProfileName}");
_activeProfile = new NewHorizonsProfile();
_saveFile.Profiles[_activeProfileName] = _activeProfile;
Save();
}
# region Frequencies
public static bool KnowsFrequency(string frequency)
{
@ -81,7 +84,16 @@ namespace NewHorizons.External
Save();
}
}
public static bool KnowsMultipleFrequencies()
{
return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0);
}
# endregion
# region Signals
public static bool KnowsSignal(string signal)
{
if (_activeProfile == null) return true;
@ -97,12 +109,30 @@ namespace NewHorizons.External
Save();
}
}
# endregion
# region Newly Revealed Facts
public static bool KnowsMultipleFrequencies()
public static void AddNewlyRevealedFactID(string id)
{
return (_activeProfile != null && _activeProfile.KnownFrequencies.Count > 0);
_activeProfile?.NewlyRevealedFactIDs.Add(id);
Save();
}
public static List<string> GetNewlyRevealedFactIDs()
{
return _activeProfile?.NewlyRevealedFactIDs;
}
public static void ClearNewlyRevealedFactIDs()
{
_activeProfile?.NewlyRevealedFactIDs.Clear();
Save();
}
# endregion
private class NewHorizonsSaveFile
{
public NewHorizonsSaveFile()
@ -119,10 +149,13 @@ namespace NewHorizons.External
{
KnownFrequencies = new List<string>();
KnownSignals = new List<string>();
NewlyRevealedFactIDs = new List<string>();
}
public List<string> KnownFrequencies { get; set; }
public List<string> KnownSignals { get; set; }
public List<string> NewlyRevealedFactIDs { get; set; }
}
}
}

View File

@ -23,8 +23,9 @@ namespace NewHorizons.Handlers
// NewHorizonsBody -> AstroID
private static Dictionary<NewHorizonsBody, string> _nhBodyToAstroIDs;
private static string[] vanillaBodies;
private static string[] vanillaIDs;
private static string[] _vanillaBodies;
private static string[] _vanillaBodyIDs;
private static string[] _moddedFactsIDs;
public static void Init()
{
@ -33,13 +34,19 @@ namespace NewHorizons.Handlers
_nhBodyToAstroIDs = new Dictionary<NewHorizonsBody, string>();
List<GameObject> gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH));
vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray();
vanillaIDs = gameObjects.ConvertAll(g => g.GetComponent<ShipLogAstroObject>()?.GetID()).ToArray();
_vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray();
_vanillaBodyIDs = gameObjects.ConvertAll(g => g.GetComponent<ShipLogAstroObject>()?.GetID()).ToArray();
}
public static void CheckForModdedFacts(ShipLogManager manager)
{
List<ShipLogFact> moddedFacts = manager._factList.Where(e => manager._entryDataDict.ContainsKey(e._entryID) == false).ToList();
_moddedFactsIDs = moddedFacts.ConvertAll(e => e.GetID()).ToArray();
}
public static bool IsVanillaAstroID(string astroId)
{
return vanillaIDs.Contains(astroId);
return _vanillaBodyIDs.Contains(astroId);
}
public static bool IsVanillaBody(NewHorizonsBody body)
@ -48,7 +55,7 @@ namespace NewHorizons.Handlers
if (existingBody != null && existingBody.GetAstroObjectName() != AstroObject.Name.CustomString)
return true;
return vanillaBodies.Contains(body.Config.Name.Replace(" ", ""));
return _vanillaBodies.Contains(body.Config.Name.Replace(" ", ""));
}
public static string GetNameFromAstroID(string astroID)
@ -66,6 +73,11 @@ namespace NewHorizons.Handlers
}
}
public static bool IsModdedFact(string FactID)
{
return _moddedFactsIDs.Contains(FactID);
}
public static void AddConfig(string astroID, List<string> entryIDs, NewHorizonsBody body)
{
// Nice to be able to just get the AstroID from the body

View File

@ -55,6 +55,14 @@ namespace NewHorizons.Tools
var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame");
Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame));
var playerDataAddNewlyRevealedFactID = typeof(PlayerData).GetMethod("AddNewlyRevealedFactID");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataAddNewlyRevealedFactID, typeof(Patches), nameof(Patches.OnPlayerDataAddNewlyRevealedFactID));
var playerDataGetNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("GetNewlyRevealedFactIDs");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataGetNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataGetNewlyRevealedFactIDs));
var playerDataClearNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("ClearNewlyRevealedFactIDs");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataClearNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataClearNewlyRevealedFactIDs));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<BlackHoleVolume>("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<WhiteHoleVolume>("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ProbeLauncher>("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues));
@ -310,6 +318,32 @@ namespace NewHorizons.Tools
}
return true;
}
public static bool OnPlayerDataAddNewlyRevealedFactID(string __0)
{
if (ShipLogHandler.IsModdedFact(__0))
{
NewHorizonsData.AddNewlyRevealedFactID(__0);
return false;
}
else
{
return true;
}
}
public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List<string> __result)
{
__result = PlayerData._currentGameSave.newlyRevealedFactIDs.Concat(NewHorizonsData.GetNewlyRevealedFactIDs()).ToList();
return false;
}
public static bool OnPlayerDataClearNewlyRevealedFactIDs()
{
PlayerData._currentGameSave.newlyRevealedFactIDs.Clear();
NewHorizonsData.ClearNewlyRevealedFactIDs();
return false;
}
public static void OnPlayerDataResetGame()
{

View File

@ -66,6 +66,7 @@ namespace NewHorizons.Tools
public static void OnShipLogManagerAwakeComplete(ShipLogManager __instance)
{
ShipLogHandler.CheckForModdedFacts(__instance);
RumorModeBuilder.GenerateEntryData(__instance);
for (var i = 0; i < __instance._entryList.Count; i++)
{