Ejemplo n.º 1
0
        /// <summary>
        /// Tries to parse the <see cref="StatValueType"/> from a string.
        /// </summary>
        /// <param name="parser">The <see cref="Parser"/> to use.</param>
        /// <param name="value">The string to parse.</param>
        /// <param name="outValue">If this method returns true, contains the parsed <see cref="StatValueType"/>.</param>
        /// <returns>True if the parsing was successfully; otherwise false.</returns>
        public static bool TryParse(this Parser parser, string value, out StatValueType outValue)
        {
            short tmp;
            var   ret = parser.TryParse(value, out tmp);

            outValue = new StatValueType(tmp);
            return(ret);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatCollectionStatChangedEventArgs&lt;TStatType&gt;"/> class.
 /// </summary>
 /// <param name="statType">The stat that changed.</param>
 /// <param name="oldValue">The old value of the stat.</param>
 /// <param name="newValue">The new value of the stat.</param>
 public StatCollectionStatChangedEventArgs(TStatType statType, StatValueType oldValue, StatValueType newValue)
 {
     _statType = statType;
     _oldValue = oldValue;
     _newValue = newValue;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Writes a <see cref="StatValueType"/> to a <see cref="IValueWriter"/>.
 /// </summary>
 /// <param name="valueWriter"><see cref="IValueWriter"/> to write to.</param>
 /// <param name="name">Unique name of the <see cref="StatValueType"/> that will be used to distinguish it
 /// from other values when reading.</param>
 /// <param name="value"><see cref="StatValueType"/> to write.</param>
 public static void Write(this IValueWriter valueWriter, string name, StatValueType value)
 {
     value.Write(valueWriter, name);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Writes a <see cref="StatValueType"/> to a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to write to.</param>
 /// <param name="value"><see cref="StatValueType"/> to write.</param>
 public static void Write(this BitStream bitStream, StatValueType value)
 {
     value.Write(bitStream);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Reads the <see cref="StatValueType"/> from an IValueReader.
 /// </summary>
 /// <param name="valueReader"><see cref="IValueReader"/> to read the <see cref="StatValueType"/> from.</param>
 /// <param name="name">The unique name of the value to read.</param>
 /// <returns>The <see cref="StatValueType"/> read from the IValueReader.</returns>
 public static StatValueType ReadStatValueType(this IValueReader valueReader, string name)
 {
     return(StatValueType.Read(valueReader, name));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Reads the <see cref="StatValueType"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="StatValueType"/> from.</param>
 /// <param name="name">The name of the field to read the value from.</param>
 /// <returns>The <see cref="StatValueType"/> read from the <see cref="IDataRecord"/>.</returns>
 public static StatValueType GetStatValueType(this IDataRecord r, string name)
 {
     return(StatValueType.Read(r, name));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Reads the <see cref="StatValueType"/> from a <see cref="BitStream"/>.
 /// </summary>
 /// <param name="bitStream"><see cref="BitStream"/> to read the <see cref="StatValueType"/> from.</param>
 /// <returns>The <see cref="StatValueType"/> read from the <see cref="BitStream"/>.</returns>
 public static StatValueType ReadStatValueType(this BitStream bitStream)
 {
     return(StatValueType.Read(bitStream));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Reads the <see cref="StatValueType"/> from an <see cref="IDataRecord"/>.
 /// </summary>
 /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="StatValueType"/> from.</param>
 /// <param name="i">The field index to read.</param>
 /// <returns>The <see cref="StatValueType"/> read from the <see cref="IDataRecord"/>.</returns>
 public static StatValueType GetStatValueType(this IDataRecord r, int i)
 {
     return(StatValueType.Read(r, i));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as a
        /// <see cref="StatValueType"/>.
        /// </summary>
        /// <typeparam name="T">The key Type.</typeparam>
        /// <param name="dict">The <see cref="IDictionary{TKey, TValue}"/>.</param>
        /// <param name="key">The key for the value to get.</param>
        /// <param name="defaultValue">The value to use if the value at the <paramref name="key"/> could not be parsed.</param>
        /// <returns>The value at the given <paramref name="key"/> parsed as an int, or the
        /// <paramref name="defaultValue"/> if the <paramref name="key"/> did not exist in the <paramref name="dict"/>
        /// or the value at the given <paramref name="key"/> could not be parsed.</returns>
        public static StatValueType AsStatValueType <T>(this IDictionary <T, string> dict, T key, StatValueType defaultValue)
        {
            string value;

            if (!dict.TryGetValue(key, out value))
            {
                return(defaultValue);
            }

            StatValueType parsed;

            if (!Parser.Invariant.TryParse(value, out parsed))
            {
                return(defaultValue);
            }

            return(parsed);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Stat{TStatType}"/> struct.
 /// </summary>
 /// <param name="statType">Type of the stat.</param>
 /// <param name="value">The value.</param>
 public Stat(TStatType statType, StatValueType value)
 {
     _statType = statType;
     _value    = value;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// When overridden in the derived class, allows for handling when a stat's value has changed.
 /// </summary>
 /// <param name="statType">The type of the stat that changed.</param>
 /// <param name="oldValue">The old value of the stat.</param>
 /// <param name="newValue">The new value of the stat.</param>
 protected virtual void OnStatChanged(TStatType statType, StatValueType oldValue, StatValueType newValue)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Sets the value of all stats in this collection to the specified value.
 /// </summary>
 /// <param name="value">The value to set all stats to.</param>
 public void SetAll(StatValueType value)
 {
     _stats.SetAll(value);
 }