44using System . Linq ;
55using DataTool . DataModels . Hero ;
66using TankLib ;
7- using TankLib . STU . Types ;
87
98namespace DataTool . Helper ;
109
1110public static class Helpers {
11+ private static Dictionary < teResourceGUID , HeroVM > ? _heroesCache ;
12+ private static Dictionary < teResourceGUID , LoadoutVM > ? _loadoutsCache ;
13+
1214 /// <summary>
13- /// Returns dictionary of all Heroes by GUID using the <see cref="Hero "/> data model.
15+ /// Returns dictionary of all Heroes by GUID using the <see cref="HeroVM "/> data model.
1416 /// </summary>
1517 public static Dictionary < teResourceGUID , Hero > GetHeroes ( ) {
18+ if ( _heroesCache != null ) {
19+ return _heroesCache ;
20+ }
21+
1622 var @return = new Dictionary < teResourceGUID , Hero > ( ) ;
1723 foreach ( teResourceGUID key in Program . TrackedFiles [ 0x75 ] ) {
18- var hero = STUHelper . GetInstance < STUHero > ( key ) ;
24+ var hero = HeroVM . Load ( key ) ;
1925 if ( hero == null ) continue ;
20- @return [ key ] = new Hero ( hero , key ) ;
26+ @return [ key ] = hero ;
2127 }
2228
29+ _heroesCache = @return ;
2330 return @return ;
2431 }
2532
33+ /// <summary>
34+ /// Returns dictionary of all Loadouts by GUID using the <see cref="LoadoutVM"/> data model.
35+ /// </summary>
36+ public static Dictionary < teResourceGUID , Loadout > GetLoadouts ( ) {
37+ if ( _loadoutsCache != null ) {
38+ return _loadoutsCache ;
39+ }
40+
41+ var @return = new Dictionary < teResourceGUID , Loadout > ( ) ;
42+ foreach ( teResourceGUID key in Program . TrackedFiles [ 0x9E ] ) {
43+ var loadout = LoadoutVM . Load ( key ) ;
44+ if ( loadout == null ) continue ;
45+ @return [ key ] = loadout ;
46+ }
47+
48+ _loadoutsCache = @return ;
49+ return @return ;
50+ }
51+
52+ /// <summary>Returns a Loadout by its GUID</summary>
53+ public static LoadoutVM ? GetLoadoutById ( ulong guid ) {
54+ var loadouts = GetLoadouts ( ) ;
55+ return loadouts . GetValueOrDefault ( ( teResourceGUID ) guid ) ;
56+ }
57+
58+ /// <summary>Returns a Hero by its GUID</summary>
59+ public static HeroVM ? GetHeroById ( ulong guid ) {
60+ var heroes = GetHeroes ( ) ;
61+ return heroes . GetValueOrDefault ( ( teResourceGUID ) guid ) ;
62+ }
63+
2664 /// <summary>
2765 /// Returns a mapping of hero names to their GUIDs in lowercase.
2866 /// </summary>
@@ -42,7 +80,7 @@ public static IgnoreCaseDict<string> GetHeroNameLocaleOverrides(Dictionary<teRes
4280 if ( ! namesForThisLocale . TryGetValue ( localizedName . Value , out var nameForThisLocale ) ) {
4381 continue ;
4482 }
45-
83+
4684 if ( localizedName . Key . Equals ( nameForThisLocale , StringComparison . OrdinalIgnoreCase ) ) {
4785 // identical, don't bother mapping
4886 continue ;
0 commit comments