Esempio n. 1
0
 public override Variable Clone()
 {
     Node clone=new Node(_name);
     foreach (Variable v in _children)
     clone.Add(v.Clone());
     return clone;
 }
Esempio n. 2
0
        private void LoadScene(Node root, World world)
        {
            Identifier iden = _tplSceneUnified.GetMatchingIdentifier(root);
            if (iden == null)
                throw new Exception(String.Format("Could not find identifier {0} in script", _tplSceneUnified.Identity[0]));
            Scene scene = CreateScene(iden, world, null);

            Node subs = root.GetNode("subs");
            if (subs != null)
            {
                foreach (Variable v in subs)
                {
                    iden = v as Identifier;
                    if (_tplSceneUnified.ValidateIdentifier(iden))
                        CreateScene(iden, world, scene);
                    else
                        Logger.Warn("Unrecognized variable named \"{0}\" in sub-scene node", v.Name);
                }
            }
        }
Esempio n. 3
0
 private void LoadListNode(Node root)
 {
     foreach (Variable v in root)
     {
         IntVariable val = v as IntVariable;
         if (_tplWorldPath.ValidateValue(val))
             this.Paths[val.Value] = Path.Combine(Directory.GetCurrentDirectory(), val.Name);
         else
             Logger.Warn("Unrecognized variable named \"{0}\" in path list", v.Name);
     }
 }
Esempio n. 4
0
        private World LoadNode(Node root)
        {
            IntVariable ivar = (IntVariable)_tplWorldSNO.GetMatchingValue(root);
            if (ivar == null)
                throw new Exception(String.Format("Could not find value {0} in script", _tplWorldSNO.Identity[0]));
            World world = new World(this.Game, ivar.Value);

            Identifier iden = _tplStartPos.GetMatchingIdentifier(root);
            if (iden == null)
                throw new Exception(String.Format("Could not find identifier {0} in script", _tplStartPos.Identity[0]));
            world.StartPosition.X = iden.GetFloat(0).Value;
            world.StartPosition.Y = iden.GetFloat(1).Value;
            world.StartPosition.Z = iden.GetFloat(2).Value;

            string name = "scenes";
            Node node = root.GetNode(name, false);
            if (node == null)
                throw new Exception(String.Format("Could not find node {0} in script", name));
            LoadWorldScenes(node, world);
            world.SortScenes();
            return world;
        }
Esempio n. 5
0
 private void LoadWorldScenes(Node root, World world)
 {
     foreach (Variable v in root)
     {
         if (v is Node)
         {
             LoadScene((Node)v, world);
         }
     }
 }
Esempio n. 6
0
 protected virtual void Process()
 {
     _rootnode=new Node((CollectionVariable)null);
     _currentnode=_rootnode;
     while (_parser.Parse()) {
     }
     Finish();
     if (_currentnode!=_rootnode)
     throw new ScriptParserException(ScriptParserError.HIERARCHY, "Process", null, null, "The current node does not match the root node");
 }
Esempio n. 7
0
 public override void HandleToken(Token<ScriptToken> token)
 {
     switch (token.Type) {
     case ScriptToken.String:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             int bv=Variable.StringToBool(token.ToString());
             if (bv!=-1) {
                 AddVariableAndReset(_currentnode, new BoolVariable(bv==1 ? true : false, _varname), false, false);
                 break;
             } else {
                 AddVariableAndReset(_currentnode, new StringVariable(token.ToString(), _varname), false, false);
             }
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             int bv=Variable.StringToBool(token.ToString());
             if (bv!=-1) {
                 AddVariableAndReset(_currentiden, new BoolVariable(bv==1 ? true : false), false, false);
                 break;
             }
             AddVariableAndReset(_currentiden, new StringVariable(token.ToString()), false, false);
         } else {
             _varname=token.ToString();
         }
         break;
     case ScriptToken.QuotedString:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             AddVariableAndReset(_currentnode, new StringVariable(token.ToString(), _varname), false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new StringVariable(token.ToString()), false, false);
         } else {
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Number:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             _currentvalue=new IntVariable(token.ToInt(), _varname);
             AddVariableAndReset(_currentnode, _currentvalue, false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new IntVariable(token.ToInt()), false, false);
         } else {
             //new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "A number cannot be an identifier");
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Double:
         if (!String.IsNullOrEmpty(_varname) && _equals) {
             _currentvalue=new FloatVariable((float)token.ToDouble(), _varname);
             AddVariableAndReset(_currentnode, _currentvalue, false, false);
         } else if ((!String.IsNullOrEmpty(_varname) || _currentiden!=null) && !_equals) {
             MakeIdentifier(token);
             AddVariableAndReset(_currentiden, new FloatVariable((float)token.ToDouble()), false, false);
         } else {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "A number cannot be an identifier");
             _varname=token.ToString();
         }
         break;
     case ScriptToken.Equals:
         if (_currentiden!=null)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Unexpected equality sign after identifier declaration");
         else if (_varname.Length==0)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected string, got equality sign");
         else if (_equals)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected value, got equality sign");
         else
             _equals=true;
         break;
     case ScriptToken.OpenBrace:
         if (_currentiden!=null)
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Node cannot contain values (possible openbrace typo)");
         Node tempnode=new Node(_varname, _currentnode);
         AddVariableAndReset(_currentnode, tempnode, false, false);
         _currentnode=tempnode;
         break;
     case ScriptToken.CloseBrace:
         if (_currentnode.Parent==null) {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Mismatched node brace");
         } else if (_equals) {
             new ScriptParserException(ScriptParserError.PARSER, "StandardScriptParserHandler.HandleToken", token, _parser, "Expected value, got close-brace");
         } else {
             if (_currentiden!=null)
                 Reset(true, true);
             _currentnode=(Node)_currentnode.Parent;
         }
         break;
     case ScriptToken.Comment:
     case ScriptToken.CommentBlock:
         // Do nothing
         break;
     case ScriptToken.EOL:
     case ScriptToken.EOF:
         Finish();
         break;
     //default:
     //	//DebugLog("(StandardScriptParserHandler.handleToken) Unhandled token of type "+token.typeAsString())
     //	break;
     }
 }
Esempio n. 8
0
 public static bool WriteToStream(Node root, StreamWriter stream, ValueFormat nameformat, ValueFormat varformat, int tcount)
 {
     if (root!=null && stream!=null) {
     string temp;
     int tcountd=tcount;
     if (root.Parent!=null) {
         if (!String.IsNullOrEmpty(root.Name)) {
             temp=root.GetNameFormatted(nameformat);
             temp+=" {";
             stream.WriteLine(temp.PadLeft(temp.Length+tcount, '\t'));
         } else {
             stream.Write(new String('\t', tcount));
             stream.WriteLine('{');
         }
         tcountd++;
     } else {
         //stream.WriteLine();
     }
     bool writtenvariable=false;
     foreach (Variable variable in root.Children) {
         if (variable is ValueVariable) {
             if (FormatValue((ValueVariable)variable, out temp, nameformat, varformat)) {
                 stream.WriteLine(temp.PadLeft(temp.Length+tcountd, '\t'));
                 writtenvariable=true;
             }
         } else if (variable is Identifier) {
             if (FormatIdentifier((Identifier)variable, out temp, nameformat, varformat)) {
                 stream.WriteLine(temp.PadLeft(temp.Length+tcountd, '\t'));
                 writtenvariable=true;
             }
         } else if (variable is Node) {
             if (root.Parent==null && writtenvariable)
                 stream.WriteLine(new String('\t', tcountd));
             WriteToStream((Node)variable, stream, nameformat, varformat, tcountd);
             if (root.Parent==null)
                 stream.WriteLine(new String('\t', tcountd));
             writtenvariable=false;
         }
     }
     if (root.Parent!=null) {
         stream.Write(new String('\t', tcount));
         stream.WriteLine('}');
     }
     return true;
     }
     return false;
 }
Esempio n. 9
0
 protected virtual void Clean()
 {
     _currentnode=null;
     _rootnode=null;
 }
Esempio n. 10
0
 public static bool WriteToStream(Node root, StreamWriter stream, ValueFormat nameformat)
 {
     return WriteToStream(root, stream, nameformat, ValueFormat.ALL_DEFAULT);
 }
Esempio n. 11
0
 public static bool WriteToStream(Node root, StreamWriter stream, ValueFormat nameformat, ValueFormat varformat)
 {
     return WriteToStream(root, stream, nameformat, varformat, 0);
 }
Esempio n. 12
0
 public static bool WriteToStream(Node root, StreamWriter stream)
 {
     return WriteToStream(root, stream, ValueFormat.NAME_DEFAULT);
 }
Esempio n. 13
0
 public static bool WriteToFile(Node root, string path, ValueFormat nameformat, ValueFormat varformat, Encoding encoding)
 {
     //try {
     StreamWriter stream=new StreamWriter(path, false, encoding);
     bool ret=WriteToStream(root, stream, nameformat, varformat, 0);
     stream.Close();
     return ret;
     //} catch {
     //}
     //return false;
 }
Esempio n. 14
0
 public static bool WriteToFile(Node root, string path, ValueFormat nameformat, ValueFormat varformat)
 {
     return WriteToFile(root, path, nameformat, varformat, Encoding.UTF8);
 }
Esempio n. 15
0
 public static bool WriteToFile(Node root, string path, ValueFormat nameformat)
 {
     return WriteToFile(root, path, nameformat, ValueFormat.ALL_DEFAULT);
 }
Esempio n. 16
0
 public static bool WriteToFile(Node root, string path)
 {
     return WriteToFile(root, path, ValueFormat.NAME_DEFAULT);
 }