コード例 #1
0
        /// <summary>
        /// If a CustomVariable has its SetByDerived to true, then any Elements that inherit from the Element
        /// that has this CustomVariable will also have CustomVariables with matching name that have their
        /// DefinedByBase set to true.  The variable with DefinedByBase often has incomplete information (like
        /// whether it is tunneling or not) so sometimes we need the defining variable for information like state types.
        /// </summary>
        /// <param name="customVariable">The variable to get the defining variable for.</param>
        /// <returns>The defining variable.  If an error occurs in finding base types, null is returned.</returns>
        public static CustomVariable GetDefiningCustomVariable(this CustomVariable customVariable)
        {
            if (customVariable == null)
            {
                throw new ArgumentNullException("customVariable");
            }
            if (!customVariable.DefinedByBase)
            {
                return(customVariable);
            }
            else
            {
                IElement container = ObjectFinder.Self.GetElementContaining(customVariable);

                if (container != null && !string.IsNullOrEmpty(container.BaseElement))
                {
                    IElement baseElement = GlueState.CurrentGlueProject.GetElement(container.BaseElement);
                    if (baseElement != null)
                    {
                        CustomVariable customVariableInBase = baseElement.GetCustomVariableRecursively(customVariable.Name);

                        if (customVariableInBase != null)
                        {
                            return(customVariableInBase.GetDefiningCustomVariable());
                        }
                    }
                }
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// If a CustomVariable has its SetByDerived to true, then any Elements that inherit from the Element
        /// that has this CustomVariable will also have CustomVariables with matching name that have their
        /// DefinedByBase set to true.  The variable with DefinedByBase often has incomplete information (like
        /// whether it is tunneling or not) so sometimes we need the defining variable for information like state types.
        /// </summary>
        /// <param name="customVariable">The variable to get the defining variable for.</param>
        /// <returns>The defining variable.  If an error occurs in finding base types, null is returned.</returns>
        public static CustomVariable GetDefiningCustomVariable(this CustomVariable customVariable)
        {
            if (!customVariable.DefinedByBase)
            {
                return(customVariable);
            }
            else
            {
                IElement container = ObjectFinder.Self.GetElementContaining(customVariable);

                if (container != null && !string.IsNullOrEmpty(container.BaseElement))
                {
                    IElement baseElement = ObjectFinder.Self.GetIElement(container.BaseElement);
                    if (baseElement != null)
                    {
                        CustomVariable customVariableInBase = baseElement.GetCustomVariableRecursively(customVariable.Name);

                        if (customVariableInBase != null)
                        {
                            return(customVariableInBase.GetDefiningCustomVariable());
                        }
                    }
                }
                return(null);
            }
        }
コード例 #3
0
        private static CustomVariable FillPossibleStatesFor(List<string> listToFill, IElement currentElement, CustomVariable customVariable)
        {

            IElement sourceElement = null;

            customVariable = customVariable.GetDefiningCustomVariable();

            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                NamedObjectSave namedObjectSave = currentElement.GetNamedObjectRecursively(customVariable.SourceObject);

                sourceElement = ObjectFinder.Self.GetEntitySave(namedObjectSave.SourceClassType);
                if (sourceElement == null)
                {
                    sourceElement = ObjectFinder.Self.GetScreenSave(namedObjectSave.SourceClassType);
                }
            }
            else
            {
                sourceElement = currentElement;
            }


            IEnumerable<StateSave> whatToLoopThrough = null;

            if (customVariable != null)
            {
                StateSaveCategory category = sourceElement.GetStateCategoryRecursively(customVariable.Type);

                if (category != null)
                {
                    whatToLoopThrough = category.States;
                }
            }

            listToFill.Add("<NONE>");

            if (whatToLoopThrough == null)
            {
                foreach (StateSave state in sourceElement.GetUncategorizedStatesRecursively())
                {
                    listToFill.Add(state.Name);

                }
                foreach (StateSaveCategory ssc in sourceElement.StateCategoryList)
                {
                    if (ssc.SharesVariablesWithOtherCategories == true)
                    {
                        foreach (StateSave stateInCategory in ssc.States)
                        {
                            listToFill.Add(stateInCategory.Name);

                        }
                    }
                }

            }
            else
            {
                // We are looping through a category
                foreach (StateSave stateSave in whatToLoopThrough)
                {
                    listToFill.Add(stateSave.Name);
                }
            }
            return customVariable;
        }
コード例 #4
0
        public static ICodeBlock AppendAssignmentForCustomVariableInElement(ICodeBlock codeBlock, CustomVariable customVariable, IElement saveObject)
        {
            bool hasBase = !string.IsNullOrEmpty(((INamedObjectContainer)saveObject).BaseObject);

            // Victor Chelaru
            // December 17, 2014
            // We used to not go into
            // this if statement if SetByDerived
            // was true, but actually since variables
            // are set bottom-up, there's really no reason
            // to set it only on the derived, because the base
            // will always get assigned first, then the derived
            // can override it.
            //if (!customVariable.SetByDerived && 
            if (customVariable.DefaultValue != null && // if it's null the user doesn't want to change what is set in the file or in the source object
                !customVariable.IsShared && // no need to handle statics here because they're always defined in class scope
                !IsVariableTunnelingToDisabledObject(customVariable, saveObject)
                )
            {


                string variableToAssign = "";

                CustomVariable variableConsideringDefinedByBase = customVariable.GetDefiningCustomVariable();

                IElement containerOfState = null;

                // This can be null
                // if the user takes
                // an Element that inherits
                // from another and has variables
                // from it, then changes the Element
                // to no longer inherit.

                if (variableConsideringDefinedByBase != null)
                {

                    containerOfState = BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(variableConsideringDefinedByBase, saveObject);

                    if (containerOfState == null)
                    {
                        variableToAssign =
                            CodeParser.ParseObjectValue(customVariable.DefaultValue);
                        NamedObjectSave namedObject = saveObject.GetNamedObject(customVariable.SourceObject);


                        if (customVariable.GetIsFile())
                        {
                            variableToAssign = variableToAssign.Replace("\"", "").Replace("-", "_");

                            if (variableToAssign == "<NONE>")
                            {
                                variableToAssign = "null";
                            }
                        }
                        else if (customVariable != null && customVariable.GetIsCsv())
                        {
                            if (ShouldAssignToCsv(customVariable, variableToAssign))
                            {
                                variableToAssign = GetAssignmentToCsvItem(customVariable, saveObject, variableToAssign);
                            }
                            else
                            {
                                variableToAssign = null;
                            }
                        }
                        else if (customVariable.Type == "Color")
                        {
                            variableToAssign = "Color." + variableToAssign.Replace("\"", "");

                        }
                        else if (customVariable.Type != "string" && variableToAssign == "\"\"")
                        {
                            variableToAssign = null;
                        }
                        else
                        {

                            //Not sure why this wasn't localizing variables but it caused a problem with 
                            //variables that tunnel in to a Text's DisplayText not being localized
                            //finish here

                            // Special Case:
                            // We don't want to
                            // set Visible on NOS's
                            // which are added/removed
                            // when Visible is set on them:
                            // Update March 7, 2014 
                            // We do want to set it because if we don't,
                            // then the checks inside the Visible property
                            // don't properly detect that they've been changed.
                            // Therefore, we're going to set it on the underlying
                            // object 
                            bool shouldSetUnderlyingValue = namedObject != null && namedObject.RemoveFromManagersWhenInvisible &&
                                customVariable.SourceObjectProperty == "Visible";

                            if (shouldSetUnderlyingValue)
                            {
                                // Don't change the variable to assign
                            }
                            else
                            {
                                variableToAssign = CodeWriter.MakeLocalizedIfNecessary(namedObject, customVariable.SourceObjectProperty,
                                    customVariable.DefaultValue, variableToAssign, null);
                                variableToAssign = variableToAssign.Replace("+", ".");
                            }
                        }
                    }
                    else
                    {
                        string valueAsString = (string)customVariable.DefaultValue;

                        if (!string.IsNullOrEmpty(valueAsString))
                        {
                            variableToAssign = StateCodeGenerator.FullyQualifyStateValue(containerOfState, (string)customVariable.DefaultValue, customVariable.Type);
                        }
                    }

                    if (!string.IsNullOrEmpty(variableToAssign))
                    {
                        string relativeVersionOfProperty = InstructionManager.GetRelativeForAbsolute(customVariable.Name);
                        if (!string.IsNullOrEmpty(relativeVersionOfProperty))
                        {
                            codeBlock = codeBlock.If("Parent == null");
                        }

                        NamedObjectSave namedObject = saveObject.GetNamedObject(customVariable.SourceObject);

                        bool shouldSetUnderlyingValue = namedObject != null && namedObject.RemoveFromManagersWhenInvisible &&
                            customVariable.SourceObjectProperty == "Visible";

                        if (namedObject != null)
                        {
                            NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, namedObject);
                        }

                        if (shouldSetUnderlyingValue)
                        {
                            codeBlock.Line(StringHelper.SpaceStrings(namedObject.InstanceName + "." + customVariable.SourceObjectProperty + " = ", variableToAssign + ";"));

                        }
                        else
                        {
                            codeBlock.Line(StringHelper.SpaceStrings(customVariable.Name, "=", variableToAssign + ";"));

                        }


                        if (!string.IsNullOrEmpty(relativeVersionOfProperty))
                        {
                            if (customVariable.Name == "Z")
                            {
                                codeBlock = codeBlock.End().ElseIf("Parent is FlatRedBall.Camera");
                                codeBlock.Line(relativeVersionOfProperty + " = " + variableToAssign + " - 40.0f;");
                            }
                            codeBlock = codeBlock.End().Else();
                            codeBlock.Line(relativeVersionOfProperty + " = " + variableToAssign + ";");
                            codeBlock = codeBlock.End();
                        }
                        

                        if (namedObject != null)
                        {
                            NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, namedObject);
                        }




                    }
                }
            }

            return codeBlock;
        }