Exemplo n.º 1
0
        /// <summary>
        /// Saves the current configuration to the field assembly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.PleaseWaitForm pleaseWait = new Forms.PleaseWaitForm("Saving config...");
            Enabled = false;
            pleaseWait.Show();

            try
            {
                if (Program.ASSEMBLY_DOCUMENT != null)
                {
                    Exporter.FieldProperties fieldProps = new Exporter.FieldProperties(FieldMetaForm.GetSpawnpoints(),
                                                                                       GetPropertySetsTabControl().TranslateToGamepieces());
                    List <PropertySet> propSets = GetPropertySetsTabControl().TranslateToPropertySets();
                    Exporter.SaveManager.Save(Program.ASSEMBLY_DOCUMENT, fieldProps, propSets);
                }

                Enabled = true;
                pleaseWait.Close();
            }
            catch (Exporter.FailedToSaveException er)
            {
                pleaseWait.Close();
                MessageBox.Show("Failed to save field configuration. The following error occurred:\n" + er.InnerException.ToString(), "Error", MessageBoxButtons.OK);
                Enabled = true;
            }
        }
Exemplo n.º 2
0
        public static void Save(AssemblyDocument document, FieldProperties fieldProps, List <PropertySet> propertySets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                SetProperty(p, "spawnpoints", JsonConvert.SerializeObject(fieldProps.spawnpoints));
                SetProperty(p, "gamepieces", JsonConvert.SerializeObject(fieldProps.gamepieces));

                // Property Sets
                SetProperty(p, "propertySets", JsonConvert.SerializeObject(propertySets, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                }));

                // Occurrences
                for (int i = 0; i < propertySets.Count; i++)
                {
                    var tabPage = (Components.ComponentPropertiesTabPage)Program.MAINWINDOW.GetPropertySetsTabControl().TabPages[propertySets[i].PropertySetID];

                    if (tabPage != null)
                    {
                        Components.InventorTreeView treeView = tabPage.ChildForm.inventorTreeView;
                        List <string> occurrences            = new List <string>();
                        foreach (TreeNode node in treeView.Nodes)
                        {
                            CreateOccurrenceList(node, "", occurrences);
                        }

                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", JsonConvert.SerializeObject(occurrences));
                    }
                    else
                    {
                        SetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]");
                    }
                }
            }
            catch (Exception e)
            {
                throw new FailedToSaveException(e);
            }
        }
Exemplo n.º 3
0
        public static void Load(AssemblyDocument document, out FieldProperties fieldProps, out List <PropertySet> propertySets, out Dictionary <string, List <string> > occurrencePropSets)
        {
            Inventor.PropertySets inventorPropertySets = document.PropertySets;

            try
            {
                Inventor.PropertySet p = GetPropertySet(inventorPropertySets, "synthesisField");

                // Field Properties
                BXDVector3[] spawnpoints = JsonConvert.DeserializeObject <BXDVector3[]>(GetProperty(p, "spawnpoints", "[]"));
                if (spawnpoints == null)
                {
                    spawnpoints = new BXDVector3[0];
                }

                Gamepiece[] gamepieces = JsonConvert.DeserializeObject <Gamepiece[]>(GetProperty(p, "gamepieces", "[]"));
                if (gamepieces == null)
                {
                    gamepieces = new Gamepiece[0];
                }

                fieldProps = new FieldProperties(spawnpoints, gamepieces);

                // Property Sets
                propertySets = JsonConvert.DeserializeObject <List <PropertySet> >(GetProperty(p, "propertySets", "[]"), new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });

                // Occurrences
                occurrencePropSets = new Dictionary <string, List <string> >();

                for (int i = 0; i < propertySets.Count(); i++)
                {
                    occurrencePropSets.Add(propertySets[i].PropertySetID,
                                           JsonConvert.DeserializeObject <List <string> >(GetProperty(p, "propertySets." + propertySets[i].PropertySetID + ".occurrences", "[]")));
                }
            }
            catch (Exception e)
            {
                throw new FailedToLoadException(e);
            }
        }