Beispiel #1
0
        private void AddTopDownValues(string predefinedName)
        {
            var values = PredefinedTopDownValues.GetValues(predefinedName);

            string newItemName = predefinedName;

            while (ViewModel.TopDownValues.Any(item => item.Name == newItemName))
            {
                newItemName = FlatRedBall.Utilities.StringFunctions.IncrementNumberAtEnd(newItemName);
            }

            values.Name = newItemName;

            ViewModel.TopDownValues.Add(values);
        }
Beispiel #2
0
        private void HandleViewModelPropertyChange(object sender, PropertyChangedEventArgs e)
        {
            /////////// early out ///////////
            if (ignoresPropertyChanges)
            {
                return;
            }
            ///////////// end early out ///////////

            var  entity = GlueState.Self.CurrentEntitySave;
            var  viewModel = sender as TopDownEntityViewModel;
            bool shouldGenerateCsv, shouldGenerateEntity, shouldAddTopDownVariables;

            DetermineWhatToGenerate(e.PropertyName, viewModel,
                                    out shouldGenerateCsv, out shouldGenerateEntity, out shouldAddTopDownVariables);

            switch (e.PropertyName)
            {
            case nameof(TopDownEntityViewModel.IsTopDown):
                HandleIsTopDownPropertyChanged(viewModel);
                break;

            // already handled in a dedicated method
            case nameof(TopDownEntityViewModel.TopDownValues):
                RefreshAnimationValues(entity);
                break;
            }

            if (shouldGenerateCsv)
            {
                if (viewModel.IsTopDown && viewModel.TopDownValues.Count == 0)
                {
                    var newValues = PredefinedTopDownValues.GetValues("Default");
                    viewModel.TopDownValues.Add(newValues);
                }

                GenerateCsv(entity, viewModel);
            }

            if (shouldAddTopDownVariables)
            {
                AddTopDownGlueVariables(entity);
            }

            if (shouldGenerateEntity)
            {
                TaskManager.Self.AddSync(
                    () => GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(entity),
                    "Generating " + entity.Name);
            }

            if (shouldAddTopDownVariables)
            {
                TaskManager.Self.AddSync(() =>
                {
                    GlueCommands.Self.DoOnUiThread(() =>
                    {
                        GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();
                        GlueCommands.Self.RefreshCommands.RefreshUiForSelectedElement();
                    });
                }, "Refreshing UI after top down plugin values changed");
            }

            if (shouldGenerateCsv || shouldGenerateEntity || shouldAddTopDownVariables)
            {
                TaskManager.Self.AddAsyncTask(
                    () =>
                {
                    GlueCommands.Self.GluxCommands.SaveGlux();
                    EnumFileGenerator.Self.GenerateAndSave();
                    InterfacesFileGenerator.Self.GenerateAndSave();
                    if (shouldGenerateCsv || shouldAddTopDownVariables)
                    {
                        AiCodeGenerator.Self.GenerateAndSave();
                        AnimationCodeGenerator.Self.GenerateAndSave();
                    }
                }, "Saving Glue Project");
            }
        }