public DataLabel(int newOffset, int newLength = 1, string labelName = "", string printTemplate = "", string cmt = "", DataSectionType dst = DataSectionType.Data, GBPalette pal = null) { m_id = System.Threading.Interlocked.Increment(ref counter); Value = newOffset; _length = newLength; Name = labelName == string.Empty ? string.Format("DS_{0:X6}", newOffset) : labelName; Comment = ""; if (!string.IsNullOrEmpty(cmt)) { Comment = cmt; } dataSectType = dst; if (pal != null) { palette = pal; } _printTemplate = printTemplate; if (_printTemplate == "") { _printTemplate = "b"; } }
// TODO: Make sure everything saves and loads properly. public void LoadLabelFile(string fileName) { using (TextReader labelFile = new StreamReader(fileName)) { using (TextWriter errFile = new StreamWriter("err.txt")) { if (labelFile.ReadLine() != "gbr") { return; } else { var items = new List <Dictionary <string, string> >(); int curItem = -1; string currentLine; while ((currentLine = labelFile.ReadLine()) != null) { switch (currentLine) { case ".label": { items.Add(new Dictionary <string, string>() { { "tag", "label" } }); curItem++; } break; case ".data": { items.Add(new Dictionary <string, string>() { { "tag", "data" } }); curItem++; } break; case ".var": { items.Add(new Dictionary <string, string>() { { "tag", "var" } }); curItem++; } break; case ".comment": { items.Add(new Dictionary <string, string>() { { "tag", "comment" } }); curItem++; } break; default: if (curItem == -1) { break; } string[] opt = currentLine.Split(new[] { ':' }, 2); if (opt.Length == 1) { if (items[curItem].ContainsKey("_c")) { items[curItem]["_c"] += "\n" + currentLine; } else { items[curItem].Add("_c", currentLine); } } else { if (items[curItem].ContainsKey(opt[0])) { items[curItem][opt[0]] = opt[1]; } else { items[curItem].Add(opt[0], opt[1]); } } break; } } foreach (var currentItem in items) { switch (currentItem["tag"]) { case "label": { int offset = 0; string name = ""; string comment = ""; bool offsetGood = false; foreach (var kvp in currentItem) { switch (kvp.Key) { case "_o": { offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset); } break; case "_n": { if (Utility.IsWord(kvp.Value)) { name = kvp.Value; } } break; case "_c": { comment = kvp.Value; } break; } } if (offsetGood) { FunctionLabel fl = new FunctionLabel(offset, name, comment); AddFuncLabel(fl); } else { errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized."); } } break; case "data": { int offset = -1; int length = -1; string printTemp = ""; string name = ""; string comment = ""; DataSectionType dst = DataSectionType.Data; GBPalette gbp = new GBPalette(); bool offsetGood = false; bool lengthGood = false; foreach (var kvp in currentItem) { switch (kvp.Key) { case "_o": { offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset); } break; case "_l": { lengthGood = Utility.OffsetStringToInt(kvp.Value, out length); } break; case "_n": { if (Utility.IsWord(kvp.Value)) { name = kvp.Value; } } break; case "_d": { printTemp = kvp.Value; } break; case "_p1": { dst = DataSectionType.Image; Utility.OffsetStringToInt(kvp.Value, out gbp.Col_1); } break; case "_p2": { dst = DataSectionType.Image; Utility.OffsetStringToInt(kvp.Value, out gbp.Col_2); } break; case "_p3": { dst = DataSectionType.Image; Utility.OffsetStringToInt(kvp.Value, out gbp.Col_3); } break; case "_p4": { dst = DataSectionType.Image; Utility.OffsetStringToInt(kvp.Value, out gbp.Col_4); } break; case "_c": { comment = kvp.Value; } break; } } if (offsetGood && lengthGood) { DataLabel ds = new DataLabel(offset, length, name, printTemp, comment, dst, gbp); AddDataLabel(ds); } else { errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized."); } } break; case "var": { int variable = -1; string name = ""; string comment = ""; bool variableGood = false; foreach (var kvp in currentItem) { switch (kvp.Key) { case "_v": { variableGood = Utility.OffsetStringToInt(kvp.Value, out variable); } break; case "_n": { if (Utility.IsWord(kvp.Value)) { name = kvp.Value; } } break; case "_c": { comment = kvp.Value; } break; } } if (variableGood) { VarLabel vl = new VarLabel(variable, name, comment); AddVarLabel(vl); } else { errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized."); } } break; case "comment": { int offset = 0; string name = String.Empty; string comment = ""; bool offsetGood = false; foreach (var kvp in currentItem) { switch (kvp.Key) { case "_o": { offsetGood = Utility.OffsetStringToInt(kvp.Value, out offset); } break; case "_c": { comment = kvp.Value; } break; } } if (offsetGood) { AddComment(offset, comment); } else { errFile.WriteLine("Label #" + items.IndexOf(currentItem) + " was unrecognized."); } } break; default: break; } } } } } }