Ejemplo n.º 1
0
        private AssetTypeInfo GetAtiFor(ElementSave element)
        {
            AssetTypeInfo newAti = FlatRedBall.IO.FileManager.CloneObject <AssetTypeInfo>(GraphicalUiElementAti);


            newAti.QualifiedRuntimeTypeName = new PlatformSpecificType()
            {
                QualifiedType = GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element)
            };

            if (element is ComponentSave)
            {
                newAti.Extension        = GumProjectSave.ComponentExtension;
                newAti.CustomLoadMethod = ComponentAti.CustomLoadMethod + " as " + GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element);
            }
            string unqualifiedName = element.Name + "Runtime";

            newAti.FriendlyName = unqualifiedName;

            newAti.FindByNameSyntax = "GetGraphicalUiElementByName(\"OBJECTNAME\") as " +
                                      newAti.QualifiedRuntimeTypeName.QualifiedType;

            if (newAti.ExtraVariablesPattern.EndsWith(";") == false)
            {
                newAti.ExtraVariablesPattern += ";";
            }

            newAti.ExtraVariablesPattern = "";

            // 9/24/2014
            // Jesse was getting
            // the plugin to crash
            // on this line of code
            // with a NullReferenceException.
            // I'm going to wrap this in if-s to be sure it's safe.
            if (element != null && element.DefaultState != null && element.DefaultState.Variables != null)
            {
                foreach (var variable in element.DefaultState.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName) || string.IsNullOrEmpty(item.SourceObject)))
                {
                    var variableDefinition = new VariableDefinition();
                    variableDefinition.Category     = variable.Category;
                    variableDefinition.DefaultValue = variable.Value?.ToString();
                    variableDefinition.Name         = variable.ExposedAsName ?? variable.Name;
                    variableDefinition.Type         = variable.Type;

                    newAti.VariableDefinitions.Add(variableDefinition);
                }
            }

            return(newAti);
        }
Ejemplo n.º 2
0
 public CodeGeneratorManager()
 {
     mGueDerivingClassCodeGenerator = new GueDerivingClassCodeGenerator();
     behaviorCodeGenerator          = new BehaviorCodeGenerator();
 }
        private AssetTypeInfo GetAtiFor(ElementSave element)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }


            AssetTypeInfo newAti = FlatRedBall.IO.FileManager.CloneObject <AssetTypeInfo>(GraphicalUiElementAti);

            newAti.AddToManagersFunc = GraphicalUiElementAti.AddToManagersFunc;

            newAti.QualifiedRuntimeTypeName = new PlatformSpecificType()
            {
                QualifiedType = GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element)
            };


            if (element is ComponentSave)
            {
                newAti.Extension        = GumProjectSave.ComponentExtension;
                newAti.CustomLoadMethod = ComponentAti.CustomLoadMethod + " as " + GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element);
            }
            string unqualifiedName = element.Name + "Runtime";

            newAti.FriendlyName    = unqualifiedName;
            newAti.ConstructorFunc = GetGumElementConstructorFunct;

            newAti.FindByNameSyntax = "GetGraphicalUiElementByName(\"OBJECTNAME\") as " +
                                      newAti.QualifiedRuntimeTypeName.QualifiedType;

            newAti.ExtraVariablesPattern = "";

            // 9/24/2014
            // Jesse was getting
            // the plugin to crash
            // on this line of code
            // with a NullReferenceException.
            // I'm going to wrap this in if-s to be sure it's safe.
            // 7/19/2018
            // Turns out this can crash if the lement's DefaultState is null
            // This happens if the backing file (like gutx) is not on disk.
            // Let's put a warning
            if (element != null && element.DefaultState == null)
            {
                GlueCommands.Self.PrintError("Could not find default state for Gum element " + element.Name + ". This can happen if the file is missing on disk");
            }

            if (element != null & element.DefaultState != null)
            {
                var states = new List <Gum.DataTypes.Variables.StateSave>();

                states.Add(element.DefaultState);

                var parentElement = Gum.Managers.ObjectFinder.Self.GetElementSave(element.BaseType);
                while (parentElement != null)
                {
                    states.Add(parentElement.DefaultState);
                    parentElement = Gum.Managers.ObjectFinder.Self.GetElementSave(parentElement.BaseType);
                }

                foreach (var state in states)
                {
                    var variablesForState = state.Variables.Where(item => !string.IsNullOrEmpty(item.ExposedAsName) || string.IsNullOrEmpty(item.SourceObject)).ToArray();

                    foreach (var variable in variablesForState)
                    {
                        string variableName = (variable.ExposedAsName ?? variable.Name).Replace(" ", "");

                        var hasAlreadyBeenAdded = newAti.VariableDefinitions.Any(item => item.Name == variableName);

                        if (!hasAlreadyBeenAdded)
                        {
                            var variableDefinition = new VariableDefinition();
                            variableDefinition.Category     = variable.Category;
                            variableDefinition.DefaultValue = variable.Value?.ToString();
                            variableDefinition.Name         = variableName; // gum variables can have spaces, but Glue variables can't

                            variableDefinition.Type = QualifyGumVariableType(variable, element);

                            ChangePositionUnitTypes(variableDefinition);

                            newAti.VariableDefinitions.Add(variableDefinition);
                        }
                    }
                }
            }

            return(newAti);
        }
        public bool HandleTryAddContainedObjects(string absoluteFile, List <string> availableObjects)
        {
            string extension = FileManager.GetExtension(absoluteFile);
            bool   toReturn  = extension == GumProjectSave.ComponentExtension ||
                               extension == GumProjectSave.ScreenExtension;

            // We don't want the "Entire File" option
            // Victor Chelaru Feb 24
            // Why not? This clears out
            // all entire objects! Like if
            // the user selects a .scnx file.
            // This is bad, so we should not clear
            // this unless the file is a .gumx or .gusx
            // or .gucx or .gutx
            // Update March 11, 2015
            // Actually we're no longer
            // going to use the weird "this"
            // syntax and instead just use the
            // entire file syntax.
            //if (extension == GumProjectSave.ScreenExtension ||
            //    extension == GumProjectSave.ComponentExtension ||
            //    extension == GumProjectSave.StandardExtension ||
            //    extension == GumProjectSave.ProjectExtension)
            //{
            //    availableObjects.Clear();
            //}
            // Update March 12, 2015
            // Actually we do want to clear everything if it's a .gucx, and only add the Entire File with the runtime type
            if (extension == GumProjectSave.ComponentExtension)
            {
                availableObjects.Clear();
            }

            if (toReturn)
            {
                ElementSave element = null;


                if (extension == GumProjectSave.ComponentExtension)
                {
                    element =
                        FileManager.XmlDeserialize <ComponentSave>(absoluteFile);
                }
                else
                {
                    element =
                        FileManager.XmlDeserialize <ScreenSave>(absoluteFile);
                }

                // Victor Chelaru, November 1, 2015
                // Initially I used a "this" syntax to
                // get access to the Screen casted as its
                // current type. But I didn't like the "this"
                // syntax, so I removed it to replace it with "Entire File".
                // Unfortunately, Entire File does a simple assignment, but screens
                // are loaded as IDB's, not as their runtime type. Maybe this should change
                // in the future (which would require their runtime types to inherit from IDBs),
                // but in the meantime, I'm going to revert back to using the "this" syntax so that
                // Screens can be casted appropriately:
                //availableObjects.Add("Entire File (" + element.Name + "Runtime" + ")");
                availableObjects.Add("this (" + GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(element) + ")");


                foreach (var instance in element.Instances)
                {
                    var elementSave = Gum.Managers.ObjectFinder.Self.GetElementSave(instance.BaseType);

                    string gueType = "";

                    if (GueDerivingClassCodeGenerator.Self.ShouldGenerateRuntimeFor(elementSave))
                    {
                        gueType = GueDerivingClassCodeGenerator.GetQualifiedRuntimeTypeFor(instance);
                    }
                    else
                    {
                        gueType = "Gum.Wireframe.GraphicalUiElement";
                    }
                    availableObjects.Add(instance.Name + " (" + gueType + ")");
                }
            }



            return(toReturn);
        }