Skip to content

Commit

Permalink
Add other method for getting everything
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 2, 2024
1 parent 5d0784a commit 3a2b8a9
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Winch/Core/AssetLoaderObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ private void OnGameStarted()
private void OnGameEnded()
{
WinchCore.Log.Debug("[AssetLoaderObject] OnGameEnded()");
PoiUtil.ClearHarvestablesAndHarvestParticlePrefabs();
PoiUtil.Clear();
HarvestZoneUtil.Clear();
CharacterUtil.ClearSpeakerData();
}

Expand Down
3 changes: 1 addition & 2 deletions Winch/Patches/API/PlayerPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public static void Postfix(Player __instance)
try
{
AbilityUtil.AddModdedAbilitiesToPlayer(__instance.transform.Find("Abilities"));
PoiUtil.PopulateHarvestablesAndHarvestParticlePrefabs();
PoiUtil.PopulateConversationPois();
PoiUtil.Populate();
PoiUtil.CreateModdedPois();
HarvestZoneUtil.CreateModdedHarvestZones();
ItemUtil.Encyclopedia();
Expand Down
5 changes: 5 additions & 0 deletions Winch/Util/CharacterUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ internal static void AddCharacterFromMeta(string metaPath)
WinchCore.Log.Error($"No character converter found");
}
}

public static SpeakerData[] GetAllSpeakerData()
{
return AllSpeakerDataDict.Values.ToArray();
}
}
4 changes: 4 additions & 0 deletions Winch/Util/GridConfigUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ internal static void AddGridConfigFromMeta(string metaPath)
}
}

public static GridConfiguration[] GetAllGridConfigs()
{
return AllGridConfigDict.Values.ToArray();
}
}
19 changes: 19 additions & 0 deletions Winch/Util/HarvestZoneUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ internal static bool PopulateHarvestZoneFromMetaWithConverter(CustomHarvestZone
}

internal static Dictionary<string, CustomHarvestZone> ModdedHarvestZoneDict = new();
internal static Dictionary<string, HarvestZone> CreatedModdedHarvestZoneDict = new();

internal static void Clear()
{
CreatedModdedHarvestZoneDict.Clear();
}

public static CustomHarvestZone GetModdedHarvestZone(string id)
{
Expand All @@ -31,6 +37,17 @@ public static CustomHarvestZone GetModdedHarvestZone(string id)
return null;
}

public static HarvestZone GetCreatedModdedHarvestZone(string id)
{
if (string.IsNullOrWhiteSpace(id))
return null;

if (CreatedModdedHarvestZoneDict.TryGetValue(id, out HarvestZone harvestZone))
return harvestZone;
else
return null;
}

internal static void CreateModdedHarvestZones()
{
foreach (var customHarvestZone in ModdedHarvestZoneDict.Values)
Expand Down Expand Up @@ -67,6 +84,8 @@ internal static GameObject CreateGameObjectFromCustomHarvestZone(CustomHarvestZo

harvestZoneObj.layer = Layer.HarvestZone;

CreatedModdedHarvestZoneDict.Add(customHarvestZone.id, harvestZone);

return harvestZoneObj;
}

Expand Down
40 changes: 28 additions & 12 deletions Winch/Util/PoiUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal static bool PopulateObjectFromMetaWithConverters<T>(T item, Dictionary<
}

internal static Dictionary<string, CustomPOI> ModdedPOIDict = new();
internal static Dictionary<string, POI> CreatedModdedPOIDict = new();
internal static Dictionary<string, IHarvestable> Harvestables = new();
internal static Dictionary<string, GameObject> HarvestParticlePrefabs = new();
internal static Dictionary<string, GameObject> ModdedHarvestParticlePrefabs = new();
Expand All @@ -53,8 +54,29 @@ public static CustomPOI GetModdedPOI(string id)
return null;
}

internal static void PopulateHarvestablesAndHarvestParticlePrefabs()
public static POI GetCreatedModdedPOI(string id)
{
if (string.IsNullOrWhiteSpace(id))
return null;

if (CreatedModdedPOIDict.TryGetValue(id, out POI poi))
return poi;
else
return null;
}

internal static GameObject InspectPoiContainer;
internal static GameObject InspectionGlint;
internal static VibrationData ExplodingWalls;
internal static NoiseSettings _6DShake;

internal static void Populate()
{
InspectPoiContainer = GameObject.FindObjectOfType<FinalePOIEnabler>().gameObject;
if (InspectionGlint == null) InspectionGlint = Resources.FindObjectsOfTypeAll<ParticleSystemRenderer>().FirstOrDefault(psr => psr.name == "InspectionGlint").gameObject.CopyPrefab();
if (ExplodingWalls == null) ExplodingWalls = Resources.FindObjectsOfTypeAll<VibrationData>().FirstOrDefault(vd => vd.name == "ExplodingWalls").DontDestroyOnLoad();
if (_6DShake == null) _6DShake = Resources.FindObjectsOfTypeAll<NoiseSettings>().FirstOrDefault(vd => vd.name == "6D Shake").DontDestroyOnLoad();

foreach (var harvestableParticle in Resources.FindObjectsOfTypeAll<HarvestableParticles>().Where(hp => !ModdedHarvestParticlePrefabs.Values.Contains(hp.gameObject)).Reverse())
{
var prefab = harvestableParticle.gameObject;
Expand Down Expand Up @@ -108,8 +130,9 @@ internal static void PopulateHarvestablesAndHarvestParticlePrefabs()
}
}

internal static void ClearHarvestablesAndHarvestParticlePrefabs()
internal static void Clear()
{
CreatedModdedPOIDict.Clear();
Harvestables.Clear();
HarvestParticlePrefabs.Clear();
}
Expand Down Expand Up @@ -383,6 +406,7 @@ internal static (GameObject, T) CreateGenericPoiFromCustomPoi<T>(CustomPOI custo
customPoiObject.transform.SetParent(parent);
customPoiObject.transform.position = customPoi.location;
var poi = customPoiObject.AddComponent<T>();
CreatedModdedPOIDict.Add(customPoi.id, poi);

poi.canBeGhostWindTarget = customPoi.canBeGhostWindTarget;

Expand Down Expand Up @@ -436,16 +460,8 @@ internal static void AddCustomPoiFromMeta<T>(string metaPath) where T : CustomPO
}
}

internal static GameObject InspectPoiContainer;
internal static GameObject InspectionGlint;
internal static VibrationData ExplodingWalls;
internal static NoiseSettings _6DShake;

internal static void PopulateConversationPois()
public static IHarvestable[] GetAllHarvestables()
{
InspectPoiContainer = GameObject.FindObjectOfType<FinalePOIEnabler>().gameObject;
if (InspectionGlint == null) InspectionGlint = Resources.FindObjectsOfTypeAll<ParticleSystemRenderer>().FirstOrDefault(psr => psr.name == "InspectionGlint").gameObject.CopyPrefab();
if (ExplodingWalls == null) ExplodingWalls = Resources.FindObjectsOfTypeAll<VibrationData>().FirstOrDefault(vd => vd.name == "ExplodingWalls").DontDestroyOnLoad();
if (_6DShake == null) _6DShake = Resources.FindObjectsOfTypeAll<NoiseSettings>().FirstOrDefault(vd => vd.name == "6D Shake").DontDestroyOnLoad();
return Harvestables.Values.ToArray();
}
}
5 changes: 5 additions & 0 deletions Winch/Util/WorldEventUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ internal static void ClearWorldEventData()
{
AllWorldEventDataDict.Clear();
}

public static WorldEventData[] GetAllWorldEventData()
{
return AllWorldEventDataDict.Values.ToArray();
}
}

0 comments on commit 3a2b8a9

Please sign in to comment.