Skip to content

Commit

Permalink
Use resources for harvest particles
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Aug 31, 2024
1 parent 467a7c3 commit 1d8934d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
27 changes: 21 additions & 6 deletions Winch/Util/PoiUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,30 @@ public static CustomPOI GetModdedPOI(string id)

internal static void PopulateHarvestablesAndHarvestParticlePrefabs()
{
foreach (var harvestableParticle in Resources.FindObjectsOfTypeAll<HarvestableParticles>().Reverse())
{
var prefab = harvestableParticle.gameObject;
var name = prefab.name.RemoveClone();
if (!HarvestParticlePrefabs.ContainsKey(name))
{
prefab.name = name;
HarvestParticlePrefabs.Add(name, prefab);
WinchCore.Log.Debug($"Added particle {name} to HarvestParticlePrefabs");
}
}
foreach (var harvestPoi in GameManager.Instance.HarvestPOIManager.allHarvestPOIs)
{
try
{
if (!Harvestables.ContainsKey(harvestPoi.Harvestable.GetId()))
Harvestables.Add(harvestPoi.Harvestable.GetId(), harvestPoi.Harvestable);
var prefab = harvestPoi.Harvestable.GetParticlePrefab();
if (!HarvestParticlePrefabs.ContainsKey(prefab.name))
var name = prefab.name.RemoveClone();
if (!HarvestParticlePrefabs.ContainsKey(name))
{
HarvestParticlePrefabs.Add(prefab.name, prefab);
WinchCore.Log.Debug($"Added particle {prefab.name} to HarvestParticlePrefabs");
prefab.name = name;
HarvestParticlePrefabs.Add(name, prefab);
WinchCore.Log.Debug($"Added particle {name} to HarvestParticlePrefabs");
}
}
catch (Exception ex)
Expand All @@ -85,10 +98,12 @@ internal static void PopulateHarvestablesAndHarvestParticlePrefabs()
if (!Harvestables.ContainsKey(itemPoi.Harvestable.GetId()))
Harvestables.Add(itemPoi.Harvestable.GetId(), itemPoi.Harvestable);
var prefab = itemPoi.Harvestable.GetParticlePrefab();
if (!HarvestParticlePrefabs.ContainsKey(prefab.name))
var name = prefab.name.RemoveClone();
if (!HarvestParticlePrefabs.ContainsKey(name))
{
HarvestParticlePrefabs.Add(prefab.name, prefab);
WinchCore.Log.Debug($"Added particle {prefab.name} to HarvestParticlePrefabs");
prefab.name = name;
HarvestParticlePrefabs.Add(name, prefab);
WinchCore.Log.Debug($"Added particle {name} to HarvestParticlePrefabs");
}
}
catch (Exception ex)
Expand Down
31 changes: 28 additions & 3 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,10 @@ where baseType.IsAssignableFrom(type)
/// </summary>
public static string? NullIfEmpty(this string s) => string.IsNullOrWhiteSpace(s) ? null : s;

/// <inheritdoc cref="Regex.Replace(string,string,string)" />
public static string RegexReplace(this string input, string pattern, string replacement) =>
Regex.Replace(input, pattern, replacement);
/// <inheritdoc cref="Regex.Replace(string,string,string,RegexOptions)" />
public static string RegexReplace(this string input, string pattern, string replacement,
RegexOptions options = RegexOptions.Multiline | RegexOptions.CultureInvariant) =>
Regex.Replace(input, pattern, replacement, options);

public static bool TryMatch(this Regex regex, string input, out Match? match)
{
Expand All @@ -803,6 +804,22 @@ public static bool TryMatch(this Regex regex, string input, out Match? match)
}
}

/// <summary>
/// Gets the index of a string inside this string using Invariant Culture
/// </summary>
/// <param name="source">The string to get the index from</param>
/// <param name="value">The string to find the index of</param>
/// <returns>The index if found, -1 if not</returns>
public static int IndexOfInvariant(this string source, string value) => CultureInfo.InvariantCulture.CompareInfo.IndexOf(source, value);

/// <summary>
/// Gets the last index of a string inside this string using Invariant Culture
/// </summary>
/// <param name="source">The string to get the last index from</param>
/// <param name="value">The string to find the last index of</param>
/// <returns>The index if found, -1 if not</returns>
public static int LastIndexOfInvariant(this string source, string value) => CultureInfo.InvariantCulture.CompareInfo.LastIndexOf(source, value);

public static string FixBackslashes(this string s) => s.Replace("\\\\", "/").Replace("\\", "/");
#endregion

Expand Down Expand Up @@ -1139,6 +1156,8 @@ public static void QuickRemoveAt<T>(this IList<T> list, int index)
#endregion

#region Unity
public static string RemoveClone(this string str) => str.Replace("(Clone)", "").Trim();

internal static Transform? prefabParent;
internal static Transform PrefabParent
{
Expand Down Expand Up @@ -1498,6 +1517,12 @@ public static StringTableEntry GetEntry(
return null;
}

public static float[] ToArray(this Vector2 value) => new float[2] { value.x, value.y };
public static float[] ToArray(this Vector3 value) => new float[3] { value.x, value.y, value.z };
public static float[] ToArray(this Vector4 value) => new float[4] { value.x, value.y, value.z, value.w };

public static Vector3 Abs(this Vector3 value) => new Vector3(Mathf.Abs(value.x), Mathf.Abs(value.y), Mathf.Abs(value.z));

#region Coroutines
public static void FireOnNextUpdate(this MonoBehaviour component, Action action) =>
component.FireInNUpdates(action, 1);
Expand Down

0 comments on commit 1d8934d

Please sign in to comment.