/// <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);
            }
        }
        private void CreateEntitySave()
        {
            mEntitySave = ExposedVariableTests.CreateEntitySaveWithStates("CustomVariableEntity");
            mExposedStateInCategoryVariable = new CustomVariable();
            mExposedStateInCategoryVariable.Name = "CurrentStateCategoryState";
            mExposedStateInCategoryVariable.Type = "StateCategory";
            mExposedStateInCategoryVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(mExposedStateInCategoryVariable);

            mSetByDerivedVariable = new CustomVariable();
            mSetByDerivedVariable.Type = "float";
            mSetByDerivedVariable.Name = "SomeVariable";
            mSetByDerivedVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(mSetByDerivedVariable);

            mTextInBase = new NamedObjectSave();
            mTextInBase.InstanceName = "TextObject";
            mTextInBase.SourceType = SourceType.FlatRedBallType;
            mTextInBase.SourceClassType = "Text";
            mEntitySave.NamedObjects.Add(mTextInBase);


            CustomVariable customVariable = new CustomVariable();
            customVariable.Name = "TunneledDisplayText";
            customVariable.SourceObject = mTextInBase.InstanceName;
            customVariable.SourceObjectProperty = "DisplayText";
            customVariable.Type = "string";
            customVariable.OverridingPropertyType = "int";
            mEntitySave.CustomVariables.Add(customVariable);


            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);
        }
示例#3
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);
            }
        }
示例#4
0
        public static void FixEnumerationTypes(this CustomVariable customVariable)
        {
            if (customVariable.GetIsEnumeration() && customVariable.DefaultValue != null && customVariable.DefaultValue.GetType() == typeof(int))
            {
                Type  runtimeType = customVariable.GetRuntimeType();
                Array array       = Enum.GetValues(runtimeType);
                int   valueAsInt  = (int)customVariable.DefaultValue;


                try
                {
                    string name = Enum.GetName(runtimeType, valueAsInt);

                    foreach (object enumValue in array)
                    {
                        if (name == enumValue.ToString())
                        {
                            customVariable.DefaultValue = enumValue;
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("Could not set the integer value" + valueAsInt + "to an enumeration of type " + runtimeType.FullName);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Returns the value of a variable either set in the NamedObjectSave (if it is set there) or in the underlying Entity if not
        /// </summary>
        /// <param name="instance">The NamedObjectSave to get the variable from.</param>
        /// <param name="variableName">The name of the variable, such as "ScaleX"</param>
        /// <returns>The value of the variable in either the NamedObjectSave or underlying Entity.  Returns null if varible isn't found.</returns>
        public static object GetEffectiveValue(this NamedObjectSave instance, string variableName)
        {
            CustomVariableInNamedObject cvino = instance.GetCustomVariable(variableName);

            if (cvino == null || cvino.Value == null)
            {
                if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                    if (entitySave != null)
                    {
                        CustomVariable variable = entitySave.GetCustomVariableRecursively(variableName);

                        if (variable != null)
                        {
                            return(variable.DefaultValue);
                        }
                    }
                }
            }
            else
            {
                return(cvino.Value);
            }
            return(null);
        }
        void OnPropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            string propertyName = e.ChangedItem.Label;

            CustomVariable customVariable = null;
            


            if (mCurrentNos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(mCurrentNos.SourceClassType))
            {
                IElement entitySave = ObjectFinder.Self.GetIElement(mCurrentNos.SourceClassType);
                customVariable = entitySave.GetCustomVariable(propertyName).Clone();
            }
            else
            {
                customVariable = new CustomVariable();
                customVariable.Name = propertyName;
            }
            customVariable.DefaultValue = e.ChangedItem.Value;

            customVariable.Type = mCurrentNos.GetCustomVariable(propertyName).Type;
            mCurrentElementRuntime.SetCustomVariable(customVariable);

            if (mRuntimeOptions.ShouldSave)
            {

                GlueViewCommands.Self.GlueProjectSaveCommands.SaveGlux();
            }
        }
        public void Initialize()
        {
            Container.Set(new StateSaveCategorySetVariableLogic());

            mEntitySave = new EntitySave();

            mCategory = new StateSaveCategory();
            mCategory.Name = "Category1";
            mCategory.SharesVariablesWithOtherCategories = true;
            mEntitySave.StateCategoryList.Add(mCategory);

            mCategory2 = new StateSaveCategory();
            mCategory2.Name = "Category2";
            mCategory2.SharesVariablesWithOtherCategories = true;
            mEntitySave.StateCategoryList.Add(mCategory);

            StateSave state1 = new StateSave();
            state1.Name = "State1";
            mCategory.States.Add(state1);

            StateSave stateInCategory2 = new StateSave();
            stateInCategory2.Name = "State1InCategory2";
            mCategory2.States.Add(stateInCategory2);


            mCustomVariable = new CustomVariable();
            mCustomVariable.Name = "CurrentState";
            mCustomVariable.Type = "VariableState";
            mCustomVariable.DefaultValue = "State1";
            mEntitySave.CustomVariables.Add(mCustomVariable);

             //need to test the case where a variable shouldn't be changed because it's not part of the category that got changed.
             //Also, need to handle a case where the variable becomes an uncategorized variable, but there alread is one...do we allow it?
        }
示例#8
0
        private void CreateContainerEntitySave()
        {
            mEntitySaveInstance = new NamedObjectSave();
            mEntitySaveInstance.InstanceName = "StateEntityInstance";
            mEntitySaveInstance.SourceType = SourceType.Entity;
            mEntitySaveInstance.SourceClassType = mEntitySave.Name;

            mDerivedSaveInstance = new NamedObjectSave();
            mDerivedSaveInstance.InstanceName = "StateDerivedEntityInstance";
            mDerivedSaveInstance.SourceType = SourceType.Entity;
            mDerivedSaveInstance.SourceClassType = mDerivedEntitySave.Name;

            mContainerEntitySave = new EntitySave();
            mContainerEntitySave.Name = "StateEntityContainer";

            mContainerEntitySave.NamedObjects.Add(mEntitySaveInstance);
            mContainerEntitySave.NamedObjects.Add(mDerivedSaveInstance);


            mTunneledUncategorizedStateInContainer = new CustomVariable();
            mTunneledUncategorizedStateInContainer.Name = "TunneledUncategorizedStateVariable";
            mTunneledUncategorizedStateInContainer.SourceObject = mEntitySaveInstance.InstanceName;
            mTunneledUncategorizedStateInContainer.SourceObjectProperty = mRenamedExposedUncategorizedStateVariable.Name;
            mContainerEntitySave.CustomVariables.Add(mTunneledUncategorizedStateInContainer);


            ObjectFinder.Self.GlueProject.Entities.Add(mContainerEntitySave);

            
        }
示例#9
0
        public static bool GetIsAnimationChain(this CustomVariable variable)
        {
            Type runtimeType = variable.GetRuntimeType();

            return(runtimeType != null &&
                   runtimeType == typeof(string) && variable.SourceObjectProperty == "CurrentChainName");
        }
示例#10
0
        public static CustomVariable GetCustomVariableRecursively(this IElement container, string variableName)
        {
            //////////////////////Early Out///////////////////////////////////
            if (string.IsNullOrEmpty(variableName))
            {
                return(null);
            }

            ////////////////////End Early Out//////////////////////////
            if (variableName.StartsWith("this."))
            {
                variableName = variableName.Substring("this.".Length);
            }
            CustomVariable foundVariable = container.GetCustomVariable(variableName);

            if (foundVariable != null)
            {
                return(foundVariable);
            }
            else
            {
                if (!string.IsNullOrEmpty(container.BaseObject))
                {
                    IElement element = GlueState.CurrentGlueProject.GetElement(container.BaseObject);

                    if (element != null)
                    {
                        foundVariable = GetCustomVariableRecursively(element, variableName);
                    }
                }

                return(foundVariable);
            }
        }
示例#11
0
        private void CreateEntitySaves()
        {
            mEntitySave = new EntitySave();
            mEntitySave.Name = "StateTestEntity";

            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            CreateNamedObjectWithSetVariable();

            CreateEntityVariables();

            CreateEntitySaveState();

            mContainer = new EntitySave();
            mContainer.Name = "StateTestContainerEntity";


            NamedObjectSave nos = new NamedObjectSave();
            nos.InstanceName = mEntitySave.Name + "Instance";
            nos.SourceType = SourceType.Entity;
            nos.SourceClassType = mEntitySave.Name;
            mContainer.NamedObjects.Add(nos);


            CustomVariable stateTunnel = new CustomVariable();
            stateTunnel.SourceObject = nos.InstanceName;
            stateTunnel.SourceObjectProperty = "CurrentState";
            stateTunnel.Type = "VariableState";
            stateTunnel.Name = "StateTunnelVariable";
            mContainer.CustomVariables.Add(stateTunnel);

            CreateContainerEntityState();

        }
示例#12
0
        public AvailableStates(NamedObjectSave currentNamedObject, IElement currentElement, CustomVariable currentCustomVariable, StateSave currentStateSave) : base()
        {
            CurrentNamedObject = currentNamedObject;
            CurrentElement = currentElement;
            CurrentCustomVariable = currentCustomVariable;
            CurrentStateSave = currentStateSave;

        }
示例#13
0
        public static void SetDefaultValueAccordingToType(this CustomVariable customVariable, string typeAsString)
        {
            Type type = TypeManager.GetTypeFromString(typeAsString);

            if (type == typeof(string))
            {
                customVariable.DefaultValue = "";
            }
            else if (type == null && customVariable.Type == "VariableState")
            {
                customVariable.DefaultValue = "";
            }
            // We used to check just Texture2D, but we want to check all file types since we're expanding that
            //else if (type == typeof(Microsoft.Xna.Framework.Graphics.Texture2D))
            else if (customVariable.GetIsFile())
            {
                customVariable.DefaultValue = "";
            }
            else if (type == typeof(Microsoft.Xna.Framework.Color))
            {
                customVariable.DefaultValue = "";
            }
            else if (type == typeof(byte))
            {
                customVariable.DefaultValue = (byte)0;
            }
            else if (type == typeof(short))
            {
                customVariable.DefaultValue = (short)0;
            }
            else if (type == typeof(int))
            {
                customVariable.DefaultValue = (int)0;
            }
            else if (type == typeof(long))
            {
                customVariable.DefaultValue = (long)0;
            }
            else if (type == typeof(char))
            {
                customVariable.DefaultValue = ' ';
            }
            else if (type == typeof(float))
            {
                customVariable.DefaultValue = 0.0f;
            }
            else if (type == typeof(double))
            {
                customVariable.DefaultValue = 0.0;
            }
            else
            {
                // This will be things like types defined in CSV values
                customVariable.DefaultValue = "";
            }

            customVariable.FixEnumerationTypes();
        }
示例#14
0
        public CustomVariable Clone()
        {
            CustomVariable newCustomVariable = this.MemberwiseClone() as CustomVariable;

            newCustomVariable.Properties = new List <PropertySave>();
            newCustomVariable.Properties.AddRange(this.Properties);

            return(newCustomVariable);
        }
        public AvailableAnimationChainsStringConverter(CustomVariable customVariable, StateSave stateSave = null)
        {
            IElement element = ObjectFinder.Self.GetVariableContainer(customVariable);

            NamedObjectSave referencedNos = element.GetNamedObjectRecursively(customVariable.SourceObject);

            Initialize(element, referencedNos, stateSave);

        }
        public static bool GetIsVariableState(this CustomVariable customVariable, IElement containingElement = null)
        {
            bool returnValue = false;

            if (customVariable != null && customVariable.DefinedByBase)
            {
                // If this is DefinedByBase, it may represent a variable that is tunneling, but it
                // doesn't know it - we have to get the variable from the base to know for sure.
                if (containingElement == null)
                {
                    containingElement = ObjectFinder.Self.GetElementContaining(customVariable);
                }
                if (containingElement != null && !string.IsNullOrEmpty(containingElement.BaseElement))
                {
                    IElement baseElement = ObjectFinder.Self.GetIElement(containingElement.BaseElement);
                    if (baseElement != null)
                    {
                        CustomVariable customVariableInBase = baseElement.GetCustomVariableRecursively(customVariable.Name);
                        if (customVariableInBase != null)
                        {
                            returnValue = customVariableInBase.GetIsVariableState();
                        }
                    }
                }
            }
            else
            {
                bool isTunneled = !string.IsNullOrEmpty(customVariable.SourceObject) &&
                                  !string.IsNullOrEmpty(customVariable.SourceObjectProperty);

                bool isOnThis = string.IsNullOrEmpty(customVariable.SourceObject) &&
                                string.IsNullOrEmpty(customVariable.SourceObjectProperty);


                if (isTunneled)
                {
                    string property = customVariable.SourceObjectProperty;
                    return(!string.IsNullOrEmpty(property) && property.StartsWith("Current") &&
                           property.EndsWith("State"));
                }
                else
                {
                    if (containingElement == null)
                    {
                        containingElement = ObjectFinder.Self.GetElementContaining(customVariable);
                    }

                    if (containingElement != null)
                    {
                        returnValue = customVariable.Type == "VariableState" ||
                                      containingElement.GetStateCategory(customVariable.Type) != null;
                    }
                }
            }
            return(returnValue);
        }
示例#17
0
        public static bool GetIsSourceFile(this CustomVariable customVariable, IElement container)
        {
            NamedObjectSave referencedNos = null;

            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                referencedNos = container.GetNamedObjectRecursively(customVariable.SourceObject);
            }

            return(referencedNos != null && customVariable.SourceObjectProperty == "SourceFile" && referencedNos.SourceType == SourceType.FlatRedBallType);
        }
示例#18
0
 public bool AssignsVariable(CustomVariable variable)
 {
     foreach (InstructionSave instructionSave in this.InstructionSaves)
     {
         if (instructionSave.Value != null && instructionSave.Member == variable.Name)
         {
             return(true);
         }
     }
     return(false);
 }
示例#19
0
 public bool AssignsVariable(CustomVariable variable)
 {
     foreach (InstructionSave instructionSave in this.InstructionSaves)
     {
         if (instructionSave.Value != null && instructionSave.Member == variable.Name)
         {
             return true;
         }
     }
     return false;
 }
示例#20
0
        public CustomVariable AddCustomVariable(string propertyType, string propertyName)
        {
            CustomVariable customVariable = new CustomVariable();

            customVariable.Type = propertyType;
            customVariable.Name = propertyName;

            CustomVariables.Add(customVariable);

            return(customVariable);
        }
        public void TestRelativeAbsoluteConversion()
        {
            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.UpdateCustomProperties();
            nos.InstanceName = "SpriteObject";
            nos.SetPropertyValue("ScaleX", 2.0f);
            nos.SetPropertyValue("X", 4.0f);
            nos.SetPropertyValue("RotationZ", 4.0f);
            nos.SetPropertyValue("RotationZVelocity", 4.0f);

            mEntitySave.NamedObjects.Add(nos);

            CustomVariable customVariable = new CustomVariable();
            customVariable.SourceObject = nos.InstanceName;
            customVariable.SourceObjectProperty = "ScaleY";
            customVariable.DefaultValue = 8.0f;

            mEntitySave.CustomVariables.Add(customVariable);

            ElementRuntime elementRuntime = new ElementRuntime(mEntitySave, null, null, null, null);

            Sprite sprite = elementRuntime.ContainedElements[0].DirectObjectReference as Sprite;
            sprite.ForceUpdateDependencies();

            if (elementRuntime.X != 0)
            {
                throw new Exception("NOS variables are being applied to the container instead of just to the NOS");
            }

            if (sprite.X != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting X on objects even though they're attached");
            }

            if (sprite.RotationZ != 4.0f)
            {
                throw new Exception("Absolute values should get set when setting RotationZ on objects even though they're attached");
            }
            if (sprite.RelativeRotationZVelocity != 4.0f)
            {
                throw new Exception("Setting RotationZVelocity should set RelativeRotationZVelocity");
            }
            if (sprite.ScaleX != 2.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
            if (sprite.ScaleY != 8.0f)
            {
                throw new Exception("Scale values aren't properly showing up on Sprites");
            }
        }
示例#22
0
 public void SetCustomVariable(string propertyName, object valueToSet)
 {
     for (int i = 0; i < CustomVariables.Count; i++)
     {
         if (CustomVariables[i].Name == propertyName)
         {
             CustomVariable cv = CustomVariables[i];
             cv.DefaultValue    = valueToSet;
             CustomVariables[i] = cv;
         }
     }
 }
        public void Initialize()
        {
            OverallInitializer.Initialize();

            ExposedVariableManager.Initialize();
            mEntitySave = CreateEntitySaveWithStates("ExposedVariableEntity");
            mEntitySave.ImplementsIVisible = true;
            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            mDerivedEntitySave.Name = "DerivedExposedVariableEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);

            mEntityWithCategorizedThatShareVariables = new EntitySave();
            mEntityWithCategorizedThatShareVariables.Name = "ExposedVariableTestEntityWithCategorizedThatShareVariables";
            ObjectFinder.Self.GlueProject.Entities.Add(mEntityWithCategorizedThatShareVariables);
            StateSaveCategory category = new StateSaveCategory();
            category.SharesVariablesWithOtherCategories = true; // this is important - it means that it won't make a new enum or property, so it is just the "CurrentState" variable
            category.Name = "Category1";
            mEntityWithCategorizedThatShareVariables.StateCategoryList.Add(category);
            StateSave stateSave = new StateSave();
            stateSave.Name = "CategorizedState1";
            category.States.Add(stateSave);

            mContainerBaseEntity = new EntitySave();
            mContainerBaseEntity.Name = "ExposedVariableTestContainerBaseEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(mContainerBaseEntity);
            NamedObjectSave namedObjectSave = new NamedObjectSave();
            namedObjectSave.InstanceName = mEntitySave.Name + "Instance";
            namedObjectSave.SourceType = SourceType.Entity;
            namedObjectSave.SourceClassType = mEntitySave.Name;
            mContainerBaseEntity.NamedObjects.Add(namedObjectSave);
            CustomVariable tunneledVariable = new CustomVariable();
            tunneledVariable.Name = "TunneledStateVariable";
            tunneledVariable.SourceObject = namedObjectSave.InstanceName;
            tunneledVariable.SourceObjectProperty = "Current" + mEntitySave.StateCategoryList[0].Name + "State";
            tunneledVariable.Type = mEntitySave.StateCategoryList[0].Name;
            tunneledVariable.SetByDerived = true;
            mContainerBaseEntity.CustomVariables.Add(tunneledVariable);

            mContainerDerivedEntity = new EntitySave();
            mContainerDerivedEntity.Name = "ExposedVariableTestContainerDerivedEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(mContainerDerivedEntity);
            mContainerDerivedEntity.BaseEntity = mContainerBaseEntity.Name;
            mContainerDerivedEntity.UpdateFromBaseType();
            mContainerDerivedEntity.GetCustomVariable(tunneledVariable.Name).DefaultValue = mEntitySave.StateCategoryList[0].States[0].Name;

            CreateCsvContainerEntitySave();
        }
示例#24
0
        public static bool GetIsObjectType(this CustomVariable customVariable)
        {
            string typeString = null;

            if (string.IsNullOrEmpty(customVariable.OverridingPropertyType))
            {
                typeString = customVariable.Type;
            }
            else
            {
                typeString = customVariable.OverridingPropertyType;
            }

            return(GetIsObjectType(typeString));
        }
示例#25
0
        public static string GetEntityNameDefiningThisTypeCategory(this CustomVariable customVariable)
        {
            if (customVariable.Type.StartsWith("Entities."))
            {
                var lastPeriod            = customVariable.Type.LastIndexOf('.');
                var entityNameWithPeriods = customVariable.Type.Substring(0, lastPeriod);
                var entityName            = entityNameWithPeriods.Replace('.', '\\');

                return(entityName);
            }
            else
            {
                return(null);
            }
        }
示例#26
0
        public static bool GetIsListCsv(this CustomVariable customVariable)
        {
            if (customVariable.GetIsCsv())
            {
                string             fullFileName = FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type;
                ReferencedFileSave foundRfs     = GlueCommands.FileCommands.GetReferencedFile(fullFileName);

                if (foundRfs != null)
                {
                    return(foundRfs.CreatesDictionary == false);
                }
            }

            return(false);
        }
示例#27
0
        public static bool GetIsExposingVariable(this CustomVariable customVariable, IElement container)
        {
            bool isExposedExistingMember = false;

            if (container is EntitySave)
            {
                isExposedExistingMember =
                    ExposedVariableManager.IsMemberDefinedByEntity(customVariable.Name, container as EntitySave);
            }
            else if (container is ScreenSave)
            {
                isExposedExistingMember = customVariable.Name == "CurrentState";
            }

            return(isExposedExistingMember);
        }
示例#28
0
 public static Type GetRuntimeType(this CustomVariable customVariable)
 {
     if (customVariable.GetIsVariableState())
     {
         return(null);
     }
     else if (string.IsNullOrEmpty(customVariable.OverridingPropertyType))
     {
         var type = TypeManager.GetTypeFromString(customVariable.Type);
         return(type);
     }
     else
     {
         return(TypeManager.GetTypeFromString(customVariable.OverridingPropertyType));
     }
 }
示例#29
0
        public static bool GetIsFile(this CustomVariable customVariable)
        {
            string typeString = null;

            if (string.IsNullOrEmpty(customVariable.OverridingPropertyType))
            {
                typeString = customVariable.Type;
            }
            else
            {
                typeString = customVariable.OverridingPropertyType;
            }

            // this can be expanded to support setting more file-based variables in Glue
            return(GetIsFile(typeString));
        }
示例#30
0
        public static bool HasAccompanyingVelocityConsideringTunneling(this CustomVariable variable, IElement container, int maxDepth = 0)
        {
            if (variable.HasAccompanyingVelocityProperty)
            {
                return(true);
            }
            else if (!string.IsNullOrEmpty(variable.SourceObject) && !string.IsNullOrEmpty(variable.SourceObjectProperty) && maxDepth > 0)
            {
                NamedObjectSave nos = container.GetNamedObjectRecursively(variable.SourceObject);

                if (nos != null)
                {
                    // If it's a FRB
                    if (nos.SourceType == SourceType.FlatRedBallType || nos.SourceType == SourceType.File)
                    {
                        return(!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty)));
                    }
                    else if (nos.SourceType == SourceType.Entity)
                    {
                        EntitySave entity = GlueState.CurrentGlueProject.GetEntitySave(nos.SourceClassType);

                        if (entity != null)
                        {
                            CustomVariable variableInEntity = entity.GetCustomVariable(variable.SourceObjectProperty);

                            if (variableInEntity != null)
                            {
                                if (!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variableInEntity.Name)))
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(variableInEntity.HasAccompanyingVelocityConsideringTunneling(entity, maxDepth - 1));
                                }
                            }
                            else
                            {
                                // There's no variable for this, so let's see if it's a variable that has velocity in FRB
                                return(!string.IsNullOrEmpty(InstructionManager.GetVelocityForState(variable.SourceObjectProperty)));
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#31
0
        public static bool GetIsEnumeration(this CustomVariable customVariable)
        {
            if (string.IsNullOrEmpty(customVariable.Type))
            {
                return(false);
            }

            Type type = TypeManager.GetTypeFromString(customVariable.Type);

            if (type == null)
            {
                return(false);
            }
            else
            {
                return(type.IsEnum);
            }
        }
示例#32
0
        private void CreateEntity()
        {
            mEntitySave = new EntitySave();
            mEntitySave.Name = "IVisibleTestEntity";
            mEntitySave.ImplementsIVisible = true;
            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            CustomVariable customVariable = new CustomVariable();
            customVariable.Name = "Visible";
            customVariable.Type = "bool";
            mEntitySave.CustomVariables.Add(customVariable);

            NamedObjectSave nos = new NamedObjectSave();
            nos.InstanceName = "SpriteObject";
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            mEntitySave.NamedObjects.Add(nos);

        }
示例#33
0
        public static string CustomVariableToString(CustomVariable cv)
        {
            IElement container     = ObjectFinder.Self.GetElementContaining(cv);
            string   containerName = " (Uncontained)";

            if (container != null)
            {
                containerName = " in " + container.ToString();
            }

            if (string.IsNullOrEmpty(cv.SourceObject))
            {
                return("" + cv.Type + " " + cv.Name + " = " + cv.DefaultValue + containerName);
            }
            else
            {
                return("" + cv.Type + " " + cv.SourceObject + "." + cv.Name + " = " + cv.DefaultValue + containerName);
            }
        }
示例#34
0
        public void TestStateVariables()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "CustomVariableTestStateVariableEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(entitySave);

            StateSaveCategory category1 = new StateSaveCategory();
            category1.Name = "Category1";
            category1.SharesVariablesWithOtherCategories = false;
            StateSave stateSave = new StateSave();
            stateSave.Name = "Disabled";
            category1.States.Add(stateSave);

            StateSaveCategory category2 = new StateSaveCategory();
            category2.Name = "Category2";
            category2.SharesVariablesWithOtherCategories = false;
            stateSave = new StateSave();
            stateSave.Name = "Disabled";
            category2.States.Add(stateSave);

            entitySave.StateCategoryList.Add(category1);
            entitySave.StateCategoryList.Add(category2);

            CustomVariable customVariable = new CustomVariable();
            customVariable.Type = "Category2";
            customVariable.DefaultValue = "Disabled";
            customVariable.Name = "CurrentCategory2State";
            entitySave.CustomVariables.Add(customVariable);

            

            ElementRuntime elementRuntime = new ElementRuntime(entitySave, null, null, null, null);

            StateSave foundStateSave = 
                elementRuntime.GetStateSaveFromCustomVariableValue(customVariable, customVariable.DefaultValue);

            if (foundStateSave != category2.States[0])
            {
                throw new Exception("States in categories are not being found properly when referenced through custom variables");
            }

        }
        private void CreateEntitySaves()
        {
            mEntitySave = new EntitySave();
            mEntitySave.Name = "NamedObjectSaveTestsEntity";
            mEntitySave.ImplementsIVisible = true;
            mEntitySave.ImplementsIWindow = true;

            CustomVariable customVariable = new CustomVariable();
            customVariable.Type = "float";
            customVariable.Name = "X";

            mEntitySave.CustomVariables.Add(customVariable);

            customVariable = new CustomVariable();
            customVariable.Type = "float";
            customVariable.Name = "Y";
            customVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(customVariable);

            StateSave stateSave = new StateSave();
            stateSave.Name = "TestState";
            mEntitySave.States.Add(stateSave);

            StateSaveCategory stateSaveCategory = new StateSaveCategory();
            stateSaveCategory.Name = "TestCategory";
            mEntitySave.StateCategoryList.Add(stateSaveCategory);

            StateSave categorizedState = new StateSave();
            categorizedState.Name = "CategorizedState";
            stateSaveCategory.States.Add(categorizedState);
            
            
            
            
            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);


            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            mDerivedEntitySave.Name = "NamedObjectSaveTestDerivedEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);
        }
示例#36
0
        private void CreateEntityVariables()
        {
            CustomVariable customVariable = new CustomVariable();
            customVariable.Name = "X";
            customVariable.Type = "float";
            mEntitySave.CustomVariables.Add(customVariable);

            customVariable = new CustomVariable();
            customVariable.Name = "CurrentState";
            customVariable.Type = "VariableState";
            customVariable.DefaultValue = "FirstState";
            mEntitySave.CustomVariables.Add(customVariable);

            customVariable = new CustomVariable();
            customVariable.Name = "SpriteScaleX";
            customVariable.Type = "float";
            customVariable.SourceObject = "SpriteObject";
            customVariable.SourceObjectProperty = "ScaleX";
            mEntitySave.CustomVariables.Add(customVariable);
        }
示例#37
0
        public static string Convert(CustomVariable customVariable, GetterOrSetter getterOrSetter, string value)
        {
            if (string.IsNullOrEmpty(customVariable.TypeConverter))
            {
                return value;
            }
            else
            {
                CustomTypeConverter converter = TypeConverters[customVariable.TypeConverter];

                if (getterOrSetter == GetterOrSetter.Getter)
                {
                    return converter.GetConversion(customVariable.Type, customVariable.OverridingPropertyType, value);
                }
                else
                {
                    return converter.GetConversion(customVariable.OverridingPropertyType, customVariable.Type, value);
                }
            }
        }
示例#38
0
        // I don't think we're going to use these anymore
        //public IElement GetElementContaining(NamedObjectPropertyOverride propertyOverride)
        //{

        //    foreach (EntitySave entitySave in Entities)
        //    {
        //        foreach (StateSave containedStateSave in entitySave.AllStates)
        //        {
        //            // I don't think we're going to use these anymore

        //            //if (containedStateSave.NamedObjectPropertyOverrides.Contains(propertyOverride))
        //            //{
        //            //    return entitySave;
        //            //}
        //        }

        //    }


        //    foreach (ScreenSave screenSave in Screens)
        //    {
        //        foreach (StateSave containedStateSave in screenSave.AllStates)
        //        {
        //            // I don't think we're going to use these anymore

        //            //if (containedStateSave.NamedObjectPropertyOverrides.Contains(propertyOverride))
        //            //{
        //            //    return screenSave;
        //            //}
        //        }
        //    }

        //    return null;


        //}

        public IElement GetElementContaining(CustomVariable customVariable)
        {
            foreach (EntitySave entitySave in Entities)
            {
                if (entitySave.CustomVariables.Contains(customVariable))
                {
                    return(entitySave);
                }
            }


            foreach (ScreenSave screenSave in Screens)
            {
                if (screenSave.CustomVariables.Contains(customVariable))
                {
                    return(screenSave);
                }
            }

            return(null);
        }
示例#39
0
 public static bool GetIsCsv(this CustomVariable customVariable)
 {
     if (customVariable.Type == null)
     {
         return(false);
     }
     if (customVariable.Type.EndsWith(".csv"))
     {
         return(true);
     }
     else if (customVariable.Type.EndsWith(".txt"))
     {
         //ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(customVariable.Type);
         throw new NotImplementedException("Need to implement checking if a custom variable is CSV from Text");
     }
     else if (GlueState.GetAllReferencedFiles().Any(item =>
                                                    item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type))
     {
         return(true);
     }
     return(false);
 }
示例#40
0
        private TreeNode FindCustomVariableInEntities(CustomVariable variable, TreeNodeCollection nodeCollection)
        {
            TreeNode foundNode = null;

            foreach (TreeNode treeNode in nodeCollection)
            {
                if (treeNode is EntityTreeNode)
                {
                    foundNode = ((EntityTreeNode)treeNode).GetTreeNodeFor(variable);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
                else
                {
                    foundNode = FindCustomVariableInEntities(variable, treeNode.Nodes);
                    if (foundNode != null)
                    {
                        break;
                    }
                }
            }
            return foundNode;
        }
示例#41
0
        public TreeNode CustomVariableTreeNode(CustomVariable variable)
        {
            TreeNode foundNode = null;

            foreach (ScreenTreeNode treeNode in ElementViewWindow.ScreensTreeNode.Nodes)
            {
                foundNode = treeNode.GetTreeNodeFor(variable);
                if (foundNode != null)
                {
                    return foundNode;
                }
            }

            TreeNodeCollection nodeCollection = ElementViewWindow.EntitiesTreeNode.Nodes;


            // This could contain directories


            foundNode = FindCustomVariableInEntities(variable, nodeCollection);

            return foundNode;

        }
        public static StateSave GetStateThatVariableBelongsTo(CustomVariable variable, IElement element)
        {
            // We only loop through categories, not uncategorized States because a variable can't belong to an uncategorized state.
            // See update below for-loop
            foreach (StateSaveCategory category in element.StateCategoryList)
            {
                if (!category.SharesVariablesWithOtherCategories)
                {
                    // This doesn't share variables, so it may own the variable
                    foreach (StateSave stateSave in category.States)
                    {
                        if (stateSave.AssignsVariable(variable))
                        {
                            return stateSave;
                        }
                    }
                }
            }

            // Update November 16, 2011
            // Yes variables can actually
            // belong to the no-category category
            foreach (StateSave stateSave in element.States)
            {
                if (stateSave.AssignsVariable(variable))
                {
                    return stateSave;
                }
            }

            return null;
        }
示例#43
0
        public static bool GetIsVariableState(this CustomVariable customVariable, IElement containingElement = null)
        {
            bool returnValue = false;

            if (customVariable != null && customVariable.DefinedByBase)
            {
                // If this is DefinedByBase, it may represent a variable that is tunneling, but it
                // doesn't know it - we have to get the variable from the base to know for sure.
                if (containingElement == null)
                {
                    containingElement = ObjectFinder.Self.GetElementContaining(customVariable);
                }
                if (containingElement != null && !string.IsNullOrEmpty(containingElement.BaseElement))
                {
                    IElement baseElement = GlueState.CurrentGlueProject.GetElement(containingElement.BaseElement);
                    if (baseElement != null)
                    {
                        CustomVariable customVariableInBase = baseElement.GetCustomVariableRecursively(customVariable.Name);
                        if (customVariableInBase != null)
                        {
                            returnValue = customVariableInBase.GetIsVariableState();
                        }
                    }
                }
            }
            else
            {
                bool isTunneled = !string.IsNullOrEmpty(customVariable.SourceObject) &&
                                  !string.IsNullOrEmpty(customVariable.SourceObjectProperty);

                bool isOnThis = string.IsNullOrEmpty(customVariable.SourceObject) &&
                                string.IsNullOrEmpty(customVariable.SourceObjectProperty);


                if (isTunneled)
                {
                    string property = customVariable.SourceObjectProperty;
                    return(!string.IsNullOrEmpty(property) && property.StartsWith("Current") &&
                           property.EndsWith("State"));
                }
                else
                {
                    if (containingElement == null)
                    {
                        containingElement = ObjectFinder.Self.GetElementContaining(customVariable);
                    }

                    if (containingElement != null)
                    {
                        returnValue = customVariable.Type == "VariableState" ||
                                      containingElement.GetStateCategory(customVariable.Type) != null;
                    }
                }
            }

            if (!returnValue && customVariable.Type.StartsWith("Entities."))
            {
                // It may still be a state, so let's see the entity:
                var entityName = customVariable.GetEntityNameDefiningThisTypeCategory();

                var entity = ObjectFinder.Self.GetEntitySave(entityName);

                if (entity != null)
                {
                    var lastPeriod    = customVariable.Type.LastIndexOf('.');
                    var startIndex    = lastPeriod + 1;
                    var stateCategory = customVariable.Type.Substring(startIndex);
                    var category      = entity.GetStateCategory(stateCategory);

                    if (category != null)
                    {
                        returnValue = true;
                    }
                }
            }

            return(returnValue);
        }
        private static void ReactToChangedHasAccompanyingVelocityProperty(CustomVariable customVariable)
        {
            if (customVariable.HasAccompanyingVelocityProperty)
            {
                // The user just
                // set this to true,
                // but we should check
                // if this is a good idea
                // or not - there may already
                // be a velocity variable for this.
                if (string.IsNullOrEmpty(customVariable.SourceObject))
                {
                    // todo:  fill this in
                }
                else
                {
                    // We want to set the accompanying to false before checking this, then back to true.
                    customVariable.HasAccompanyingVelocityProperty = false;
                    InterpolationCharacteristic characteristic =
                        CustomVariableHelper.GetInterpolationCharacteristic(customVariable, EditorLogic.CurrentElement);
                    customVariable.HasAccompanyingVelocityProperty = true;

                    if (characteristic == InterpolationCharacteristic.CantInterpolate)
                    {
                        MessageBox.Show("The variable " + customVariable.SourceObjectProperty + " cannot be interpolated.");
                        customVariable.HasAccompanyingVelocityProperty = false;
                    }
                    else if (characteristic == InterpolationCharacteristic.CanInterpolate)
                    {
                        string velocityMember =
                            FlatRedBall.Instructions.InstructionManager.GetVelocityForState(customVariable.SourceObjectProperty);
                        MessageBox.Show("The variable " + customVariable.SourceObjectProperty + " already has a built-in " +
                            "velocity member named " + velocityMember + "\n\nThere is no need to set an accompanying velocity property. " +
                            "Glue will undo this change now.");

                        customVariable.HasAccompanyingVelocityProperty = false;
                    }
                }

            }
        }
        private static void HandleIsSharedVariableSet(CustomVariable customVariable, object oldValue)
        {
            // July 11, 2011
            // We used to loop
            // through all derived
            // elements and set all
            // variables with the same
            // name to be IsShared as well,
            // however, this is bad because now
            // we discourage same-named variables
            // that are not SetByDerived. 
            //if (EditorLogic.CurrentEntitySave != null)
            //{
            //    List<EntitySave> derivedEntities = ObjectFinder.Self.GetAllEntitiesThatInheritFrom(
            //        EditorLogic.CurrentEntitySave.Name);
            //    foreach (EntitySave entity in derivedEntities)
            //    {
            //        foreach (CustomVariable cv in entity.CustomVariables)
            //        {
            //            if (cv.Name == customVariable.Name)
            //            {
            //                cv.IsShared = customVariable.IsShared;
            //            }
            //        }
            //    }
            //}
            bool didErrorOccur = false;
            if (customVariable.SetByDerived && customVariable.IsShared)
            {
                MessageBox.Show("Variables which are SetByDerived cannot be IsShared");
                didErrorOccur = true;
            }

            if (didErrorOccur)
            {
                customVariable.IsShared = (bool)oldValue;
            }

            if (!didErrorOccur)
            {

                if (customVariable.IsShared && customVariable.GetIsCsv())
                {
                    MessageBox.Show("Shared CSV variables are not assigned until either an instance of this object is created, or until LoadStaticContent is called.  Until then, the variable will equal null");

                }
            }
        }
        public static List <FlatRedBall.Instructions.Reflection.TypedMemberBase> GetTypedMembers(this EntitySave instance)
        {
            List <TypedMemberBase> typedMembers = new List <TypedMemberBase>();

            for (int i = 0; i < instance.CustomVariables.Count; i++)
            {
                CustomVariable customVariable = instance.CustomVariables[i];

                string type = customVariable.Type;

                if (!string.IsNullOrEmpty(customVariable.OverridingPropertyType))
                {
                    type = customVariable.OverridingPropertyType;
                }

                TypedMemberBase typedMemberBase =
                    AssetTypeInfoExtensionMethods.GetTypedMemberBase(
                        type,
                        customVariable.Name);

                typedMembers.Add(typedMemberBase);
            }

            // Add any variables that are set by container
            for (int i = 0; i < instance.NamedObjects.Count; i++)
            {
                NamedObjectSave nos = instance.NamedObjects[i];

                if (nos.SetByContainer && !string.IsNullOrEmpty(nos.InstanceType))
                {
                    if (nos.SourceType == SourceType.Entity)
                    {
                        TypedMemberBase typedMemberBase = TypedMemberBase.GetTypedMember(nos.InstanceName, typeof(string));
                        typedMembers.Add(typedMemberBase);
                    }
                    else
                    {
                        if (!nos.IsList)
                        {
                            TypedMemberBase typedMemberBase =
                                AssetTypeInfoExtensionMethods.GetTypedMemberBase(
                                    nos.InstanceType,
                                    nos.InstanceName);

                            typedMembers.Add(typedMemberBase);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(instance.BaseEntity))
            {
                EntitySave entitySave = ObjectFinder.Self.GetEntitySave(
                    instance.BaseEntity);

                // This may be null if the project improperly references
                // an EntitySave that really doesn't exist.
                if (entitySave != null)
                {
                    // We used to call "AddRange" but we don't want duplicates
                    // (I don't think) so we're going to use the custom extension
                    // method to prevent duplicates:
                    //typedMembers.AddRange(entitySave.GetTypedMembers());
                    typedMembers.AddRangeUnique(entitySave.GetTypedMembers());
                }
            }

            return(typedMembers);
        }
示例#47
0
        private static string GetLeftSideOfEquals(IElement element, CustomVariable customVariable, InstructionSave instruction, bool switchToRelative)
        {
            string leftSideOfEquals = instruction.Member;

            if (switchToRelative && customVariable != null)
            {
                string possibleLeftSide = RelativeValueForInstruction(instruction, customVariable, element);
                if (!string.IsNullOrEmpty(possibleLeftSide))
                {
                    
                    leftSideOfEquals = possibleLeftSide;
                    if (!string.IsNullOrEmpty(customVariable.SourceObject))
                    {
                        leftSideOfEquals = customVariable.SourceObject + "." + leftSideOfEquals;
                    }
                }
            }

            return leftSideOfEquals;
        }
 public TreeNode GetTreeNodeFor(CustomVariable variable)
 {
     foreach (TreeNode treeNode in this.mVariablesTreeNode.Nodes)
     {
         if (treeNode.Tag == variable)
         {
             return treeNode;
         }
     }
     return null;
 }
        //public abstract void GenerateCode();



        public static IElement GetElementIfCustomVariableIsVariableState(CustomVariable customVariable, IElement saveObject)
        {

            if (customVariable.GetIsVariableState() && string.IsNullOrEmpty(customVariable.SourceObject))
            {
                return saveObject;
            }
            else
            {

                NamedObjectSave sourceNamedObjectSave = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

                if (sourceNamedObjectSave != null)
                {
                    EntitySave sourceEntitySave = ObjectFinder.Self.GetEntitySave(sourceNamedObjectSave.SourceClassType);

                    if (sourceEntitySave != null &&
                        ((sourceEntitySave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState") ||
                        sourceEntitySave.StateCategoryList.ContainsCategoryName(customVariable.Type))
                        )
                    {
                        return sourceEntitySave;
                    }
                    else if (sourceEntitySave == null)
                    {
                        ScreenSave sourceScreenSave = ObjectFinder.Self.GetScreenSave(sourceNamedObjectSave.SourceClassType);

                        if (sourceScreenSave != null && sourceScreenSave.States.Count != 0 && customVariable.SourceObjectProperty == "CurrentState")
                        {
                            return sourceScreenSave;
                        }

                    }
                }
                return null;
            }
        }
示例#50
0
        public static void GetAdditionsNeededForChangingType(string oldType, string newType, List <PropertyValuePair> valuesToBeSet,
                                                             List <CustomVariable> neededVariables, List <StateSave> neededStates, List <StateSaveCategory> neededCategories)
        {
            IElement oldElement = ObjectFinder.Self.GetIElement(oldType);
            IElement newElement = ObjectFinder.Self.GetIElement(newType);

            if (oldElement != null && newElement != null)
            {
                #region Compare CustomVariables
                foreach (CustomVariable customVariable in oldElement.CustomVariables)
                {
                    string name = customVariable.Name;
                    string type = customVariable.Type;

                    // Is there a custom variable in the type to change to?
                    // We used to only call GetCustomVariable, but this needs
                    // to be recursive, because the object will get variables from
                    // the immediate type as well as all base types.
                    //CustomVariable customVariableInNewType = newElement.GetCustomVariable(name);
                    CustomVariable customVariableInNewType = newElement.GetCustomVariableRecursively(name);

                    if (customVariableInNewType == null || customVariableInNewType.Type != type)
                    {
                        neededVariables.Add(customVariable);
                    }
                }
                #endregion

                #region Compare interfaces like IClickable

                if (oldElement is EntitySave && newElement is EntitySave)
                {
                    EntitySave oldEntity = oldElement as EntitySave;
                    EntitySave newEntity = newElement as EntitySave;

                    if (oldEntity.GetImplementsIClickableRecursively() && !newEntity.GetImplementsIClickableRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIClickable", true));
                    }
                    if (oldEntity.GetImplementsIVisibleRecursively() && !newEntity.GetImplementsIVisibleRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIVisible", true));
                    }
                    if (oldEntity.GetImplementsIWindowRecursively() && !newEntity.GetImplementsIWindowRecursively())
                    {
                        valuesToBeSet.Add(new PropertyValuePair("ImplementsIWindow", true));
                    }
                }

                #endregion

                #region Compare States

                // Don't use AllStates because we want
                // states that belong to categories to be
                // identified as being in categories.
                foreach (StateSave state in oldElement.States)
                {
                    if (newElement.GetUncategorizedStateRecursively(state.Name) == null)
                    {
                        neededStates.Add(state);
                    }
                }

                #endregion

                #region Compare Categories

                foreach (StateSaveCategory category in oldElement.StateCategoryList)
                {
                    StateSaveCategory cloneOfCategory = null;
                    StateSaveCategory categoryInNew   = newElement.GetStateCategoryRecursively(category.Name);
                    if (categoryInNew == null)
                    {
                        cloneOfCategory = new StateSaveCategory {
                            Name = category.Name
                        };
                        neededCategories.Add(cloneOfCategory);
                    }

                    List <StateSave> statesMissingInNewCategory = new List <StateSave>();

                    foreach (StateSave state in category.States)
                    {
                        if (categoryInNew == null || categoryInNew.GetState(state.Name) == null)
                        {
                            if (cloneOfCategory == null)
                            {
                                cloneOfCategory = new StateSaveCategory {
                                    Name = category.Name
                                };
                            }
                            cloneOfCategory.States.Add(state);
                        }
                    }

                    if (cloneOfCategory != null)
                    {
                        neededCategories.Add(cloneOfCategory);
                    }
                }


                #endregion
            }
        }
示例#51
0
 public static bool GetIsTunneling(this CustomVariable customVariable)
 {
     return(!string.IsNullOrEmpty(customVariable.SourceObject) && !string.IsNullOrEmpty(customVariable.SourceObjectProperty));
 }
示例#52
0
        public static void UpdateCustomVariablesFromBaseType(IElement element)
        {
            IElement baseElement = null;

            if (element is ScreenSave)
            {
                baseElement = ObjectFinder.Self.GetScreenSave(element.BaseObject);
            }
            else
            {
                baseElement = ObjectFinder.Self.GetEntitySave(element.BaseObject);
            }



            List <CustomVariable> customVariablesBeforeUpdate = new List <CustomVariable>();

            for (int i = 0; i < element.CustomVariables.Count; i++)
            {
                if (element.CustomVariables[i].DefinedByBase)
                {
                    customVariablesBeforeUpdate.Add(element.CustomVariables[i]);
                }
            }

            List <CustomVariable> newCustomVariables = null;

            //EntitySave entity = ProjectManager.GetEntitySave(mBaseEntity);

            if (baseElement != null)
            {
                newCustomVariables = baseElement.GetCustomVariablesToBeSetByDerived();
            }
            else
            {
                newCustomVariables = new List <CustomVariable>();
            }

            // See if there are any objects to be removed.
            for (int i = customVariablesBeforeUpdate.Count - 1; i > -1; i--)
            {
                bool contains = false;

                for (int j = 0; j < newCustomVariables.Count; j++)
                {
                    if (customVariablesBeforeUpdate[i].Name == newCustomVariables[j].Name &&
                        customVariablesBeforeUpdate[i].DefinedByBase)
                    {
                        contains = true;
                        break;
                    }
                }

                if (!contains)
                {
                    // We got a NamedObject we should remove
                    element.CustomVariables.Remove(customVariablesBeforeUpdate[i]);
                    customVariablesBeforeUpdate.RemoveAt(i);
                }
            }

            // Next, see if there are any objects to be added
            for (int i = 0; i < newCustomVariables.Count; i++)
            {
                bool alreadyContainedAsDefinedByBase = false;
                for (int j = 0; j < customVariablesBeforeUpdate.Count; j++)
                {
                    if (customVariablesBeforeUpdate[j].Name == newCustomVariables[i].Name &&
                        customVariablesBeforeUpdate[j].DefinedByBase)
                    {
                        alreadyContainedAsDefinedByBase = true;
                    }
                }

                if (!alreadyContainedAsDefinedByBase)
                {
                    // There isn't a variable by this
                    // name that is already DefinedByBase,
                    // but there may still be a variable that
                    // is just a regular variable - and in that
                    // case we want to connect the existing variable
                    // with the variable in the base
                    CustomVariable existingInDerived = element.GetCustomVariable(newCustomVariables[i].Name);
                    if (existingInDerived != null)
                    {
                        existingInDerived.DefinedByBase = true;
                    }
                    else
                    {
                        CustomVariable customVariable = newCustomVariables[i].Clone();

                        // March 4, 2012
                        // We used to not
                        // change the SourceObject
                        // or the SourceObjectProperty
                        // values; however, this new variable
                        // should behave like an exposed variable,
                        // so it shouldn't have any SourceObject or
                        // SourceObjectProperty.  If it did, then it
                        // will access the base NamedObjectSave to set
                        // its property, and this could cause compilation
                        // errors if the NOS in the base is marked as private.
                        // It may also avoid raising events defined in the base.
                        customVariable.SourceObject         = null;
                        customVariable.SourceObjectProperty = null;

                        customVariable.DefinedByBase = true;
                        // We'll assume that this thing is going to be the acutal definition
                        customVariable.SetByDerived = false;

                        element.CustomVariables.Add(customVariable);
                    }
                }
            }
        }
示例#53
0
        private static string RelativeValueForInstruction(InstructionSave instruction, CustomVariable customVariable, IElement element)
        {
            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                string relativeMember = InstructionManager.GetRelativeForAbsolute(customVariable.SourceObjectProperty);

                return relativeMember;
            }
            else
            {

                string relativeMember = null;

                if (element is EntitySave)
                {
                    relativeMember = InstructionManager.GetRelativeForAbsolute(instruction.Member);
                }
                return relativeMember;
            }

        }
示例#54
0
        private static bool IsCustomVariableAssignedInAddToManagers(CustomVariable customVariable, IElement saveObject)
        {
            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                NamedObjectSave nos = saveObject.GetNamedObjectRecursively(customVariable.SourceObject);

                if (nos != null)
                {
                    AssetTypeInfo ati = nos.GetAssetTypeInfo();

                    if (ati != null && ati.IsInstantiatedInAddToManagers)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        private bool GetIfCanBeRenamed(CustomVariable customVariable)
        {
            if (customVariable.GetIsVariableState())
            {
                return false;
            }


            return true;
        }
示例#56
0
        public static string MakeLocalizedIfNecessary(NamedObjectSave namedObject, string variableName, object valueAsObject, string valueAsString, CustomVariable customVariable)
        {
            // This code will convert something like
            //      someVariable = "Hello";
            // to
            //      someVariable = LocalizationManager.Translate("Hello");

            // This code gets called on states.
            // If it's a state, then we find the 
            // custom variable that the state represents
            // and pass it as the last argument in the method.
            // We can look at that custom variable to see if it's
            // an AnimationChain

            if (ObjectFinder.Self.GlueProject != null && 
                ObjectFinder.Self.GlueProject.UsesTranslation && valueAsObject is string && (customVariable == null || customVariable.Type != "Color"))//&& !namedObject.IsAnimationChain)
            {
                if (customVariable != null && customVariable.GetIsAnimationChain())
                {
                    // do nothing
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.File)
                {
                    if (variableName != "CurrentChain" // CurrentChain is used by some FRB types
                        && variableName != "CurrentChainName" // and CurrentChainName is used by others....sucky.
                        )
                    {
                        valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                    }
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.Entity)
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(namedObject.SourceClassType);

                    if (entitySave != null)
                    {
                        CustomVariable variableInEntity = entitySave.GetCustomVariable(variableName);

                        if (variableInEntity == null || variableInEntity.GetIsAnimationChain() == false)
                        {
                            valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                        }
                    }
                }
                else if (namedObject != null && namedObject.SourceType == SourceType.FlatRedBallType)
                {
                    if (namedObject.SourceClassType == "Text" && variableName == "DisplayText")
                    {
                        valueAsString = "FlatRedBall.Localization.LocalizationManager.Translate(" + valueAsString + ")";
                    }
                }
            }
            return valueAsString;
        }
        internal void ReactToCustomVariableChangedValue(string changedMember, CustomVariable customVariable, object oldValue)
        {

            #region Name

            if (changedMember == "Name")
            {
                ReactToChangedCustomVariableName((string)oldValue, customVariable);
            }
            #endregion

            #region SetByDerived
            if (changedMember == "SetByDerived")
            {






                bool didErrorOccur = false;

                if (customVariable.SetByDerived && customVariable.IsShared)
                {
                    MessageBox.Show("Variables that are IsShared cannot be SetByDerived");
                    didErrorOccur = true;
                }

                if (didErrorOccur)
                {
                    customVariable.SetByDerived = (bool)oldValue;
                }
                else
                {
                    ProjectManager.UpdateAllDerivedElementFromBaseValues(false, true);
                }
            }
            #endregion

            #region IsShared

            else if (changedMember == "IsShared")
            {
                HandleIsSharedVariableSet(customVariable, oldValue);
            }
            #endregion

            #region SouceObjectProperty

            else if (changedMember == "SourceObjectProperty")
            {
                // See if there is already a NOS that uses this SourceObject/SourceObjectProperty combo
                IElement currentElement = EditorLogic.CurrentElement;
                CustomVariable currentVariable = customVariable;

                if (!string.IsNullOrEmpty(currentVariable.SourceObject) && !string.IsNullOrEmpty(currentVariable.SourceObjectProperty))
                {



                    foreach (CustomVariable variableInLoop in currentElement.CustomVariables)
                    {

                        if (variableInLoop != currentVariable &&
                            !string.IsNullOrEmpty(variableInLoop.SourceObject) && currentVariable.SourceObject == variableInLoop.SourceObject &&
                            !string.IsNullOrEmpty(variableInLoop.SourceObjectProperty) && currentVariable.SourceObjectProperty == variableInLoop.SourceObjectProperty)
                        {
                            MessageBox.Show("There is already a variable that is modifying " + currentVariable.SourceObjectProperty + " on " + currentVariable.SourceObject);

                            currentVariable.SourceObjectProperty = (string)oldValue;
                        }
                    }
                }
            }

            #endregion

            #region DefaultValue

            else if (changedMember == "DefaultValue")
            {
                customVariable.FixEnumerationTypes();

                if (!string.IsNullOrEmpty(customVariable.SourceObject))
                {
                    // See if the source NamedObjectSave has
                    // this variable exposed, and if so, set that 
                    // variable too so the two mirror each other...
                    // or make it null if this is a recasted variable.
                    NamedObjectSave nos = EditorLogic.CurrentElement.GetNamedObjectRecursively(customVariable.SourceObject);

                    if (nos != null)
                    {
                        CustomVariableInNamedObject cvino = nos.GetCustomVariable(customVariable.SourceObjectProperty);

                        // If the cvino is null, that means that the NOS doesn't have this exposed, so we don't
                        // need to do anything.
                        if (cvino != null)
                        {
                            if (string.IsNullOrEmpty(customVariable.OverridingPropertyType))
                            {
                                cvino.Value = customVariable.DefaultValue;
                            }
                            else
                            {
                                cvino.Value = null;
                            }
                        }

                    }
                }
            }

            #endregion

            #region HasAccompanyingVelocityProperty
            else if (changedMember == "HasAccompanyingVelocityProperty")
            {
                ReactToChangedHasAccompanyingVelocityProperty(customVariable);
            }
            #endregion

            #region OverridingPropertyType

            else if (changedMember == "OverridingPropertyType")
            {
                if (customVariable.OverridingPropertyType != null)
                {
                    customVariable.SetDefaultValueAccordingToType(customVariable.OverridingPropertyType);
                }
                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();
            }

            #endregion

            #region Type
            else if (changedMember == "Type")
            {
                customVariable.SetDefaultValueAccordingToType(customVariable.Type);
            }
            #endregion
        }
示例#58
0
        internal static bool IsVariableHandledByCustomCodeGenerator(CustomVariable customVariable, IElement element)
        {
            foreach (var codeGenerator in CodeGenerators)
            {
                if (codeGenerator.HandlesVariable(customVariable, element))
                {
                    return true;

                }
            }
            return false;
        }
        private static void ReactToChangedCustomVariableName(string oldName, CustomVariable customVariable)
        {
            string whyItIsntValid = "";
            bool isNameValid = NameVerifier.IsCustomVariableNameValid(customVariable.Name, customVariable, GlueState.Self.CurrentElement, ref whyItIsntValid);
            string newName = EditorLogic.CurrentCustomVariable.Name;

            if (customVariable.GetIsVariableState() && oldName != newName)
            {
                whyItIsntValid += "\nState variables cannot be renamed - they require specific names to function properly.";
            }

            if (!string.IsNullOrEmpty(whyItIsntValid))
            {
                MessageBox.Show(whyItIsntValid);
                customVariable.Name = oldName;
                // handle invalid names here
            }
            else
            {
                IElement element = EditorLogic.CurrentElement;

                List<IElement> elementsToGenerate = new List<IElement>();
                List<IElement> elementsToSearchForTunneledVariablesIn = new List<IElement>();

                #region Change any states that use this variable
                foreach (StateSave stateSave in element.AllStates)
                {
                    foreach (InstructionSave instructionSave in stateSave.InstructionSaves)
                    {
                        if (instructionSave.Member == oldName)
                        {
                            instructionSave.Member = newName;
                        }
                    }
                }

                #endregion

                #region Change any NOS that uses this as its source
                List<NamedObjectSave> nosList = ObjectFinder.Self.GetAllNamedObjectsThatUseElement(element);
                foreach (NamedObjectSave nos in nosList)
                {
                    IElement container = ObjectFinder.Self.GetElementContaining(nos);

                    if (!elementsToSearchForTunneledVariablesIn.Contains(container))
                    {
                        elementsToSearchForTunneledVariablesIn.Add(container);
                    }

                    if (nos.RenameVariable(oldName, newName))
                    {
                        if (!elementsToGenerate.Contains(container))
                        {
                            elementsToGenerate.Add(container);
                        }
                    }
                }

                #endregion

                #region Change any CustomVaribles that tunnel in to this variable
                foreach (IElement elementToCheck in elementsToSearchForTunneledVariablesIn)
                {
                    foreach (CustomVariable variableToCheck in elementToCheck.CustomVariables)
                    {
                        if (!string.IsNullOrEmpty(variableToCheck.SourceObject) && !string.IsNullOrEmpty(variableToCheck.SourceObjectProperty) &&
                            variableToCheck.SourceObjectProperty == oldName)
                        {
                            NamedObjectSave nos = elementToCheck.GetNamedObjectRecursively(variableToCheck.SourceObject);

                            // just to be safe
                            if (nos != null && nosList.Contains(nos))
                            {
                                variableToCheck.SourceObjectProperty = newName;

                                if (!elementsToGenerate.Contains(elementToCheck))
                                {
                                    elementsToGenerate.Add(elementToCheck);
                                }
                            }
                        }
                    }
                }

                #endregion

                #region Change all events that reference this variable

                foreach (var eventResponse in element.Events)
                {
                    if (eventResponse.SourceVariable == oldName)
                    {
                        eventResponse.SourceVariable = newName;
                        Plugins.PluginManager.ReceiveOutput("Changing event " + eventResponse.EventName + " to use variable " + newName);
                    }
                }

                #endregion

                foreach (IElement toRegenerate in elementsToGenerate)
                {
                    CodeWriter.GenerateCode(toRegenerate);

                }

            }
        }
示例#60
0
 public static bool GetIsNewVariable(this CustomVariable customVariable, IElement container)
 {
     return(customVariable.GetIsTunneling() == false && customVariable.GetIsExposingVariable(container) == false);
 }