private LevelBlueprint ParseLevelFile(string input, bool sim)
        {
            input = ReplaceMagicConstantsInLevelFile(input);

            var includesFunc = DSLUtil.GetIncludesFunc(FilePath);

            return(DSLUtil.ParseLevelFromString(input, includesFunc, sim));
        }
Exemplo n.º 2
0
 private GraphBlueprint ParseGraphFileSafe(string input, string path)
 {
     try
     {
         var incf = DSLUtil.GetIncludesFunc(path);
         return(DSLUtil.ParseGraphFromString(input, incf));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        private ImageSource ReparseGraphFile(string input)
        {
            try
            {
                var sw = Stopwatch.StartNew();

                ClearLog();
                AddLog("Start parsing");

                var incf = DSLUtil.GetIncludesFunc(FilePath);
                var lp   = DSLUtil.ParseGraphFromString(input, incf);

                _currentDisplayGraph = lp;

                var img = ImageHelper.CreateImageSource(graphPainter.Draw(lp, FilePath, AddLog, last));

                AddLog("File parsed  in " + sw.ElapsedMilliseconds + "ms");

                if (lp != null)
                {
                    last = img.Item2;
                }

                return(img.Item1);
            }
            catch (ParsingException pe)
            {
                AddLog(pe.ToOutput());
                Console.Out.WriteLine(pe.ToString());
                _currentDisplayGraph = null;

                return(ImageHelper.CreateImageSource(graphPainter.Draw(null, null, AddLog, last)).Item1);
            }
            catch (Exception pe)
            {
                AddLog(pe.Message);
                Console.Out.WriteLine(pe.ToString());
                _currentDisplayGraph = null;

                return(ImageHelper.CreateImageSource(graphPainter.Draw(null, null, AddLog, last)).Item1);
            }
        }
Exemplo n.º 4
0
        private void CompileGraph()
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException(FilePath);
            }

            var incf = DSLUtil.GetIncludesFunc(FilePath);
            var lp   = DSLUtil.ParseGraphFromString(Code, incf);

            var dir  = Path.GetDirectoryName(FilePath);
            var name = Path.GetFileNameWithoutExtension(FilePath) + ".xnb";

            if (string.IsNullOrWhiteSpace(dir))
            {
                throw new Exception("dir == null");
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new Exception("name == null");
            }

            var outPath = Path.Combine(dir, name);

            byte[] binData;
            using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                    lp.BinarySerialize(bw);
                    binData = ms.ToArray();
                }

            using (var fs = new FileStream(outPath, FileMode.Create))
                using (var bw = new ExtendedBinaryWriter(fs))
                {
                    // Header

                    bw.Write('X');
                    bw.Write('N');
                    bw.Write('B');
                    bw.Write('g');                    // Target Platform
                    bw.Write((byte)5);                // XNB Version
                    bw.Write((byte)0);                // Flags


                    bw.Write((UInt32)0x95);

                    bw.Write((byte)0x01);
                    bw.Write("GridDominance.Graphfileformat.Pipeline.GDLevelReader, GridDominance.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 });

                    bw.Write(binData);

                    bw.Write(new byte[] { 0x58, 0x4E, 0x42, 0x67, 0x05, 0x00, 0x58, 0x4E, 0x42, 0x67, 0x05, 0x00 });
                    bw.Write(new byte[] { 0x9B, 0x00, 0x00, 0x00, 0x01 });

                    bw.Write("GridDominance.Graphfileformat.Pipeline.GDLevelReader, GridDominance.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 });
                    bw.Write(new byte[] { 0x58, 0x4E, 0x42, 0x67, 0x05, 0x00, 0x58, 0x4E, 0x42, 0x67, 0x05, 0x00 });
                    bw.Write(new byte[] { 0x58, 0x4E, 0x42, 0x67, 0x05, 0x00, 0xA1 });
                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x01 });

                    bw.Write("GridDominance.Graphfileformat.Pipeline.GDLevelReader, GridDominance.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");

                    bw.Write(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 });
                }
        }