public void Init(string _name) { Name = _name.ToUpperInvariant(); if (ScriptEngine.Classes.ContainsKey(Name)) { Script_Class sc = (Script_Class)ScriptEngine.Classes[Name]; //found our class... need to copy over the variables now foreach (ScriptVariable sv in sc._Variables) { _Variables.Add(sv.Name, sv.Clone()); } } }
public void ReadFile(ScriptFile filein) { File = filein.Name; //gotta find the varbeing and varend and read in the middle bool cstarted = false; bool vstarted = false; bool cended = false; string p1, p2, p3; for (int i = 0; i < filein._ScriptLines.Count; i++) { ScriptLine cmd = (ScriptLine)filein._ScriptLines[i]; string line = cmd.UnParsedParams; switch (cmd.Command) { case ScriptCommands.INCLUDE: if (!cstarted) { Globals.scriptthread.Script_INCLUDE(line); } break; case ScriptCommands.PUBLIC: if (cstarted && vstarted) { //defining a variable p1 = ScriptEngine.Get_String(ref line); p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant(); p3 = ScriptEngine.Get_String(ref line); ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PUBLIC); _Variables.Add(nv); } else if (cstarted) { //a function p1 = ScriptEngine.Get_String(ref line); Add_Function(p1, i, filein, Var_State.PUBLIC); } break; case ScriptCommands.PRIVATE: if (cstarted && vstarted) { //defining a variable p1 = ScriptEngine.Get_String(ref line); p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant(); p3 = ScriptEngine.Get_String(ref line); ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PRIVATE); _Variables.Add(nv); } else if (cstarted) { //a function p1 = ScriptEngine.Get_String(ref line); Add_Function(p1, i, filein, Var_State.PRIVATE); } break; case ScriptCommands.PROTECTED: if (cstarted && vstarted) { //defining a variable p1 = ScriptEngine.Get_String(ref line); p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant(); p3 = ScriptEngine.Get_String(ref line); ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.PROTECTED); _Variables.Add(nv); } else if (cstarted) { //a function p1 = ScriptEngine.Get_String(ref line); Add_Function(p1, i, filein, Var_State.PROTECTED); } break; case ScriptCommands.STATIC: if (cstarted && vstarted) { //defining a variable p1 = ScriptEngine.Get_String(ref line); p2 = ScriptEngine.Get_String(ref line).ToUpperInvariant(); p3 = ScriptEngine.Get_String(ref line); ScriptVariable nv = ScriptEngine.Create_Variable(p1, p2, p3, Var_State.STATIC); _Variables.Add(nv); } else if (cstarted) { //a function p1 = ScriptEngine.Get_String(ref line); Add_Function(p1, i, filein, Var_State.STATIC); } break; case ScriptCommands.CLASS: cstarted = true; Name = ScriptEngine.Get_String(ref line).ToUpperInvariant(); p1 = ScriptEngine.Get_String(ref line).ToUpperInvariant(); if (p1 != "NULL" && p1.Length != 0) { //gotta find this class... and copy over it's stuff if (ScriptEngine.Classes.ContainsKey(p1)) { Script_Class sc = (Script_Class)ScriptEngine.Classes[p1]; foreach (ScriptVariable nv in sc._Variables) { _Variables.Add(nv.Clone()); } ParentName = sc.Name; ParentFile = sc.File; } else { ScriptEngine.Script_Error("CLASS [" + p1 + "] NOT LOADED PRIOR TO USAGE"); } } break; case ScriptCommands.END_CLASS: cended = true; cstarted = false; break; case ScriptCommands.VAR_START: vstarted = true; break; case ScriptCommands.VAR_END: vstarted = false; break; } if (cended) { break; } } }
public void Script_INCLUDE(string line) { string s_file = Get_String(ref line); s_file = Globals.PATH + "\\Scripts\\" + s_file; s_file = s_file.ToUpperInvariant().Replace('/','\\'); try { Script_Class sc = new Script_Class(); if (!Files.ContainsKey(s_file)) { System.IO.StreamReader filein = new System.IO.StreamReader(s_file); ScriptFile sf = new ScriptFile(); sf.Name = s_file; sf.ReadScript(filein); filein.Close(); Files.Add(sf.Name, sf); sc.ReadFile(sf); if (!Classes.ContainsKey(sc.Name)) { Classes.Add(sc.Name, sc); } else { //we already have a class of this name... from a different file ScriptEngine.Script_Error("FAILED TO INCLUDE FILE : " + s_file + " : A class of this name [" + sc.Name + "] from a different file has already been loaded"); Globals.gamedata.CurrentScriptState = ScriptState.Error; } } /*else { //we already have this file loaded... why would we want to reload it? //what was I thinking here? maybe they would have a class in a non class file? f**k that... //sc.ReadFile((ScriptFile)Files[s_file]); }*/ } catch { ScriptEngine.Script_Error("FAILED TO INCLUDE FILE : " + s_file); Globals.gamedata.CurrentScriptState = ScriptState.Error; } }