Guest User

Untitled

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