/// <summary> /// Tries to parse the BodyID from a string. /// </summary> /// <param name="parser">The Parser to use.</param> /// <param name="value">The string to parse.</param> /// <param name="outValue">If this method returns true, contains the parsed BodyID.</param> /// <returns>True if the parsing was successfully; otherwise false.</returns> public static bool TryParse(this Parser parser, string value, out BodyID outValue) { ushort tmp; var ret = parser.TryParse(value, out tmp); outValue = new BodyID(tmp); return(ret); }
/// <summary> /// Gets the <see cref="BodyInfo"/> at the given <paramref name="index"/>. /// </summary> /// <param name="index">The index of the body to get.</param> /// <returns>The <see cref="BodyInfo"/> at the given <paramref name="index"/>, or null if the /// <paramref name="index"/> was invalid or no body exists for the given value.</returns> public BodyInfo GetBody(BodyID index) { BodyInfo ret; if (_bodies.TryGetValue(index, out ret)) { return(ret); } return(null); }
/// <summary> /// Gets the next free <see cref="BodyID"/>. /// </summary> /// <returns>The next free <see cref="BodyID"/>.</returns> BodyID GetNextFreeID() { var i = new BodyID(1); while (_bodies.ContainsKey(i)) { i++; } return(i); }
/// <summary> /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as type BodyID. /// </summary> /// <typeparam name="T">The key Type.</typeparam> /// <param name="dict">The IDictionary.</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 BodyID AsBodyID <T>(this IDictionary <T, string> dict, T key, BodyID defaultValue) { string value; if (!dict.TryGetValue(key, out value)) { return(defaultValue); } BodyID parsed; if (!Parser.Invariant.TryParse(value, out parsed)) { return(defaultValue); } return(parsed); }
/// <summary> /// Deletes a <see cref="BodyInfo"/> in this <see cref="BodyInfoManager"/>. /// </summary> /// <param name="id">The <see cref="BodyID"/> of the body to remove.</param> /// <returns>True if a <see cref="BodyInfo"/> was removed from the given <paramref name="id"/>; otherwise false.</returns> /// <remarks> /// Should only be used in the editor. /// </remarks> public bool RemoveBody(BodyID id) { return(_bodies.Remove(id)); }
/// <summary> /// Initializes a new instance of the <see cref="BodyInfo"/> class. /// </summary> /// <param name="id">The <see cref="BodyID"/>.</param> public BodyInfo(BodyID id) { ID = id; }
/// <summary> /// Writes a BodyID to a IValueWriter. /// </summary> /// <param name="valueWriter">IValueWriter to write to.</param> /// <param name="name">Unique name of the BodyID that will be used to distinguish it /// from other values when reading.</param> /// <param name="value">BodyID to write.</param> public static void Write(this IValueWriter valueWriter, string name, BodyID value) { value.Write(valueWriter, name); }
/// <summary> /// Writes a BodyID to a BitStream. /// </summary> /// <param name="bitStream">BitStream to write to.</param> /// <param name="value">BodyID to write.</param> public static void Write(this BitStream bitStream, BodyID value) { value.Write(bitStream); }
/// <summary> /// Reads the BodyID from an IValueReader. /// </summary> /// <param name="valueReader">IValueReader to read the BodyID from.</param> /// <param name="name">The unique name of the value to read.</param> /// <returns>The BodyID read from the IValueReader.</returns> public static BodyID ReadBodyID(this IValueReader valueReader, string name) { return(BodyID.Read(valueReader, name)); }
/// <summary> /// Reads the BodyID from a BitStream. /// </summary> /// <param name="bitStream">BitStream to read the BodyID from.</param> /// <returns>The BodyID read from the BitStream.</returns> public static BodyID ReadBodyID(this BitStream bitStream) { return(BodyID.Read(bitStream)); }
/// <summary> /// Reads the BodyID from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the BodyID from.</param> /// <param name="name">The name of the field to read the value from.</param> /// <returns>The BodyID read from the <see cref="IDataRecord"/>.</returns> public static BodyID GetBodyID(this IDataRecord r, string name) { return(BodyID.Read(r, name)); }
/// <summary> /// Reads the BodyID from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the BodyID from.</param> /// <param name="i">The field index to read.</param> /// <returns>The BodyID read from the <see cref="IDataRecord"/>.</returns> public static BodyID GetBodyID(this IDataRecord r, int i) { return(BodyID.Read(r, i)); }
/// <summary> /// Initializes a new instance of the <see cref="AccountCharacterInfo"/> class. /// </summary> /// <param name="index">The index.</param> /// <param name="name">The name.</param> /// <param name="bodyID">The ID of the body.</param> public AccountCharacterInfo(byte index, string name, BodyID bodyID) { Index = index; Name = name; BodyID = bodyID; }