-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityOverrideCache.cs
More file actions
70 lines (55 loc) · 1.9 KB
/
EntityOverrideCache.cs
File metadata and controls
70 lines (55 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
namespace CalTestHelpers
{
public class EntityOverrideCache
{
internal static List<Projectile> LoadedProjectiles = new();
internal static List<string> ProjectileNames = new();
public static int[] StaticIFrameOverrides;
public static int[] LocalIFrameOverrides;
internal static void Load()
{
LoadedProjectiles = new List<Projectile>();
ProjectileNames = new List<string>();
StaticIFrameOverrides = new int[ProjectileLoader.ProjectileCount];
LocalIFrameOverrides = new int[ProjectileLoader.ProjectileCount];
for (int i = 0; i < ProjectileLoader.ProjectileCount; i++)
{
Projectile projectile = new();
projectile.SetDefaults(i);
LoadedProjectiles.Add(projectile);
string projectileName = projectile.Name.ToLower();
projectileName = string.Concat(projectileName.Where(c => !char.IsWhiteSpace(c)));
ProjectileNames.Add(projectileName);
StaticIFrameOverrides[i] = LocalIFrameOverrides[i] = -2;
}
}
internal static void Unload()
{
LoadedProjectiles = null;
ProjectileNames = null;
StaticIFrameOverrides = null;
LocalIFrameOverrides = null;
}
public static void ResetOverrides()
{
for (int i = 0; i < StaticIFrameOverrides.Length; i++)
StaticIFrameOverrides[i] = LocalIFrameOverrides[i] = -2;
}
public static IEnumerable<int> AttemptToLocateProjectilesWithSimilarName(string name)
{
if (string.IsNullOrEmpty(name))
yield break;
name = name.ToLower();
// Remove whitespace from the name.
name = string.Concat(name.Where(c => !char.IsWhiteSpace(c)));
IEnumerable<string> similarProjectileNames = ProjectileNames.Where(n => n.Contains(name)).Take(CalTestHelperConfig.Instance.StuffAmountDisplay);
foreach (string itemName in similarProjectileNames)
yield return ProjectileNames.IndexOf(itemName);
}
}
}