public int ContainsEmote(TwitchEmote te) { for (int i = 0; i < this.Emotes.Length; i++) { if (this.Emotes[i].EmoteId == te.EmoteId) { return(i); } } return(-1); }
public void AddEmote(TwitchEmote te) { int Index = this.ContainsEmote(te); //Console.WriteLine(te.EmoteName + " | " + Index); if (Index != -1) { this.Emotes[Index].UseEmote(te.Amount); //Console.WriteLine("Using Emote: {0} - Amount: {1} Index: {2}", this.Emotes[Index].ToString(), te.Amount, Index); if (Index > 0) { if (this.Emotes[Index].Amount > this.Emotes[Index - 1].Amount) { int OldIndex = Index; while (Index > 0 && this.Emotes[OldIndex].Amount > this.Emotes[Index - 1].Amount) { Index--; } TwitchEmote ek = this.Emotes[Index]; this.EmoteList[Index] = this.Emotes[OldIndex]; this.EmoteList[OldIndex] = ek; Console.WriteLine("Swapped {1} -> {2}\t{0}", this.Emotes[Index].ToString(), OldIndex, Index); } } return; } else { //Console.WriteLine("This is a new emote!"); //Console.WriteLine("Adding emote: {0}", te.ToString()); if (!HasEmotes) { this.EmoteList.Add(te); return; } int EmoteIndex = -1; int l = 0; int r = this.Emotes.Length - 1; do { EmoteIndex = (l + r) / 2; if (this.Emotes[l].Amount == this.Emotes[r].Amount) { break; } int Amount = this.Emotes[EmoteIndex].Amount; if (this.Emotes[l].Amount == Amount) { EmoteIndex = l; break; } else if (this.Emotes[r].Amount == Amount) { EmoteIndex = r; break; } else if (Amount > te.Amount) { l = EmoteIndex + 1; } else { r = EmoteIndex - 1; } } while (this.Emotes[EmoteIndex].Amount != te.Amount); if (this.Emotes.Length > 10) { Console.WriteLine("Inserting {0} to position {1} | REF: {2}", te.ToString(), EmoteIndex, (EmoteIndex > -1) ? this.Emotes[EmoteIndex].ToString() : "None"); } if (EmoteIndex > -1) { this.EmoteList.Insert(EmoteIndex, te); } else { this.EmoteList.Add(te); } } }
public void Sort() { this.Emotes = TwitchEmote.SortByAmount(this.Emotes).ToArray(); }