private static void addUnique(NounVerbCase nvc, List <NounVerbCase> nvcs, bool isAll) { for (int i = 0; i < nvcs.Count; i++) { if (nvcs[i].Noun == nvc.Noun && nvcs[i].Verb == nvc.Verb) { // the "ALL" case seems to be like an "else", where // it is overridden if there are other valid cases. // So since we already have a valid case, ignore this one if it's "ALL". if (isAll) { return; } // compare priorities and keep the higher of the two int oldPriority = CaseUtils.GetCasePriority(nvcs[i].CaseType); int newPriority = CaseUtils.GetCasePriority(nvc.CaseType); if (newPriority > oldPriority) { nvcs[i] = nvc; } return; } } // still here? must be a new case. nvcs.Add(nvc); }
public NvcResource(string name, System.IO.Stream stream) : base(name, stream) { // load the Logic aliases foreach (Resource.InfoSection section in _sections) { if (section.Name.Equals("Logic", StringComparison.OrdinalIgnoreCase)) { foreach (Resource.InfoLine line in section.Lines) { _logic.Add(new KeyValuePair <string, string>(line.Attributes[0].Key, line.Attributes[0].Value.Replace("{", "").Replace("}", ""))); } } } foreach (Resource.InfoLine line in GlobalSection.Lines) { NounVerbCase nvc; nvc.Noun = NounUtils.ConvertStringToNoun(line.Value); nvc.Verb = VerbsUtils.ConvertStringToVerbs(line.Attributes[0].Key); nvc.Case = line.Attributes[1].Key; nvc.CaseType = CaseUtils.ConvertStringToCase(line.Attributes[1].Key); string approach; if (line.TryGetAttribute("approach", out approach)) { if (approach.ToUpper() == "WALKTO") { nvc.Approach = NvcApproachType.WalkTo; } else if (approach.ToUpper() == "TURNTOMODEL") { nvc.Approach = NvcApproachType.TurnToModel; } else { nvc.Approach = NvcApproachType.None; } } else { nvc.Approach = NvcApproachType.None; } line.TryGetAttribute("target", out nvc.Target); line.TryGetAttribute("script", out nvc.Script); // remove any { } around the script // (normally they wouldn't mess anything up, but there are a few // that have no ; at the end, and those will mess up) int firstBracket = nvc.Script.IndexOf("{"); int lastBracket = nvc.Script.LastIndexOf("}"); if (firstBracket >= 0 && lastBracket >= 0) { nvc.Script = nvc.Script.Substring(firstBracket + 1, lastBracket - firstBracket - 1); } else if (firstBracket >= 0) { nvc.Script = nvc.Script.Substring(firstBracket + 1); } else if (lastBracket >= 0) { nvc.Script = nvc.Script.Substring(0, lastBracket); } add(nvc); } }