public static void ReadSceneFile(TextAsset file) { Manager = PhaseManager.Get(); CurrentPhase = new Phase(); Regex regex = new Regex(@"\t*"); string temp = regex.Replace(file.text, ""); regex = new Regex(@" {2,}"); temp = regex.Replace(temp, " "); regex = new Regex(@" *= *"); temp = regex.Replace(temp, "="); regex = new Regex(Environment.NewLine + @"{2,}"); temp = regex.Replace(temp, ""); StreamWriter newFile = new StreamWriter(Application.dataPath + @"\ParseFix.txt"); newFile.Write(temp); newFile.Close(); StreamReader fileReader = new StreamReader(Application.dataPath + @"\ParseFix.txt"); while (!fileReader.EndOfStream) { ++CurrentLine; Debug.Log("Line #" + CurrentLine); string line = fileReader.ReadLine(); if(String.IsNullOrEmpty(line) || line.Trim().Length == 0) { Debug.Log("Skipping: Empty Line"); continue; } if (line.TrimStart().Substring(0, 2) == PP.COMMENT_LINE) { Debug.Log("Skipping: Comment Line"); continue; } if (line == PP.PHASE_CLOSE) { Debug.Log("Phase Ended"); Manager.AddPhase(CurrentPhase); CurrentPhase = null; } else { switch (line.GetWord(0, " ")) { case PP.PHASE_OPEN: case PP.GLOBAL_OPEN: Debug.Log("Beginning New Phase"); CurrentPhase = new Phase(); break; case PP.GLOBAL_CLOSE: Manager.AddGlobalPhase(CurrentPhase); CurrentPhase = null; break; case PP.CUSTOM_EVENT_OPEN: string eName = line.GetWord(1, " "); eName = eName.SplitTextDelimited("=")[1]; // Since Events can have prerequisite string preReqCheck = line.GetLastWord(" "); Debug.Log("PreReqs for " + eName + ": " + preReqCheck); if (preReqCheck.SplitTextDelimited("=")[0] == PP.PARAM_EVENT_REQ) { Debug.Log("PreReqs found"); CreateCustomEvent(ref fileReader, eName, Int32.Parse(preReqCheck.SplitTextDelimited("=")[1])); } else { Debug.Log("No PreReqs found, defaulting."); CreateCustomEvent(ref fileReader, eName); } break; case PP.EVENT_BEGIN_PHASE: case PP.EVENT_ENTER_TRIGGER: case PP.EVENT_ITEM_PICKUP: case PP.EVENT_TIMER_COMPLETED: Debug.Log("Creating Event Watcher"); CreateEventWatcher(line); break; case PP.EVENT_MATH_CONDITION: CurrentPhase.AddConditional(CreateConditional(line)); break; case PP.OBJECT_TIMER: case PP.OBJECT_VARIABLE: case PP.OBJECT_SOUND: Debug.Log("Creating Object"); CreateObject(line); break; case PP.PHASE_CLOSE: break; default: Debug.Log("Couldn't parse line: " + line); break; } } } fileReader.Close(); File.Delete(Application.dataPath + @"\ParseFix.txt"); Debug.Log("Parse Successful"); }
public static void ReadSceneFile(TextAsset file) { Manager = PhaseManager.Get(); CurrentPhase = new Phase(); Regex regex = new Regex(@"\t*"); string temp = regex.Replace(file.text, ""); regex = new Regex(@" {2,}"); temp = regex.Replace(temp, " "); regex = new Regex(@" *= *"); temp = regex.Replace(temp, "="); regex = new Regex(Environment.NewLine + @"{2,}"); temp = regex.Replace(temp, ""); StreamWriter newFile = new StreamWriter(Application.dataPath + @"\ParseFix.txt"); newFile.Write(temp); newFile.Close(); StreamReader fileReader = new StreamReader(Application.dataPath + @"\ParseFix.txt"); while (!fileReader.EndOfStream) { ++CurrentLine; Debug.Log("Line #" + CurrentLine); string line = fileReader.ReadLine(); if (String.IsNullOrEmpty(line) || line.Trim().Length == 0) { Debug.Log("Skipping: Empty Line"); continue; } if (line.TrimStart().Substring(0, 2) == PP.COMMENT_LINE) { Debug.Log("Skipping: Comment Line"); continue; } if (line == PP.PHASE_CLOSE) { Debug.Log("Phase Ended"); Manager.AddPhase(CurrentPhase); CurrentPhase = null; } else { switch (line.GetWord(0, " ")) { case PP.PHASE_OPEN: case PP.GLOBAL_OPEN: Debug.Log("Beginning New Phase"); CurrentPhase = new Phase(); break; case PP.GLOBAL_CLOSE: Manager.AddGlobalPhase(CurrentPhase); CurrentPhase = null; break; case PP.CUSTOM_EVENT_OPEN: string eName = line.GetWord(1, " "); eName = eName.SplitTextDelimited("=")[1]; // Since Events can have prerequisite string preReqCheck = line.GetLastWord(" "); Debug.Log("PreReqs for " + eName + ": " + preReqCheck); if (preReqCheck.SplitTextDelimited("=")[0] == PP.PARAM_EVENT_REQ) { Debug.Log("PreReqs found"); CreateCustomEvent(ref fileReader, eName, Int32.Parse(preReqCheck.SplitTextDelimited("=")[1])); } else { Debug.Log("No PreReqs found, defaulting."); CreateCustomEvent(ref fileReader, eName); } break; case PP.EVENT_BEGIN_PHASE: case PP.EVENT_ENTER_TRIGGER: case PP.EVENT_ITEM_PICKUP: case PP.EVENT_TIMER_COMPLETED: Debug.Log("Creating Event Watcher"); CreateEventWatcher(line); break; case PP.EVENT_MATH_CONDITION: CurrentPhase.AddConditional(CreateConditional(line)); break; case PP.OBJECT_TIMER: case PP.OBJECT_VARIABLE: case PP.OBJECT_SOUND: Debug.Log("Creating Object"); CreateObject(line); break; case PP.PHASE_CLOSE: break; default: Debug.Log("Couldn't parse line: " + line); break; } } } fileReader.Close(); File.Delete(Application.dataPath + @"\ParseFix.txt"); Debug.Log("Parse Successful"); }