Guest User

Untitled

a guest
Sep 12th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public List<Encounter> LoadSet(string path)
  2. {
  3.     StreamReader sr = new StreamReader(path);
  4.     Encounter encounter = new Encounter();
  5.     List<Encounter> listEncounters = new List<Encounter>();
  6.  
  7.     int lineNumber = 0;
  8.     while ((line = sr.ReadLine()) != null)
  9.     {
  10.         lineNumber++;
  11.         line = line.Trim();
  12.         if (line.StartsWith("//")) { }
  13.         else if (string.IsNullOrEmpty(line)) { }
  14.  
  15.         else if (line.StartsWith("name:"))
  16.         {
  17.             if (!string.IsNullOrEmpty(encounter.Name))
  18.             {
  19.                 Debug.LogWarning("Potential encounter overwriting at " + lineNumber + " in " + path);
  20.             }
  21.  
  22.             encounter.Name = line.Replace("name:", "");
  23.             encounter.Name = encounter.Name.Trim();
  24.         }
  25.  
  26.         else if (line.StartsWith("tag:"))
  27.         {
  28.             encounter.LocationTag = line.Replace("tag:", "");
  29.             encounter.LocationTag = encounter.LocationTag.Trim();
  30.         }
  31.  
  32.         else if (line.StartsWith("modifierRequirement:"))
  33.         {
  34.             encounter.ModifierRequirement = line.Replace("modifierRequirement:", "");
  35.             encounter.ModifierRequirement = encounter.ModifierRequirement.Trim();
  36.         }
  37.  
  38.         else if (line.StartsWith("text:"))
  39.         {
  40.             string text = line.Replace("text:", "");
  41.             text = text.Trim();
  42.             encounter.Text += "\n\n" + text;
  43.             encounter.Text = encounter.Text.Trim();
  44.         }
  45.  
  46.         else if (line.StartsWith("end"))
  47.         {
  48.             if (!string.IsNullOrEmpty(encounter.Name) &&
  49.                 !string.IsNullOrEmpty(encounter.LocationTag) &&
  50.                 !string.IsNullOrEmpty(encounter.Text))
  51.             {
  52.                 listEncounters.Add(encounter);
  53.             }
  54.  
  55.             else
  56.             {
  57.                 Debug.LogWarning("Minimum tags not met at line " + lineNumber + " in " + path);
  58.             }
  59.  
  60.             encounter = new Encounter();
  61.         }
  62.  
  63.         else
  64.         {
  65.             Debug.LogWarning("Bad encounter formatting (" + line + ") at line " + lineNumber + " in " + path);
  66.         }
  67.     }
  68.  
  69.     return listEncounters;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment