Exemplo n.º 1
0
 private void LoadMultiplicityValues()
 {
     fromMultiplicityComboBox.Items.AddRange(DSLUtil.GetMultiplicityTextValues().ToArray());
     toMultiplicityComboBox.Items.AddRange(DSLUtil.GetMultiplicityTextValues().ToArray());
     fromMultiplicityComboBox.SelectedItem = Multiplicity.One.ToText();
     toMultiplicityComboBox.SelectedItem   = Multiplicity.ZeroMany.ToText();
 }
        private LevelBlueprint ParseLevelFile(string input, bool sim)
        {
            input = ReplaceMagicConstantsInLevelFile(input);

            var includesFunc = DSLUtil.GetIncludesFunc(FilePath);

            return(DSLUtil.ParseLevelFromString(input, includesFunc, sim));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return a list of the values to display in the grid
        /// </summary>
        /// <param name="context"></param>
        /// <returns>A list of values the user can choose from</returns>
        public override StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
        {
            // Try to get a store from the current context
            // "context.Instance"  returns the element(s) that are currently selected i.e. whose values are being
            // shown in the property grid. Note that the user could have selected multiple objects, in which case
            //context.Instance will be an array.
            Store store = GetStore(context.Instance);

            List <string> values = (store != null) ? DSLUtil.GetClasses(store).ToList() : new List <string>();

            return(new StandardValuesCollection(values));
        }
Exemplo n.º 4
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.º 5
0
        private void LoadTypes()
        {
            IEnumerable <string> types = DSLUtil.GetClasses(_Store);

            fromEntityComboBox.Items.Add("Select Entity");
            fromEntityComboBox.Items.AddRange(types.OrderBy(t => t).ToArray());
            fromEntityComboBox.SelectedItem = "Select Entity";

            toEntityComboBox.Items.Add("Select Entity");
            toEntityComboBox.Items.AddRange(types.OrderBy(t => t).ToArray());
            toEntityComboBox.SelectedItem = "Select Entity";

            fromEntityComboBox.Focus();
        }
Exemplo n.º 6
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.º 7
0
        private Dictionary <Guid, LevelBlueprint> MapLevels(string path, Action <string> logwrite)
        {
            path = Path.GetDirectoryName(path);

            if (!Directory.Exists(path))
            {
                return(new Dictionary <Guid, LevelBlueprint>());
            }

            var d = new Dictionary <Guid, LevelBlueprint>();

            foreach (var f in Directory.EnumerateFiles(path).Where(p => p.ToLower().EndsWith(".gslevel")))
            {
                try
                {
                    var dat = File.ReadAllBytes(f);

                    Tuple <byte[], LevelBlueprint> cache;
                    if (_levelCache.TryGetValue(f, out cache))
                    {
                        if (cache.Item1.SequenceEqual(dat))
                        {
                            d[cache.Item2.UniqueID] = cache.Item2;
                            continue;
                        }
                    }

                    logwrite("Scan level: " + Path.GetFileName(f));
                    var lf = DSLUtil.ParseLevelFromFile(f, false);

                    d[lf.UniqueID] = lf;

                    _levelCache.AddOrUpdate(f, Tuple.Create(dat, lf), (a, b) => Tuple.Create(dat, lf));
                }
                catch (Exception)
                {
                    //
                }
            }
            return(d);
        }
Exemplo n.º 8
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (fromEntityComboBox.Text == "Select Entity" || toEntityComboBox.Text == "Select Entity")
            {
                MessageBox.Show("Select both entities involved in the association.");
                return;
            }

            //If both entities are the same, navigation properties need to be different
            if (fromEntityComboBox.Text == toEntityComboBox.Text)
            {
                if (fromNavigationPropertyNameTextBox.Text == toNavigationPropertyNameTextBox.Text)
                {
                    MessageBox.Show("The " + fromEntityComboBox.Text + " class cannot have two properties of the name "
                                    + fromNavigationPropertyNameTextBox.Text + ".");
                    return;
                }
            }

            //Many to many mapping column names have to be different
            if (fromMultiplicityComboBox.SelectedItem.ToString() == Multiplicity.ZeroMany.ToText() &&
                toMultiplicityComboBox.SelectedItem.ToString() == Multiplicity.ZeroMany.ToText())
            {
                if (manyToManyFromColumnTextBox.Text == manyToManyToColumnTextBox.Text)
                {
                    MessageBox.Show("Specify different names for columns in the Many-to-Many Map Table.");
                    return;
                }
            }

            var startClass = getClassFromStore(fromEntityComboBox.SelectedItem.ToString());
            var endClass   = getClassFromStore(toEntityComboBox.SelectedItem.ToString());

            var assoc = new Association(startClass, endClass);

            assoc.Name = associationNameTextBox.Text;

            assoc.End1Multiplicity       = DSLUtil.ToMultiplicity(fromMultiplicityComboBox.SelectedItem.ToString());
            assoc.End1RoleName           = fromEntityComboBox.SelectedItem.ToString();
            assoc.End1NavigationProperty = fromNavigationPropertyNameTextBox.Text;

            assoc.End2Multiplicity       = DSLUtil.ToMultiplicity(toMultiplicityComboBox.SelectedItem.ToString());
            assoc.End2RoleName           = toEntityComboBox.SelectedItem.ToString();
            assoc.End2NavigationProperty = toNavigationPropertyNameTextBox.Text;

            if (assoc.End1Multiplicity == Multiplicity.ZeroMany && assoc.End1Multiplicity == Multiplicity.ZeroMany)
            {
                Func <string, string> getNavigationPropertyName = colName => colName.ToLower().EndsWith("id") ? colName.Substring(0, colName.Length - 2) : colName;
                Func <string, string> getFieldName = colName => colName.ToLower().EndsWith("id") ? colName : colName + "Id";
                assoc.ManyToManyMappingTable = manyToManyTableTextBox.Text;

                assoc.End1ManyToManyMappingColumn      = manyToManyFromColumnTextBox.Text;
                assoc.End1ManyToManyFieldName          = getFieldName(manyToManyFromColumnTextBox.Text);
                assoc.End1ManyToManyNavigationProperty = getNavigationPropertyName(manyToManyFromColumnTextBox.Text);

                assoc.End2ManyToManyMappingColumn      = manyToManyToColumnTextBox.Text;
                assoc.End2ManyToManyFieldName          = getFieldName(manyToManyToColumnTextBox.Text);
                assoc.End2ManyToManyNavigationProperty = getNavigationPropertyName(manyToManyToColumnTextBox.Text);
            }

            startClass.NavigationProperties.Add(new NavigationProperty(_Store)
            {
                Name             = assoc.End1NavigationProperty,
                Association      = assoc.Name,
                Multiplicity     = assoc.End2Multiplicity,
                Type             = (assoc.End2Multiplicity == Multiplicity.ZeroMany) ? "ICollection<" + assoc.End2RoleName + ">" : assoc.End2RoleName,
                IsForeignkey     = fromFKeyCheckBox.Checked,
                ForeignkeyColumn = fromFKeyCheckBox.Checked ? fromNavigationPropertyNameTextBox.Text : string.Empty
            });

            endClass.NavigationProperties.Add(new NavigationProperty(_Store)
            {
                Name             = assoc.End2NavigationProperty,
                Association      = assoc.Name,
                Multiplicity     = assoc.End1Multiplicity,
                Type             = (assoc.End1Multiplicity == Multiplicity.ZeroMany) ? "ICollection<" + assoc.End1RoleName + ">" : assoc.End1RoleName,
                IsForeignkey     = toFKeyCheckBox.Checked,
                ForeignkeyColumn = toFKeyCheckBox.Checked ? toNavigationPropertyNameTextBox.Text : string.Empty
            });

            if (fromFKeyCheckBox.Checked)
            {
                startClass.Fields.Add(new ModelField(_Store)
                {
                    Name       = fromFKeyPropertyTextBox.Text,
                    ColumnName = fromNavigationPropertyNameTextBox.Text,
                    Type       = GetPrimaryKeyFieldType(startClass),
                    Getter     = AccessModifier.Public,
                    Setter     = AccessModifier.Public,
                    Nullable   = toMultiplicityComboBox.SelectedItem.ToString() != Multiplicity.One.ToText()
                });
            }

            if (toFKeyCheckBox.Checked)
            {
                endClass.Fields.Add(new ModelField(_Store)
                {
                    Name       = toFKeyPropertyTextBox.Text,
                    ColumnName = toNavigationPropertyNameTextBox.Text,
                    Type       = GetPrimaryKeyFieldType(startClass),
                    Getter     = AccessModifier.Public,
                    Setter     = AccessModifier.Public,
                    Nullable   = fromMultiplicityComboBox.SelectedItem.ToString() != Multiplicity.One.ToText()
                });
            }

            this.DialogResult = DialogResult.OK;
        }
 private LevelBlueprint ParseSpecificLevelFile(string f, bool sim)
 {
     return(DSLUtil.ParseLevelFromFile(f, sim));
 }
Exemplo n.º 10
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 });
                }
        }
Exemplo n.º 11
0
        private void UpdateSourceFiles()
        {
            if (!File.Exists(FilePath))
            {
                MessageBox.Show("No root folder"); return;
            }
            var folder = Path.GetDirectoryName(FilePath);

            if (!Directory.Exists(folder))
            {
                MessageBox.Show("No root folder"); return;
            }
            if (!folder.ToLower().Trim('\\').EndsWith("GridDominance.Shared\\Content\\levels".ToLower()))
            {
                MessageBox.Show("Invalid root folder"); return;
            }

            var files1 = Directory.EnumerateFiles(folder).Where(p => Path.GetExtension(p).ToLower() == ".gslevel").ToList();
            var files2 = Directory.EnumerateFiles(folder).Where(p => Path.GetExtension(p).ToLower() == ".gsgraph").ToList();
            var levels = files1.Select(f => ParseSpecificLevelFile(f, false)).OrderBy(p => p.UniqueID.ToString()).ToList();
            var worlds = files2.Select(f => DSLUtil.ParseGraphFromFile(f)).OrderBy(p => p.ID.ToString()).ToList();
            {
                var f0 = Path.Combine(folder, @"..\..\..\GridDominance.Shared\Content\Content.mgcb");

                if (File.Exists(f0))
                {
                    var txt0 = File.ReadAllText(f0);
                    foreach (var f in files1)
                    {
                        if (!txt0.Contains($"#begin levels/{Path.GetFileName(f)}"))
                        {
                            txt0 += $"#begin levels/{Path.GetFileName(f)}\r\n";
                            txt0 += $"/importer:GDLevelImporter\r\n";
                            txt0 += $"/processor:GDLevelProcessor\r\n";
                            txt0 += $"/build:levels/{Path.GetFileName(f)}\r\n";
                            txt0 += $"\r\n";
                        }
                    }
                    if (File.ReadAllText(f0) != txt0)
                    {
                        File.WriteAllText(f0, txt0);
                    }
                }
                else
                {
                    MessageBox.Show("FileNotFound: " + f0);
                }
            }

            {
                var f1 = Path.Combine(folder, @"..\..\Resources\Levels.cs");

                if (File.Exists(f1))
                {
                    var txt1 = File.ReadAllText(f1);
                    foreach (var loadstr in files1.Select(f => $"LoadLevel(content, \"levels/{Path.GetFileNameWithoutExtension(f)}\");"))
                    {
                        if (!txt1.Contains(loadstr))
                        {
                            txt1 = txt1.Replace("/* [MARK_LOAD_LEVEL] */", $"{loadstr}\r\n\t\t\t/* [MARK_LOAD_LEVEL] */");
                        }
                    }
                    if (File.ReadAllText(f1) != txt1)
                    {
                        File.WriteAllText(f1, txt1);
                    }
                }
                else
                {
                    MessageBox.Show("FileNotFound: " + f1);
                }
            }

            {
                var           f2   = Path.Combine(folder, @"..\..\..\GridDominance.Server\internals\config_levelids.php");
                StringBuilder txt2 = new StringBuilder();
                txt2.AppendLine("<?php");
                txt2.AppendLine();
                txt2.AppendLine("if(count(get_included_files()) ==1) exit(\"Direct access not permitted.\");");
                txt2.AppendLine();
                txt2.AppendLine("return [");

                txt2.AppendLine("\t[ '{d34db335-0001-4000-7711-000000100001}', '{b16b00b5-0001-4000-9999-000000000002}' ], // X-X      | Tutorial");

                foreach (var ww in worlds)
                {
                    txt2.AppendLine();
                    foreach (var nn in ww.LevelNodes)
                    {
                        var ll = levels.First(l => l.UniqueID == nn.LevelID);
                        txt2.AppendLine($"\t[ '{ww.ID:B}', '{ll.UniqueID:B}' ], // {ll.Name,-8} | {ll.FullName}");
                    }
                }

                txt2.AppendLine("];");

                if (File.Exists(f2))
                {
                    File.WriteAllText(f2, txt2.ToString());
                }
                else
                {
                    MessageBox.Show("FileNotFound: " + f2);
                }
            }
        }