public void loadScript(GameData gamedata, string gameScriptPath) { string lineRead; string functionName = null; string functionExpressions = null; int countLine; gamedata.script = new Dictionary<string, string>(); bool readingFunction = false; bool readingComment = false; string[] filePaths = Directory.GetFiles(gameScriptPath, "*.cps", SearchOption.AllDirectories); foreach (string file in filePaths) { countLine = 0; StreamReader SRead = new StreamReader(file, System.Text.Encoding.UTF8); while ((lineRead = SRead.ReadLine()) != null) { if (lineRead != null) lineRead = lineRead.TrimStart(); countLine++; if (readingFunction) { if (lineRead.StartsWith("#end", true, null) && !readingComment) { readingFunction = false; gamedata.script.Add(functionName, functionExpressions); functionName = null; functionExpressions = null; } else if (lineRead.StartsWith("#function", true, null)) { throw new CruiserScriptLoadException("Could not find #end but found new #function at line " + countLine + " of file " + file); } else if (lineRead.StartsWith(@"//", true, null)) { } else if (lineRead.StartsWith(@"/*", true, null)) { readingComment = true; } else if (lineRead.EndsWith(@"*/", true, null)) { readingComment = false; } else if (readingComment) { } else { functionExpressions += (lineRead + "\n"); } } else { if (lineRead.StartsWith("#function", true, null)) { functionName = lineRead.Replace("#function ", "").ToLower(); functionName.Trim(); readingFunction = true; } } } if (readingFunction) { throw new CruiserScriptLoadException("Could not find #end but reached EOF at line " + countLine + " of file " + file); } SRead.Close(); } }
public void initialize() { lua = new Lua(); luaFunctions = new Hashtable(); registerLuaFunctions(this); try { Console.WriteLine("Loading Games..."); gameData = new GameData("scripts\\gamedata.xml", "scripts\\", ref lua); } catch (CruiserGameShutException e) { Console.WriteLine(e); isGameShut = true; } }