/// <summary> /// Add new cheat code /// </summary> /// <param name="cp"></param> public void AddChainePattern(ChainePattern cp) { // some checks foreach (ChainePattern current in availablePatterns) { // check against fact that passed pattern will hide some existed pattern line new pattern "ABC" will hide an existing pattern like "ABCD" cause the older one will never be triggered if (cp.Count() < current.Count()) { List <int> newCp = new List <int>(current.Pattern).GetRange(0, cp.Count()); if (cp.Pattern.SequenceEqual(newCp)) { throw new Exception("Duplication found, new pattern \"" + cp.Alias + "\" will hide \"" + current.Alias + "\" alreay existed"); } } // check against fact that passed pattern will be hidden by an existing pattern line new pattern "ABCD" will be hidden by an existing pattern like "ABC" will hide new one "ABCD" else if (cp.Count() > current.Count()) { List <int> newCp = new List <int>(cp.Pattern).GetRange(0, current.Count()); if (current.Pattern.SequenceEqual(newCp)) { throw new Exception("Duplication found, the already registred pattern \"" + current.Alias + "\" will hide the new one \"" + cp.Alias + "\""); } } // check if dupplication exist else if (cp.Count() == current.Count()) { if (current.Pattern.SequenceEqual(cp.Pattern)) { throw new Exception("Pattern \"" + cp.Alias + "\" already exist"); } } } availablePatterns.Add(cp); matchedPatterns.Clear(); matchedPatterns = new List <ChainePattern>(availablePatterns); }
public PatternEventHandler(ChainePattern chainePattern) { ChainePattern = chainePattern; }