コード例 #1
0
        /// <summary>
        /// Converts a Weapons Json object to a Weapons Object that can be used ingame
        /// </summary>
        /// <param name="weaponsJS">JSON Object containing weapons data</param>
        /// <returns>Weapons object for further use</returns>
        private Dictionary <string, Weapon> convertToWeapons(WeaponsJS weaponsJS)
        {
            Dictionary <string, Weapon> weapons = new Dictionary <string, Weapon>();

            foreach (KeyValuePair <string, SingleWeaponJS> weaponIdPair in weaponsJS.WeaponsIDValuePairs)
            {
                weapons.Add(weaponIdPair.Key, new Weapon(weaponIdPair.Value));
            }

            return(weapons);
        }
コード例 #2
0
        /// <summary>
        /// Reads the WeaponsJS.json and converts it to a JSON Object
        /// </summary>
        /// <returns></returns>
        private WeaponsJS loadWeaponsJS()
        {
            WeaponsJS weaponsJS = new WeaponsJS();

            try
            {
                weaponsJS.WeaponsIDValuePairs = JsonConvert.DeserializeObject <Dictionary <string, SingleWeaponJS> >(File.ReadAllText(WeaponsJS.WeaponsJSPath));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error while parsing: " + WeaponsJS.WeaponsJSPath);
                System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
            }
            return(weaponsJS);
        }
コード例 #3
0
        /// <summary>
        /// Default constructor for the Weapons factory
        /// </summary>
        public WeaponsFactory()
        {
            WeaponsJS weaponsJS = loadWeaponsJS();

            Weapons = convertToWeapons(weaponsJS);
        }