SHOW:
|
|
- or go back to the newest paste.
| 1 | public List<Encounter> LoadSet(string path) | |
| 2 | {
| |
| 3 | StreamReader sr = new StreamReader(path); | |
| 4 | Encounter encounter = new Encounter(); | |
| 5 | - | EncounterAction encAction = new EncounterAction(); |
| 5 | + | |
| 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 | - | if (encounterNames.Contains(encounter.Name)) |
| 29 | + | |
| 30 | } | |
| 31 | - | Debug.LogWarning("Duplicate encounter name " + encounter.Name + " at " + lineNumber + " in " + path);
|
| 31 | + | |
| 32 | else if (line.StartsWith("modifierRequirement:"))
| |
| 33 | {
| |
| 34 | - | encounterNames.Add(encounter.Name); |
| 34 | + | |
| 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 | - | |
| 63 | + | |
| 64 | {
| |
| 65 | Debug.LogWarning("Bad encounter formatting (" + line + ") at line " + lineNumber + " in " + path);
| |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | return listEncounters; | |
| 70 | } |