public static LpTemplate ParseTempl(string s, int start, out int idx, bool rootlevel) { idx = start; LpTemplate template = new LpTemplate(); List<LpItem> items = template.Children; while (idx < s.Length) { int commentopenindex = s.IndexOf("<!--", idx); int templatecloseindex = rootlevel ? -1 : s.IndexOf("}}", idx); int templateopenindex = s.IndexOf("{{", idx); if ((commentopenindex >= 0) && ((templatecloseindex < 0) || (commentopenindex < templatecloseindex)) && ((templateopenindex < 0) || (commentopenindex < templateopenindex))) { string text = s.Substring(idx, commentopenindex - idx).TrimWhitespace(); if (!string.IsNullOrEmpty(text)) items.Add(new LpText(text)); items.Add(ParseComment(s, commentopenindex + 4, out idx)); } else if ((templateopenindex < 0) || ((templatecloseindex >= 0) && (templatecloseindex < templateopenindex))) { if (templatecloseindex < 0) { string text = s.Substring(idx).TrimWhitespace(); if (!string.IsNullOrEmpty(text)) items.Add(new LpText(text)); idx = s.Length; } else { string text = s.Substring(idx, templatecloseindex - idx).TrimWhitespace(); if (!string.IsNullOrEmpty(text)) items.Add(new LpText(text)); idx = templatecloseindex + 2; break; } } else if (templateopenindex == idx) { items.Add(ParseTempl(s, templateopenindex + 2, out idx, false)); } else { string text = s.Substring(idx, templateopenindex - idx); if (!string.IsNullOrEmpty(text)) items.Add(new LpText(text)); items.Add(ParseTempl(s, templateopenindex + 2, out idx, false)); } } // now process into params if (!rootlevel) { List<LpItem> currentParam = new List<LpItem>(); int unnamed = 0; string paramName = "0"; Queue<LpItem> remainingItems = new Queue<LpItem>(template.Children); while (remainingItems.Count > 0) { LpItem item = remainingItems.Dequeue(); if (item is LpText) { string text = (item as LpText).Text; int baridx; while ((baridx = text.IndexOf('|')) >= 0) { // add up to the | string tt = text.Substring(0, baridx).TrimWhitespace(); if (!string.IsNullOrEmpty(tt)) currentParam.Add(new LpText(tt)); template.Params[paramName] = currentParam; currentParam = new List<LpItem>(); text = text.Substring(baridx + 1); int nextbar = text.IndexOf('|'); int equalsidx; if (nextbar > 0) equalsidx = text.IndexOf('=', 0, nextbar); else equalsidx = text.IndexOf('='); if (equalsidx < 0) { unnamed++; paramName = unnamed.ToString(); } else { paramName = text.Substring(0, equalsidx).TrimWhitespace(); text = text.Substring(equalsidx + 1); } } text = text.TrimWhitespace(); if (text.Length > 0) currentParam.Add(new LpText(text)); } else { currentParam.Add(item); } } if (currentParam.Count != 0) { template.Params[paramName] = currentParam; } } return template; }
private bool TryProcessMatchMaps(LpTemplate template) { string fmtfile = Path.Combine(fmtfolder, template.Name + ".matchfmt"); if (!File.Exists(fmtfile)) return false; string[] xs = File.ReadAllLines(fmtfile); if (xs.Length != 4) { sw.WriteLine("; Unrecognised match formatting file."); return true; } sw.WriteLine("; -- {0} --", template.Name); string mapname = xs[2]; int mapno = 1; while (true) { if (TryProcessMatch(template, xs[0], xs[1], xs[2], xs[3], mapno)) mapno++; else break; if (!mapname.Contains("{0}")) break; } // just for TeamMatch really TryProcessMatch(template, "acep1", "acep2", "acemap", "acewin"); return true; }
private bool TryProcessMatch(LpTemplate template, string p1, string p2, string mapname, string mapwin, object param) { string playerleft = template.GetParamText(string.Format(p1, param)); if (playerleft == null) return false; playerleft = playerleft.Replace(" ", "_"); string playerright = template.GetParamText(string.Format(p2, param)); if (playerright == null) return false; playerright = playerright.Replace(" ", "_"); players.AddUnique(playerleft); players.AddUnique(playerright); string mapnameparam = string.Format(mapname, param); string mapwinparam = string.Format(mapwin, param); if (!template.Params.ContainsKey(mapwinparam)) return false; string map = "Unknown"; if (template.Params.ContainsKey(mapnameparam)) { map = template.GetParamText(mapnameparam) ?? "Unknown"; } maps.AddUnique(map); string win = template.GetParamText(mapwinparam); if (string.IsNullOrEmpty(win) || win == "skip") return false; string arrow = "?"; if (win == "1") arrow = ">"; else if (win == "2") arrow = "<"; sw.WriteLine("{0} {2} {1} : {3}", playerleft, playerright, arrow, map); return true; }
private bool TryProcessMatch(LpTemplate template, string p1, string p2, string mapnameparam, string mapwinparam) { return TryProcessMatch(template, p1, p2, mapnameparam, mapwinparam, null); }
private bool TryProcessBracket(LpTemplate template) { string fmtfile = Path.Combine(fmtfolder, template.Name + ".bracketfmt"); if (!File.Exists(fmtfile)) return false; sw.WriteLine("; -- {0} --", template.Name); using (var fmtsr = new StreamReader(fmtfile)) { string fmtstring; while ((fmtstring = fmtsr.ReadLine()) != null) { if (string.IsNullOrEmpty(fmtstring) || fmtstring.StartsWith(";")) { sw.WriteLine(fmtstring); continue; } string[] xs = fmtstring.Split(' '); if (xs.Length == 2) { ProcessBracketGame(template, xs[0], xs[1], ""); } else if (xs.Length == 3) { ProcessBracketGame(template, xs[0], xs[1], xs[2]); } else { sw.WriteLine("; Unrecognised format string: " + fmtstring); } } return true; } }
private void ProcessBracketGame(LpTemplate template, string left, string right, string game) { if (!template.Params.ContainsKey(left)) return; if (!template.Params.ContainsKey(right)) return; string playerleft = template.GetParamText(left); if (playerleft == null) return; playerleft = playerleft.Replace(" ", "_"); string playerright = template.GetParamText(right); if (playerright == null) return; playerright = playerright.Replace(" ", "_"); players.AddUnique(playerleft); players.AddUnique(playerright); int scoreleft, scoreright; if (!int.TryParse(template.GetParamText(left + "score"), out scoreleft) | !int.TryParse(template.GetParamText(right + "score"), out scoreright)) { sw.WriteLine(";{0}-{1} {2} {3}", template.GetParamText(left + "score"), template.GetParamText(right + "score"), playerleft, playerright); return; } if (template.Params.ContainsKey(game + "details")) { // game has details - use them LpTemplate details = template.GetParamTemplate(game + "details", "BracketMatchSummary"); for (int i = 1; i <= scoreleft + scoreright; i++) { string map = "Unknown"; if (details.Params.ContainsKey("map" + i.ToString())) { map = details.GetParamText("map" + i.ToString()) ?? "Unknown"; } maps.AddUnique(map); string win = details.GetParamText(string.Format("map{0}win", i)); if (string.IsNullOrEmpty(win) || win == "skip") continue; string arrow = "?"; if (win == "1") arrow = ">"; else if (win == "2") arrow = "<"; sw.WriteLine("{0} {2} {1} : {3}", playerleft, playerright, arrow, map); } } else { // just output games sw.WriteLine("{0}-{1} {2} {3}", scoreleft, scoreright, playerleft, playerright); // TODO- extended series //|R5W1score2, |R5W2score2= } }