/*/// <summary> * /// Gets the category at the specified index in the category. * /// </summary> * /// <param name="index">The index of the category to get.</param> * /// <returns>The category at the specified index.</returns> * ISpriteCategory ISpriteCategoryContainer.this[int index] => (ISpriteCategory) this[index]; * * /// <summary> * /// Gets the category with the specified Id in the category. * /// </summary> * /// <param name="id">The Id of the category to get.</param> * /// <returns>The category with the specified Id.</returns> * /// * /// <exception cref="KeyNotFoundException"> * /// The element with the <paramref name="id"/> was not found. * /// </exception> * ISpriteCategory ISpriteCategoryContainer.Get(object id) => (ISpriteCategory) Get(id); * /// <summary> * /// Gets if the category contains a category with the specified Id. * /// </summary> * /// <param name="id">The Id to check for a category with.</param> * /// <returns>True if a category exists with the specified Id, otherwise null.</returns> * bool ISpriteCategoryContainer.ContainsKey(object id) => ContainsKey(id);*/ #endregion #region Part List Accessors /*/// <summary> * /// Gets the part list at the specified index in the category. * /// </summary> * /// <param name="index">The index of the part list to get.</param> * /// <returns>The part list at the specified index.</returns> * ISpritePartList ISpritePartListContainer.this[int index] => (ISpritePartList) this[index]; * * /// <summary> * /// Gets the part list with the specified Id in the category. * /// </summary> * /// <param name="id">The Id of the part list to get.</param> * /// <returns>The part list with the specified Id.</returns> * /// * /// <exception cref="KeyNotFoundException"> * /// The element with the <paramref name="id"/> was not found. * /// </exception> * ISpritePartList ISpritePartListContainer.Get(int id) => (ISpritePartList) Get(id); * /// <summary> * /// Gets if the category contains a part list with the specified Id. * /// </summary> * /// <param name="id">The Id to check for an part list with.</param> * /// <returns>True if a part list exists with the specified Id, otherwise null.</returns> * bool ISpritePartListContainer.ContainsKey(int id) => ContainsKey(id);*/ #endregion #region Part Accessors /*/// <summary> * /// Tries to get the part types that exist for this sprite selection for the specified sprite part group. * /// </summary> * /// <param name="group">The sprite part group whose sprite parts are being acquired.</param> * /// <param name="partId">The Id of the parts being used for the group.</param> * /// <param name="parts">The output sprite parts. This value should be ignored when false is returned.</param> * /// <returns>True if any parts were found for this group's part Id.</returns> * /// * /// <exception cref="ArgumentNullException"> * /// <paramref name="group"/> is null. * /// </exception> * public bool TryGetPartTypes(CharacterSpritePartGroupInfo group, int partId, out ISpritePart[] parts) { * if (group == null) * throw new ArgumentNullException(nameof(group)); * IReadOnlyList<int> typeIds = group.TypeIds; * parts = new ISpritePart[typeIds.Count]; * bool found = false; * for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) { * int typeId = typeIds[groupIndex]; * if (TryGetValue(typeId, out var partTypesElement)) { * SpritePartList partTypes = (SpritePartList) partTypesElement; * if (partTypes.TryGetValue(partId, out parts[groupIndex])) * found = true; // Not a situation where we break after found, fill in the parts array. * } * } * return found; * } * /// <summary> * /// Tries to get the first part types that exist for this sprite selection for the specified part group. * /// </summary> * /// <param name="group">The sprite part group whose sprite parts are being acquired.</param> * /// <param name="partId">The output Id for the parts to use for this group.</param> * /// <param name="parts">The output sprite parts. This value should be ignored when false is returned.</param> * /// <returns>True if this sprite selection has any parts for this sprite part group.</returns> * /// * /// <exception cref="ArgumentNullException"> * /// <paramref name="group"/> is null. * /// </exception> * public bool TryGetFirstPartTypes(CharacterSpritePartGroupInfo group, out int partId, out ISpritePart[] parts) { * if (group == null) * throw new ArgumentNullException(nameof(group)); * IReadOnlyList<int> typeIds = group.TypeIds; * parts = new ISpritePart[typeIds.Count]; * partId = int.MaxValue; * bool found = false; * for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) { * int typeId = typeIds[groupIndex]; * if (TryGetValue(typeId, out var partTypesElement)) { * SpritePartList partTypes = (SpritePartList) partTypesElement; * if (partTypes.List.Count != 0) { * parts[groupIndex] = partTypes.List.First(); * partId = Math.Min(parts[groupIndex].Id, partId); * found = true; * } * } * } * if (found) { * for (int groupIndex = 0; groupIndex < typeIds.Count; groupIndex++) { * if (parts[groupIndex] != null && parts[groupIndex].Id != partId) * parts[groupIndex] = null; * } * } * else { * partId = -1; * } * return found; * }*/ #endregion #region CreateGroups /// <summary> /// Creates sprite part groups used to categorize the sprite parts during selection. /// </summary> /// <param name="game">The game info associated with this sprite category.</param> /// <param name="character">The character info associated with this sprite category.</param> /// <returns>An array of sprite part groups for use in sprite part selection.</returns> /// /// <exception cref="ArgumentNullException"> /// <paramref name="game"/> or <paramref name="character"/> is null. /// </exception> public ISpritePartGroup[] CreateGroups(GameInfo game, CharacterInfo character) { CharacterSpritePartGroupInfo[] groupInfos = character.Database.GetPartGroups(game, character); ISpritePartGroup[] groups = new ISpritePartGroup[groupInfos.Length]; for (int i = 0; i < groups.Length; i++) { CharacterSpritePartGroupInfo groupInfo = groupInfos[i]; SpritePartGroup group = new SpritePartGroup { Info = groupInfo, Index = i, TypeIds = groupInfo.TypeIds.ToArray(), GroupParts = new List <SpritePartGroupPart> { SpritePartGroupPart.None }, }; // Add sprite part group parts that contain sprite parts for each Type Id. for (int typeIndex = 0; typeIndex < groupInfo.TypeIds.Count; typeIndex++) { int typeId = groupInfo.TypeIds[typeIndex]; SpritePartList partList = (SpritePartList)List.Find(e => e.Id.Equals(typeId)); if (partList != null) { foreach (ISpritePart part in partList.List) { SpritePartGroupPart groupPart = group.GroupParts.Find(gp => gp.Id == part.Id); if (groupPart == null) { groupPart = new SpritePartGroupPart { Id = part.Id, Parts = new SpritePart[groupInfo.TypeIds.Count], }; group.GroupParts.Add(groupPart); } groupPart.Parts[typeIndex] = (SpritePart)part; } } } group.GroupParts.Sort(); groups[i] = group; } return(groups); }
/// <summary> /// Tries to get the sprite part group part with the specified Id in the category. /// </summary> /// <param name="id">The Id of the sprite part group part to get.</param> /// <param name="value">The output sprite part group part if one was found, otherwise null.</param> /// <returns>True if a sprite part group part with the Id was found, otherwise null.</returns> public bool TryGetValue(int id, out SpritePartGroupPart value) { value = GroupParts.Find(gp => gp.Id == id); return(value != null); }
/*/// <summary> * /// Gets the sprite part group part at the specified index in the group. * /// </summary> * /// <param name="index">The index of the sprite part group part to get.</param> * /// <returns>The sprite part group part at the specified index.</returns> * public SpritePartGroupPart this[int index] => GroupParts[index]; * ISpritePartGroupPart ISpritePartGroup.this[int index] => this[index];*/ /// <summary> /// Gets the sprite part group part with the specified Id in the category. /// </summary> /// <param name="id">The Id of the sprite part group part to get.</param> /// <returns>The sprite part group part with the specified Id.</returns> /// /// <exception cref="KeyNotFoundException"> /// The element with the <paramref name="id"/> was not found. /// </exception> public SpritePartGroupPart this[int id] { get { SpritePartGroupPart element = GroupParts.Find(gp => gp.Id == id); return(element ?? throw new KeyNotFoundException($"Could not find the key \"{id}\"!")); } }
/// <summary> /// Compares the order between this sprite part group part and another. /// </summary> /// <param name="other">The sprite part group part to compare.</param> /// <returns>The comparison between this sprite part group part and <paramref name="other"/>.</returns> public int CompareTo(SpritePartGroupPart other) => Id.CompareTo(other.Id);
/// <summary> /// Checks for equality between this sprite part group part and another. /// </summary> /// <param name="other">The sprite part group part to compare.</param> /// <returns>True if <paramref name="other"/> is of the same Id.</returns> public bool Equals(SpritePartGroupPart other) => Id.Equals(other.Id);