Wycademy/src/Wycademy/Commands/Services/WeaponInfoService.cs
/// <summary>
/// Deserializes the weapon info for a game.
/// </summary>
/// <typeparam name="T">The implementation of <see cref="BaseWeaponInfo"/> to deserialize to.</typeparam>
/// <param name="gameString">The directory name of the game.</param>
/// <returns>A <see cref="Dictionary{TKey, TValue}"/> with the weapon's ID as the key and the weapon info as the value.</returns>
Deserializes the weapon info for a game.
Deserializes the weapon info for a game .
private Dictionary<int, T> LoadWeaponInfo<T>(string gameString) 
            where T : BaseWeaponInfo
        {
            var encoding = new UTF8Encoding(false);
            var deserialized = new List<List<T>>();
            foreach (string fileName in Directory.GetFiles(Path.Combine(WycademyConst.DATA_LOCATION, gameString, "weapon")))
            {
                string json = File.ReadAllText(fileName, encoding);
                deserialized.Add(JsonConvert.DeserializeObject<List<T>>(json));
            }
            return deserialized.SelectMany(x => x).ToDictionary(w => w.Id);
        }
private Dictionary < int , T > LoadWeaponInfo < T > ( string gameString ) where T : BaseWeaponInfo { var encoding = new UTF8Encoding ( false ) ; var deserialized = new List < List < T > > ( ) ; foreach ( string fileName in Directory . GetFiles ( Path . Combine ( WycademyConst . DATA_LOCATION , gameString , " " ) ) ) { string json = File . ReadAllText ( fileName , encoding ) ; deserialized . Add ( JsonConvert . DeserializeObject < List < T > > ( json ) ) ; } return deserialized . SelectMany ( x => x ) . ToDictionary ( w => w . Id ) ; }
Deserializes the weapon info for a game.
Deserializes the weapon info for a game .
// The encoding to use when reading from files. // Start by storing each weapon type as its own element in a list. // Flatten the list of lists then convert it to a dictionary with the ID as the key.
A  with the weapon's ID as the key and the weapon info as the value.
A with the weapon ' s ID as the key and the weapon info as the value .
gameString
string
The directory name of the game.
The directory name of the game .
typeparam
The implementation of  to deserialize to.
The implementation of to deserialize to .