internal void Generate(FireMLRoot root)
        {
            this.root = root;
            this.counter = 1;
            root.NodeMap = new Dictionary<int, ASTNode>();

            if (root.MainPlot != null)
            {
                generate(root.MainPlot);
            }

            foreach (KeyValuePair<string, PlotDef> subPlot in root.SubPlotMap)
            {
                generate(subPlot.Value);
            }

            foreach (KeyValuePair<string, FunctionDef> funcDef in root.FuncDefMap)
            {
                generate(funcDef.Value);
            }

            foreach (KeyValuePair<string, ActionLayerDef> actionLayerDef in root.ActionLayerMap)
            {
                generate(actionLayerDef.Value);
            }

            foreach (KeyValuePair<string, AssetDef> assetDef in root.AssetMap)
            {
                generate(assetDef.Value);
            }
        }
Ejemplo n.º 2
0
 public ASTVisitor(RuntimeKernel kernel, FireMLRoot root)
 {
     this.kernel     = kernel;
     this.root       = root;
     exprProcessor   = new ExprProcessor(kernel);
     varRefProcessor = new StrVarRefProcessor(kernel);
 }
Ejemplo n.º 3
0
        internal void Generate(FireMLRoot root)
        {
            this.root    = root;
            this.counter = 1;
            root.NodeMap = new Dictionary <int, ASTNode>();

            if (root.MainPlot != null)
            {
                generate(root.MainPlot);
            }

            foreach (KeyValuePair <string, PlotDef> subPlot in root.SubPlotMap)
            {
                generate(subPlot.Value);
            }

            foreach (KeyValuePair <string, FunctionDef> funcDef in root.FuncDefMap)
            {
                generate(funcDef.Value);
            }

            foreach (KeyValuePair <string, ActionLayerDef> actionLayerDef in root.ActionLayerMap)
            {
                generate(actionLayerDef.Value);
            }

            foreach (KeyValuePair <string, AssetDef> assetDef in root.AssetMap)
            {
                generate(assetDef.Value);
            }
        }
 public ASTVisitor(RuntimeKernel kernel, FireMLRoot root)
 {
     this.kernel = kernel;
     this.root = root;
     exprProcessor = new ExprProcessor(kernel);
     varRefProcessor = new StrVarRefProcessor(kernel);
 }
 public override void Visit(FireMLRoot root, object[] args)
 {
     if (root.MainPlot == null)
     {
         kernel.IssueError(ErrorType.MainPlotNotExist, new Location(""));
     }
     base.Visit(root, args);
 }
Ejemplo n.º 6
0
 public override void Visit(FireMLRoot root, object[] args)
 {
     if (root.MainPlot == null)
     {
         kernel.IssueError(ErrorType.MainPlotNotExist, new Location(""));
     }
     base.Visit(root, args);
 }
Ejemplo n.º 7
0
 public override void Visit(FireMLRoot root, object[] args)
 {
     this.root = root;
     foreach (AssetDef asset in root.AssetMap.Values)
     {
         asset.Accept(this);
     }
     base.Visit(root, args);
 }
        public RuntimeKernel(IEngineFunctionCaller funcCaller, FireMLRoot fireMLRoot)
        {
            this.funcCaller = funcCaller;
            this.root = fireMLRoot;
            this.visitor = new ASTVisitor(this, root);
            this.runtimeData.InstructionStack.Push(InstructionStack.ROOT_FLAG);

            funcCaller.UserSelected += new SelectEventHandler(funcCaller_UserSelected);
        }
Ejemplo n.º 9
0
        public RuntimeKernel(IEngineFunctionCaller funcCaller, FireMLRoot fireMLRoot)
        {
            this.funcCaller = funcCaller;
            this.root       = fireMLRoot;
            this.visitor    = new ASTVisitor(this, root);
            this.runtimeData.InstructionStack.Push(InstructionStack.ROOT_FLAG);

            funcCaller.UserSelected += new SelectEventHandler(funcCaller_UserSelected);
        }
Ejemplo n.º 10
0
        public void Build(string[] plotFiles, FireMLRoot root)
        {
            foreach (string file in plotFiles)
            {
                this.file = file;
                xmlError  = false;
                //FINISH: 检查XML语法
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Schemas = kernel.FireMLSchemaSet;
                try
                {
                    xmlDoc.Load(file);
                }
                catch (Exception e)
                {
                    kernel.IssueError(ErrorType.ReadFileError, e.Message, new Location(file));
                    continue;
                }
                xmlDoc.Validate(new ValidationEventHandler(settings_ValidationEventHandler));
                if (xmlError)
                {
                    continue;
                }


                XmlTextReader reader;
                try
                {
                    reader = new XmlTextReader(file);
                }
                catch (Exception e)
                {
                    kernel.IssueError(ErrorType.ReadFileError, e.Message, new Location(file));
                    continue;
                }


                for (; reader.Name != "FireML"; reader.Read())
                {
                    ;
                }
                reader.MoveToContent();

                this.reader = reader;

                root.Accept(this);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            string          filepath   = args[0];
            FileStream      rootStream = new FileStream(filepath, FileMode.Open);
            BinaryFormatter bf         = new BinaryFormatter();
            FireMLRoot      root       = bf.Deserialize(rootStream) as FireMLRoot;

            FuncCaller    funcCaller = new FuncCaller();
            RuntimeKernel kernel     = new RuntimeKernel(funcCaller, root);

            do
            {
                kernel.Next();
                Console.ReadKey(true);
            } while (!funcCaller.IsEnd);
        }
        public void Visit(FireMLRoot root, object[] args)
        {
            bsonRoot = new BsonDocument();

            BsonDocument mainPlot = new BsonDocument();

            parentStack.Push(mainPlot);
            //MainPlot
            root.MainPlot.Accept(this);
            parentStack.Pop();
            bsonRoot.Add("mainPlot", mainPlot);

            /*
             * //SubPlot
             * BsonDocument subPlotMap = new BsonDocument();
             * foreach (KeyValuePair<string, PlotDef> plotDefEntry in root.SubPlotMap)
             * {
             *  BsonDocument subPlot = new BsonDocument();
             *
             *  parentStack.Push(subPlot);
             *  plotDefEntry.Value.Accept(this);
             *  parentStack.Pop();
             *
             *  subPlotMap.Add(plotDefEntry.Key, subPlot);
             * }
             * bsonRoot.Add("subPlotMap", subPlotMap);
             *
             * //FuncDef
             * BsonDocument funcDefMap = new BsonDocument();
             * foreach (KeyValuePair<string, FunctionDef> funcDefEntry in root.FuncDefMap)
             * {
             *  BsonDocument funcDef = new BsonDocument();
             *
             *  parentStack.Push(funcDef);
             *  funcDefEntry.Value.Accept(this);
             *  parentStack.Pop();
             *
             *  funcDefMap.Add(funcDefEntry.Key, funcDef);
             * }
             * bsonRoot.Add("funcDefMap", funcDefMap);
             */

            //ActionLayer
            //Asset

            //No need for NodeMap. Regenerate in runtime
        }
        public virtual void Visit(FireMLRoot root, object[] args)
        {
            if (root.MainPlot != null)
            {
                root.MainPlot.Accept(this);
            }

            foreach (KeyValuePair<string, PlotDef> subPlot in root.SubPlotMap)
            {
                subPlot.Value.Accept(this);
            }

            foreach (KeyValuePair<string, FunctionDef> funcDef in root.FuncDefMap)
            {
                funcDef.Value.Accept(this);
            }

            foreach (KeyValuePair<string, ActionLayerDef> actionLayerDef in root.ActionLayerMap)
            {
                actionLayerDef.Value.Accept(this);
            }
        }
Ejemplo n.º 14
0
        public virtual void Visit(FireMLRoot root, object[] args)
        {
            if (root.MainPlot != null)
            {
                root.MainPlot.Accept(this);
            }

            foreach (KeyValuePair <string, PlotDef> subPlot in root.SubPlotMap)
            {
                subPlot.Value.Accept(this);
            }

            foreach (KeyValuePair <string, FunctionDef> funcDef in root.FuncDefMap)
            {
                funcDef.Value.Accept(this);
            }

            foreach (KeyValuePair <string, ActionLayerDef> actionLayerDef in root.ActionLayerMap)
            {
                actionLayerDef.Value.Accept(this);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 编译FireML
        /// </summary>
        public FireMLRoot CompileFireML()
        {
            FireMLRoot root = new FireMLRoot();

            #region 读取Asset
            AssetBuilder assetBuilder = new AssetBuilder(this);
            assetBuilder.Build(assetFiles, root);
            #endregion

            #region 构造AST
            ASTBuilder astBuilder = new ASTBuilder(this);
            astBuilder.Build(plotFiles, root);
            #endregion

            #region AST合法性检查
            ASTChecker astChecker = new ASTChecker(this);
            astChecker.Check(root);
            #endregion

            #region 生成ID号
            IDGenerator idGenerator = new IDGenerator();
            idGenerator.Generate(root);
            #endregion

            #region 资源存在性检查
            //ContentChecker contentChecker = new ContentChecker(this);
            //contentChecker.Check(root);
            #endregion

            if (errorList.Count > 0)
            {
                return(null);
            }
            else
            {
                return(root);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args">
        /// XMLReader, filename
        /// </param>
        public void Visit(FireMLRoot root, object[] args)
        {
            //reader = args[0] as XmlTextReader;
            //file = args[1] as string;

            while (reader.Read())
            {
                reader.MoveToContent();
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    Location location = new Location(file, reader.LineNumber, reader.LinePosition);
                    switch (dic[reader.Name])
                    {
                    case "MainPlot":
                        if (root.MainPlot != null)
                        {
                            kernel.IssueError(ErrorType.DuplicatedMainPlot, location);
                            continue;
                        }

                        PlotDef plotDef = new PlotDef();
                        plotDef.Location = location;

                        root.MainPlot = plotDef;
                        //reader.MoveToContent();
                        plotDef.Accept(this);
                        break;

                    case "SubPlot":
                        reader.MoveToAttribute("name");
                        string subPlotName = reader.Value;
                        if (root.SubPlotMap.ContainsKey(subPlotName))
                        {
                            kernel.IssueError(ErrorType.DuplicatedSubPlot, subPlotName,
                                              new Location(file, reader.LineNumber, reader.LinePosition));
                            continue;
                        }

                        PlotDef subPlotDef = new PlotDef();
                        subPlotDef.Location = location;
                        subPlotDef.Name     = subPlotName;

                        root.SubPlotMap.Add(subPlotName, subPlotDef);
                        //reader.MoveToContent();
                        subPlotDef.Accept(this);
                        break;

                    case "ActionLayer":
                        reader.MoveToAttribute("name");
                        string layerName = reader.Value;
                        if (root.ActionLayerMap.ContainsKey(layerName))
                        {
                            kernel.IssueError(ErrorType.DuplicatedActorLayer, layerName,
                                              new Location(file, reader.LineNumber, reader.LinePosition));
                            continue;
                        }

                        ActionLayerDef actionLayerDef = new ActionLayerDef();
                        actionLayerDef.Location = location;
                        actionLayerDef.Name     = layerName;

                        root.ActionLayerMap.Add(layerName, actionLayerDef);
                        //reader.Read();
                        reader.MoveToElement();
                        actionLayerDef.Accept(this);
                        break;

                    case "Function":
                        reader.MoveToAttribute("name");
                        string funcName = reader.Value;
                        if (root.FuncDefMap.ContainsKey(funcName))
                        {
                            kernel.IssueError(ErrorType.DuplicatedFunction, funcName,
                                              new Location(file, reader.LineNumber, reader.LinePosition));
                            continue;
                        }

                        FunctionDef funcDef = new FunctionDef();
                        funcDef.Location = location;
                        funcDef.Name     = funcName;

                        root.FuncDefMap.Add(funcName, funcDef);
                        //reader.MoveToContent();
                        funcDef.Accept(this);
                        break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    reader.Read();
                    break;
                }
            }
        }
Ejemplo n.º 17
0
        public override TImport Import(string filename, ContentImporterContext context)
        {
            FileInfo      assemblyFileInfo = new FileInfo(filename);
            DirectoryInfo fireMLDirInfo    = assemblyFileInfo.Directory;
            DirectoryInfo contentDirInfo   = fireMLDirInfo.Parent;

            /*
             * DirectoryInfo plotDirInfo = new DirectoryInfo(fireMLDirInfo.FullName + "\\Plot");
             * if (!plotDirInfo.Exists)
             * {
             *  throw new InvalidContentException("剧情脚本文件夹Plot不存在!");
             * }
             *
             * List<string> plotFileList = new List<string>();
             * foreach (FileInfo plotFile in plotDirInfo.GetFiles("*.xml"))
             * {
             *  plotFileList.Add(plotFile.FullName);
             * }
             *
             * DirectoryInfo assetDirInfo = new DirectoryInfo(fireMLDirInfo.FullName + "\\Asset");
             * List<string> assetFileList = new List<string>();
             * if (assetDirInfo.Exists)
             * {
             *  foreach (FileInfo assetFile in assetDirInfo.GetFiles("*.xml"))
             *  {
             *      assetFileList.Add(assetFile.FullName);
             *  }
             * }*/

            List <string> plotFileList  = new List <string>();
            List <string> assetFileList = new List <string>();

            foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                string ext = fileInfo.Extension;
                if (ext == ".fmlplot")
                {
                    plotFileList.Add(fileInfo.FullName);
                }
                else if (ext == ".fmlasset")
                {
                    assetFileList.Add(fileInfo.FullName);
                }
            }

            string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD";

            CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath,
                                                       new FireEngine.XNAContent.ContentManager(contentDirInfo.FullName));

            FireMLRoot root = kernel.CompileFireML();

            Error[] errors = kernel.CheckPoint();

            if (errors.Length > 0)
            {
                StringBuilder msg = new StringBuilder();
                foreach (Error error in errors)
                {
                    msg.AppendLine(error.Message + "(" + error.Location.ToString() + ")");
                }

                ContentIdentity ci = new ContentIdentity(errors[0].Location.FileName);
                ci.FragmentIdentifier = errors[0].Location.Line + ", " + errors[0].Location.Column;

                throw new InvalidContentException(msg.ToString(), ci);
            }

            return(root);
        }
Ejemplo n.º 18
0
        /*
         #region IAssetVisitor Members
         *
         * public void Visit(ActorAsset actorAsset, object[] args)
         * {
         *  CheckContent(actorAsset.Source, ContentType.Texture, actorAsset.Location);
         * }
         *
         * public void Visit(CGAsset cgAsset, object[] args)
         * {
         *  CheckContent(cgAsset.Source, ContentType.Texture, cgAsset.Location);
         * }
         *
         * public void Visit(MusicAsset musicAsset, object[] args)
         * {
         *  CheckContent(musicAsset.Source, ContentType.Music, musicAsset.Location);
         * }
         *
         * public void Visit(VideoAsset videoAsset, object[] args)
         * {
         *  CheckContent(videoAsset.Source, ContentType.Video, videoAsset.Location);
         * }
         *
         #endregion
         */

        public void Check(FireMLRoot root)
        {
            root.Accept(this);
        }
Ejemplo n.º 19
0
 public void Visit(FireMLRoot root, object[] args)
 {
     root.MainPlot.Accept(this);
 }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            FileInfo assemblyFileInfo = new FileInfo(args[0]);
            string   savePath         = args[1];

            DirectoryInfo fireMLDirInfo  = assemblyFileInfo.Directory;
            DirectoryInfo contentDirInfo = fireMLDirInfo.Parent;

            List <string> plotFileList  = new List <string>();
            List <string> assetFileList = new List <string>();

            foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                string ext = fileInfo.Extension;
                if (ext == ".fmlplot")
                {
                    plotFileList.Add(fileInfo.FullName);
                }
                else if (ext == ".fmlasset")
                {
                    assetFileList.Add(fileInfo.FullName);
                }
            }

            string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD";

            //FireEngine.XNAContent.ContentManager contentManager = new FireEngine.XNAContent.ContentManager(contentDirInfo.FullName);
            CompilerKernel kernel = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, null /*contentManager*/);
            FireMLRoot     result = kernel.CompileFireML();

            Error[] errors = kernel.CheckPoint();

            foreach (Error e in errors)
            {
                Console.WriteLine("{0}\n{1},{2}\n{3}", e.Location.FileName, e.Location.Line, e.Location.Column, e.Message);
                Console.WriteLine();
            }

            if (errors.Length > 0)
            {
                Environment.Exit(-1);
                return;
            }

            Stream     bsonStream = new FileStream(savePath, FileMode.Create);
            BsonBuffer bsonBuffer = new BsonBuffer();
            BsonBinaryWriterSettings bsonSettings = new BsonBinaryWriterSettings();
            BsonBinaryWriter         bsonWriter   = new BsonBinaryWriter(bsonStream, bsonBuffer, bsonSettings);

            BsonSerializer.Serialize <FireMLRoot>(bsonWriter, result);
            bsonWriter.Close();

            JsonWriterSettings jsonSettings = new JsonWriterSettings();

            jsonSettings.NewLineChars = "\r\n";
            jsonSettings.OutputMode   = JsonOutputMode.JavaScript;
            jsonSettings.Indent       = true;
            jsonSettings.IndentChars  = "  ";
            StreamWriter streamWriter = new StreamWriter(new FileStream(savePath + ".json", FileMode.Create));
            JsonWriter   jsonWriter   = new JsonWriter(streamWriter, jsonSettings);

            BsonSerializer.Serialize <FireMLRoot>(jsonWriter, result);
            jsonWriter.Close();
        }
 public BsonExporterASTVisitor(FireMLRoot root)
 {
     parentStack = new Stack <BsonDocument>();
     fireMLRoot  = root;
     fireMLRoot.Accept(this);
 }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            /*
             * int plotNum = int.Parse(args[0]);
             * int assetNum = int.Parse(args[1]);
             * string contentPath = args[2];
             * const int BEGIN_ARG = 3;
             *
             * List<string> plotList = new List<string>();
             * List<string> assetList = new List<string>();
             * for (int i = BEGIN_ARG; i < BEGIN_ARG + plotNum; i++)
             * {
             *  plotList.Add(args[i]);
             * }
             * for (int i = BEGIN_ARG + plotNum; i < BEGIN_ARG + plotNum + assetNum; i++)
             * {
             *  assetList.Add(args[i]);
             * }*/

            FileInfo      assemblyFileInfo = new FileInfo(args[0]);
            DirectoryInfo fireMLDirInfo    = assemblyFileInfo.Directory;
            DirectoryInfo contentDirInfo   = fireMLDirInfo.Parent;

            List <string> plotFileList  = new List <string>();
            List <string> assetFileList = new List <string>();

            foreach (FileInfo fileInfo in fireMLDirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                string ext = fileInfo.Extension;
                if (ext == ".fmlplot")
                {
                    plotFileList.Add(fileInfo.FullName);
                }
                else if (ext == ".fmlasset")
                {
                    assetFileList.Add(fileInfo.FullName);
                }
            }

            string xsdDirPath = fireMLDirInfo.FullName + "\\" + "XSD";

            ContentManager contentManager = new ContentManager(contentDirInfo.FullName);
            CompilerKernel kernel         = new CompilerKernel(plotFileList.ToArray(), assetFileList.ToArray(), xsdDirPath, contentManager);
            FireMLRoot     result         = kernel.CompileFireML();

            Error[] errors = kernel.CheckPoint();

            foreach (Error e in errors)
            {
                Console.WriteLine("{0}\n{1},{2}\n{3}", e.Location.FileName, e.Location.Line, e.Location.Column, e.Message);
                Console.WriteLine();
            }

            if (errors.Length > 0)
            {
                Environment.Exit(-1);
                return;
            }

            BinaryFormatter bf          = new BinaryFormatter();
            FileStream      writeStream = new FileStream("compiled.bin", FileMode.Create);

            bf.Serialize(writeStream, result);
            writeStream.Close();

            Console.WriteLine("编译完成");

            FileStream readStream   = new FileStream("compiled.bin", FileMode.Open);
            FireMLRoot deserialized = bf.Deserialize(readStream) as FireMLRoot;
        }
        /*
        #region IAssetVisitor Members

        public void Visit(ActorAsset actorAsset, object[] args)
        {
            CheckContent(actorAsset.Source, ContentType.Texture, actorAsset.Location);
        }

        public void Visit(CGAsset cgAsset, object[] args)
        {
            CheckContent(cgAsset.Source, ContentType.Texture, cgAsset.Location);
        }

        public void Visit(MusicAsset musicAsset, object[] args)
        {
            CheckContent(musicAsset.Source, ContentType.Music, musicAsset.Location);
        }

        public void Visit(VideoAsset videoAsset, object[] args)
        {
            CheckContent(videoAsset.Source, ContentType.Video, videoAsset.Location);
        }

        #endregion
        */
        public void Check(FireMLRoot root)
        {
            root.Accept(this);
        }
        /// <summary>
        /// 编译FireML
        /// </summary>
        public FireMLRoot CompileFireML()
        {
            FireMLRoot root = new FireMLRoot();

            #region 读取Asset
            AssetBuilder assetBuilder = new AssetBuilder(this);
            assetBuilder.Build(assetFiles, root);
            #endregion

            #region 构造AST
            ASTBuilder astBuilder = new ASTBuilder(this);
            astBuilder.Build(plotFiles, root);
            #endregion

            #region AST合法性检查
            ASTChecker astChecker = new ASTChecker(this);
            astChecker.Check(root);
            #endregion

            #region 生成ID号
            IDGenerator idGenerator = new IDGenerator();
            idGenerator.Generate(root);
            #endregion

            #region 资源存在性检查
            //ContentChecker contentChecker = new ContentChecker(this);
            //contentChecker.Check(root);
            #endregion

            if (errorList.Count > 0)
                return null;
            else
                return root;
        }
 public void Check(FireMLRoot root)
 {
     this.root = root;
     root.Accept(this);
 }
Ejemplo n.º 26
0
        /*
         #region IAssetVisitor Members
         *
         * /// <summary>
         * ///
         * /// </summary>
         * /// <param name="actorAsset"></param>
         * /// <param name="args">XML Node</param>
         * public void Visit(ActorAsset actorAsset, object[] args)
         * {
         *  //FINISH: 检查资源存在性
         *  actorAsset.Source = currentNode.Attributes["src"].Value;
         *
         *  foreach (XmlNode child in currentNode.ChildNodes)
         *  {
         *      switch (dic[child.Name])
         *      {
         *          case "group":
         *              actorAsset.Group = child.InnerText;
         *              break;
         *
         *          default:
         *              continue;
         *      }
         *  }
         *
         *  if (assetMap.ContainsKey(actorAsset.Name))
         *  {
         *      kernel.IssueError(ErrorType.DuplicatedAsset, new Location(currentFile),
         *          actorAsset.Name, "Actor");
         *      return;
         *  }
         *
         *  assetMap.Add(actorAsset.Name, actorAsset);
         * }
         *
         * public void Visit(CGAsset cgAsset, object[] args)
         * {
         *  //FINISH: 检查资源存在性
         *  cgAsset.Source = currentNode.Attributes["src"].Value;
         *
         *  foreach (XmlNode child in currentNode.ChildNodes)
         *  {
         *      switch (dic[child.Name])
         *      {
         *          case "group":
         *              cgAsset.Group = child.InnerText;
         *              break;
         *
         *          default:
         *              continue;
         *      }
         *  }
         *
         *  if (assetMap.ContainsKey(cgAsset.Name))
         *  {
         *      kernel.IssueError(ErrorType.DuplicatedAsset, new Location(currentFile),
         *          cgAsset.Name, "CG");
         *      return;
         *  }
         *
         *  assetMap.Add(cgAsset.Name, cgAsset);
         * }
         *
         * public void Visit(MusicAsset musicAsset, object[] args)
         * {
         *  //TODO: 检查资源存在性
         *  musicAsset.Source = currentNode.Attributes["src"].Value;
         *
         *  foreach (XmlNode child in currentNode.ChildNodes)
         *  {
         *      switch (dic[child.Name])
         *      {
         *          case "group":
         *              musicAsset.Group = child.InnerText;
         *              break;
         *
         *          case "title":
         *              musicAsset.Title = child.InnerText;
         *              break;
         *
         *          case "artist":
         *              musicAsset.Artist = child.InnerText;
         *              break;
         *
         *          case "lyricsBy":
         *              musicAsset.LyricsBy = child.InnerText;
         *              break;
         *
         *          case "musicBy":
         *              musicAsset.MusicBy = child.InnerText;
         *              break;
         *
         *          case "description":
         *              musicAsset.Description = child.InnerText;
         *              break;
         *
         *          case "lyrics":
         *              musicAsset.Lyrics = child.InnerText;
         *              break;
         *
         *          case "lrc":
         *              musicAsset.LRC = child.InnerText;
         *              //TODO: 检查和解析LRC
         *              break;
         *
         *          default:
         *              continue;
         *      }
         *  }
         *
         *  if (assetMap.ContainsKey(musicAsset.Name))
         *  {
         *      kernel.IssueError(ErrorType.DuplicatedAsset, new Location(currentFile),
         *          musicAsset.Name, "Music");
         *      return;
         *  }
         *
         *  assetMap.Add(musicAsset.Name, musicAsset);
         * }
         *
         * public void Visit(VideoAsset videoAsset, object[] args)
         * {
         *  //TODO: 检查资源存在性
         *  videoAsset.Source = currentNode.Attributes["src"].Value;
         *
         *  if (assetMap.ContainsKey(videoAsset.Name))
         *  {
         *      kernel.IssueError(ErrorType.DuplicatedAsset, new Location(currentFile),
         *          videoAsset.Name, "Video");
         *      return;
         *  }
         *
         *  assetMap.Add(videoAsset.Name, videoAsset);
         * }
         *
         #endregion
         */

        public void Build(string[] assetFiles, FireMLRoot root)
        {
            assetMap = root.AssetMap;

            foreach (string file in assetFiles)
            {
                currentFile = file;
                xmlError    = false;

                XmlDocument doc = new XmlDocument();
                doc.Schemas = kernel.FireMLSchemaSet;
                try
                {
                    doc.Load(file);
                }
                catch (Exception e)
                {
                    kernel.IssueError(ErrorType.ReadFileError, new Location(file), e.Message);
                    continue;
                }
                doc.Validate(new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler));
                if (xmlError)
                {
                    continue;
                }

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                nsmgr.AddNamespace("fm", FireEngine.Library.FireEngineConstant.FIREML_XMLNS);

                foreach (XmlNode node in doc.SelectSingleNode("fm:FireMLAsset", nsmgr).ChildNodes)
                {
                    AssetDef      def = new AssetDef();
                    AssetDataBase data;

                    switch (dic[node.Name])
                    {
                    case "Actor":
                        data = FireMLDataBase.Deserialize <ActorAsset>(node.OuterXml);
                        break;

                    case "CG":
                        data = FireMLDataBase.Deserialize <CGAsset>(node.OuterXml);
                        break;

                    case "Music":
                        data = FireMLDataBase.Deserialize <MusicAsset>(node.OuterXml);
                        break;

                    case "Video":
                        data = FireMLDataBase.Deserialize <VideoAsset>(node.OuterXml);
                        break;

                    default:
                        continue;
                    }

                    string name = node.Attributes["Name"].Value;
                    def.Name      = name;
                    def.Location  = new Location(file);
                    def.AssetData = data;

                    if (assetMap.ContainsKey(name))
                    {
                        kernel.IssueError(ErrorType.DuplicatedAsset, new Location(currentFile),
                                          name, data.GetType().Name);
                    }
                    else
                    {
                        assetMap.Add(name, def);
                    }

                    currentNode = node;
                }
            }
        }
 public override void Visit(FireMLRoot root, object[] args)
 {
     this.root = root;
     foreach (AssetDef asset in root.AssetMap.Values)
     {
         asset.Accept(this);
     }
     base.Visit(root, args);
 }
Ejemplo n.º 28
0
 public BsonExporter(FireMLRoot root)
 {
     this.root = root;
 }
Ejemplo n.º 29
0
 public void Check(FireMLRoot root)
 {
     this.root = root;
     root.Accept(this);
 }
 public void Visit(FireMLRoot root, object[] args)
 {
     root.MainPlot.Accept(this);
 }