Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Encounter> LoadSet(string path)
- {
- StreamReader sr = new StreamReader(path);
- Encounter encounter = new Encounter();
- EncounterAction encAction = new EncounterAction();
- List<Encounter> listEncounters = new List<Encounter>();
- int lineNumber = 0;
- while ((line = sr.ReadLine()) != null)
- {
- lineNumber++;
- line = line.Trim();
- if (line.StartsWith("//")) { }
- else if (string.IsNullOrEmpty(line)) { }
- else if (line.StartsWith("name:"))
- {
- if (!string.IsNullOrEmpty(encounter.Name))
- {
- Debug.LogWarning("Potential encounter overwriting at " + lineNumber + " in " + path);
- }
- encounter.Name = line.Replace("name:", "");
- encounter.Name = encounter.Name.Trim();
- if (encounterNames.Contains(encounter.Name))
- {
- Debug.LogWarning("Duplicate encounter name " + encounter.Name + " at " + lineNumber + " in " + path);
- }
- encounterNames.Add(encounter.Name);
- }
- else if (line.StartsWith("tag:"))
- {
- encounter.LocationTag = line.Replace("tag:", "");
- encounter.LocationTag = encounter.LocationTag.Trim();
- }
- else if (line.StartsWith("modifierRequirement:"))
- {
- encounter.ModifierRequirement = line.Replace("modifierRequirement:", "");
- encounter.ModifierRequirement = encounter.ModifierRequirement.Trim();
- }
- else if (line.StartsWith("text:"))
- {
- string text = line.Replace("text:", "");
- text = text.Trim();
- encounter.Text += "\n\n" + text;
- encounter.Text = encounter.Text.Trim();
- }
- else if (line.StartsWith("end"))
- {
- if (!string.IsNullOrEmpty(encounter.Name) &&
- !string.IsNullOrEmpty(encounter.LocationTag) &&
- !string.IsNullOrEmpty(encounter.Text))
- {
- listEncounters.Add(encounter);
- }
- else
- {
- Debug.LogWarning("Minimum tags not met at line " + lineNumber + " in " + path);
- }
- encounter = new Encounter();
- }
- else
- {
- Debug.LogWarning("Bad encounter formatting (" + line + ") at line " + lineNumber + " in " + path);
- }
- }
- return listEncounters;
- }
Advertisement
Add Comment
Please, Sign In to add comment