Example #1
0
        public void Initialize()
        {
            OverallInitializer.Initialize();

            mBaseEntity = new EntitySave();
            mBaseEntity.Name = "BaseEntityInheritanceTests";
            ObjectFinder.Self.GlueProject.Entities.Add(mBaseEntity);

            NamedObjectSave nos = new NamedObjectSave();
            nos.InstanceName = "SpriteInstance";
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.SetByDerived = true;
            mBaseEntity.NamedObjects.Add(nos);

            nos = new NamedObjectSave();
            nos.InstanceName = "RectInstance";
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "AxisAlignedRectangle";
            nos.ExposedInDerived = true;
            mBaseEntity.NamedObjects.Add(nos);

            mDerivedEntity = new EntitySave();
            mDerivedEntity.Name = "DerivedentityInheritanceTests";
            mDerivedEntity.BaseEntity = mBaseEntity.Name;
            mDerivedEntity.UpdateFromBaseType();
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntity);

            mDerivedElementRuntime = new ElementRuntime(mDerivedEntity, null, null, null, null);
        }
Example #2
0
        public static void AddNamedObjectToCurrentNamedObjectList(NamedObjectSave namedObject)
        {
            namedObject.AddToManagers = true;

            NamedObjectSave parentNamedObject = EditorLogic.CurrentNamedObject;

            parentNamedObject.ContainedObjects.Add(namedObject);

            EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes();

            // Since it's part of a list we know its type
            string typeOfNewObject = parentNamedObject.SourceClassGenericType;

            if (ObjectFinder.Self.GetEntitySave(typeOfNewObject) != null)
            {
                namedObject.SourceType = SourceType.Entity;

                namedObject.SourceClassType = typeOfNewObject;
                namedObject.UpdateCustomProperties();
            }
            else if (AvailableClassTypeConverter.IsFlatRedBallType(typeOfNewObject))
            {
                namedObject.SourceType      = SourceType.FlatRedBallType;
                namedObject.SourceClassType = typeOfNewObject;
                namedObject.UpdateCustomProperties();
            }

            // Highlight the newly created object
            TreeNode newNode = GlueState.Self.Find.NamedObjectTreeNode(namedObject);

            if (newNode != null)
            {
                MainGlueWindow.Self.ElementTreeView.SelectedNode = newNode;
            }
        }
Example #3
0
        public static void FixEnumerationTypes(this NamedObjectSave instance)
        {
            foreach (CustomVariableInNamedObject instruction in instance.InstructionSaves)
            {
                if (!string.IsNullOrEmpty(instruction.Type))
                {
                    Type type = TypeManager.GetTypeFromString(instruction.Type);

                    if (type != null && instruction.Value != null && type.IsEnum && instruction.Value.GetType() == typeof(int))
                    {
                        Array array = Enum.GetValues(type);

                        // The enumerations may not necessarily be
                        // 0,1,2,3,4
                        // They may skip values or start at non-zero values.
                        // Therefore, we need to compare the int values
                        for (int i = 0; i < array.Length; i++)
                        {
                            if ((int)(array.GetValue(i)) == (int)instruction.Value)
                            {
                                instruction.Value = array.GetValue(i);
                                break;
                            }
                        }
                    }
                }
            }

            foreach (NamedObjectSave contained in instance.ContainedObjects)
            {
                contained.FixEnumerationTypes();
            }
        }
        public virtual void AddVariablesForAllProperties(object saveObject, NamedObjectSave toAddTo)
        {
            toAddTo.InstructionSaves.Clear();

            foreach (var field in saveObject.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                object currentValue = field.GetValue(saveObject);

                if (!MemberInvestigator.IsDefault(saveObject, field.Name, currentValue))
                {
                    string memberName = field.Name;

                    AddVariableToNos(toAddTo, memberName, currentValue);
                }
            }

            foreach (var property in saveObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                object currentValue = property.GetValue(saveObject, null);

                if (!MemberInvestigator.IsDefault(saveObject, property.Name, currentValue))
                {
                    string memberName = property.Name;

                    AddVariableToNos(toAddTo, memberName, currentValue);
                }
            }
        }
        private static void AssignTextureCoordinateValues(TextureCoordinateSelectionWindow selectionWindow, NamedObjectSave nos)
        {
            var texture = selectionWindow.CurrentTexture;
            var rectangle = selectionWindow.RectangleSelector;

            if (texture != null)
            {
                GlueCommands.Self.GluxCommands.SetVariableOn(
                    nos,
                    "LeftTexturePixel",
                    typeof(float),
                    rectangle.Left);

                GlueCommands.Self.GluxCommands.SetVariableOn(
                    nos,
                    "RightTexturePixel",
                    typeof(float),
                    rectangle.Right);

                GlueCommands.Self.GluxCommands.SetVariableOn(
                    nos,
                    "TopTexturePixel",
                    typeof(float),
                    rectangle.Top);

                GlueCommands.Self.GluxCommands.SetVariableOn(
                    nos,
                    "BottomTexturePixel",
                    typeof(float),
                    rectangle.Bottom);
            }
        }
        void AdjustNewNamedObject(NamedObjectSave nos)
        {
            IElement element = EditorLogic.CurrentElement;

            if (element != null)
            {
                if(nos.SourceType == SourceType.FlatRedBallType)
                {
                    switch (nos.SourceClassType)
                    {
                        case "Sprite":
                            AdjustSprite(nos, element);
                            break;
                        case "Circle":
                            AdjustCircle(nos, element);
                            break;
                        case "SpriteFrame":
                            AdjustSpriteFrame(nos, element);
                            break;
                        case "AxisAlignedRectangle":
                            AdjustAxisAlignedRectangle(nos, element);
                            break;
                        case "Layer":
                            AdjustLayer(nos, element);
                            break;


                    }

                }
            }

        }
 private void AdjustLayer(NamedObjectSave nos, IElement element)
 {
     if (Is2D(element))
     {
         nos.Is2D = true;
     }
 }
        public ScalableElementRuntime(IElement elementSave, Layer layerProvidedByContainer,
            NamedObjectSave namedObjectSave, EventHandler<VariableSetArgs> onBeforeVariableSet,
            EventHandler<VariableSetArgs> onAfterVariableSet)
            : base(elementSave, layerProvidedByContainer, namedObjectSave, onBeforeVariableSet, onAfterVariableSet)
        {

        }
Example #9
0
        public static InstructionSave SetPropertyValue(this NamedObjectSave instance, string propertyName, object valueToSet)
        {
            InstructionSave instruction = instance.GetInstructionFromMember(propertyName);

            if (instruction == null)
            {
                TypedMemberBase tmb = instance.TypedMembers.FirstOrDefault(member => member.MemberName == propertyName);

                if (tmb != null)
                {
                    instruction = instance.AddNewGenericInstructionFor(propertyName, tmb.MemberType);
                }
                else
                {
                    instruction = instance.AddNewGenericInstructionFor(propertyName, valueToSet.GetType());
                }

                if (tmb.CustomTypeName != null)
                {
                    instruction.Type = tmb.CustomTypeName;
                }
            }

            instruction.Value = valueToSet;
            return(instruction);
        }
Example #10
0
        public static bool CanBeInList(this NamedObjectSave instance, NamedObjectSave listNos)
        {
            if (listNos.SourceClassGenericType == instance.SourceClassType ||
                listNos.SourceClassGenericType == instance.InstanceType ||
                listNos.SourceClassGenericType == instance.GetAssetTypeInfo()?.QualifiedRuntimeTypeName.QualifiedType)
            {
                return(true);
            }

            if (instance.SourceType == SourceType.Entity)
            {
                EntitySave instanceElement = instance.GetReferencedElement() as EntitySave;

                IElement listElementType = ObjectFinder.Self.GetIElement(listNos.SourceClassGenericType);

                if (instanceElement == null || listElementType == null)
                {
                    return(false);
                }

                if (instanceElement.InheritsFrom(listNos.SourceClassGenericType))
                {
                    return(true);
                }
            }


            return(false);
        }
Example #11
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);
        }
Example #12
0
 public static bool IsGue(FlatRedBall.Glue.SaveClasses.NamedObjectSave item)
 {
     return(item.SourceType == FlatRedBall.Glue.SaveClasses.SourceType.File &&
            !string.IsNullOrEmpty(item.SourceFile) &&
            !string.IsNullOrEmpty(item.SourceName) &&
            (FileManager.GetExtension(item.SourceFile) == "gusx" || FileManager.GetExtension(item.SourceFile) == "gucx"));
 }
        private static void AddSetByDerivedNos(INamedObjectContainer namedObjectContainer,
                                               NamedObjectSave namedObjectSetByDerived, bool instantiatedByBase)
        {
            NamedObjectSave existingNamedObject = null;

            foreach (NamedObjectSave namedObjectInDerived in namedObjectContainer.NamedObjects)
            {
                if (namedObjectInDerived.InstanceName == namedObjectSetByDerived.InstanceName)
                {
                    existingNamedObject = namedObjectInDerived;
                    break;
                }
            }

            if (existingNamedObject != null)
            {
                existingNamedObject.DefinedByBase      = true;
                existingNamedObject.InstantiatedByBase = instantiatedByBase;
            }
            else
            {
                NamedObjectSave namedObjectSave = namedObjectSetByDerived.Clone();

                namedObjectSave.SetDefinedByBaseRecursively(true);
                namedObjectSave.SetInstantiatedByBaseRecursively(instantiatedByBase);

                // This can't be set by derived because an object it inherits from has that already set
                namedObjectSave.SetSetByDerivedRecursively(false);


                namedObjectContainer.NamedObjects.Add(namedObjectSave);
            }
        }
Example #14
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();

        }
        private static void TryToRemoveInvalidState(this GlueProjectSave glueProjectSave, bool showPopupsOnFixedErrors, IElement containingElement, NamedObjectSave nos)
        {
            if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType) && !string.IsNullOrEmpty(nos.CurrentState))
            {
                EntitySave foundEntitySave = glueProjectSave.GetEntitySave(nos.SourceClassType);

                if (foundEntitySave != null)
                {
                    bool hasFoundState = false;

                    hasFoundState = foundEntitySave.GetStateRecursively(nos.CurrentState) != null;

                    if (!hasFoundState)
                    {
                        if (showPopupsOnFixedErrors)
                        {
                            MessageBox.Show("The Object " + nos.InstanceName + " in " + containingElement.Name + " uses the invalid state " + nos.CurrentState +
                                "\nRemoving this current State");
                        }

                        nos.CurrentState = null;

                    }
                }
            }
        }
        private static void PerformStandardVariableAssignments(NamedObjectSave instance, TypedMemberBase typedMember, object value, DataGridItem instanceMember, Type memberType)
        {
            // If we ignore the next refresh, then AnimationChains won't update when the user
            // picks an AnimationChainList from a combo box:
            //RefreshLogic.IgnoreNextRefresh();
            GlueCommands.Self.GluxCommands.SetVariableOn(
                instance,
                typedMember.MemberName,
                memberType,
                value);


            GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

            // let's make the UI faster:

            // Get this on the UI thread, but use it in the async call below
            var currentElement = GlueState.Self.CurrentElement;

            TaskManager.Self.AddAsyncTask(() =>
            {
                GlueCommands.Self.GluxCommands.SaveGlux();

                GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(currentElement);
            },
            "Saving .glux and regenerating the code for the current element");
        }
 public static void GenerateTimedEmit(ICodeBlock codeBlock, NamedObjectSave nos)
 {
     if (!nos.IsDisabled && nos.AddToManagers && !nos.DefinedByBase && nos.IsEmitter())
     {
         codeBlock.Line(nos.InstanceName + ".TimedEmit();");
     }
 }
Example #18
0
        public static NamedObjectSave AddNewNamedObjectTo(string objectName, MembershipInfo membershipInfo,
                                                          IElement element, NamedObjectSave namedObjectSave, bool raisePluginResponse = true)
        {
            NamedObjectSave namedObject = new NamedObjectSave();

            namedObject.InstanceName = objectName;

            namedObject.DefinedByBase = membershipInfo == MembershipInfo.ContainedInBase;

            #region Adding to a NamedObject (PositionedObjectList)

            if (namedObjectSave != null)
            {
                AddNamedObjectToCurrentNamedObjectList(namedObject);
            }
            #endregion

            else if (element != null)
            {
                AddExistingNamedObjectToElement(element, namedObject, true);
            }


            if (raisePluginResponse)
            {
                PluginManager.ReactToNewObject(namedObject);
            }
            MainGlueWindow.Self.PropertyGrid.Refresh();
            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();

            return(namedObject);
        }
Example #19
0
        private static void RemoveNosFromElementIfNecessary(NamedObjectSave namedObject, out int wasRemovedFromIndex, out IElement element, out NamedObjectSave containingNos)
        {
            // We want to see if this name is already being used by other NOS's.
            // However, if this NOS is already part of the current element, then the
            // check for whether it's being used will always return true - because it's
            // being used by itself.  We don't want itself from returning the name as invalid
            // so we're going to remove it from the NOS list before running the check, then we'll
            // insert it back to the appropriate place.
            wasRemovedFromIndex = -1;
            element             = EditorLogic.CurrentElement;

            if (namedObject != null && element != null && element.NamedObjects.Contains(namedObject))
            {
                wasRemovedFromIndex = element.NamedObjects.IndexOf(namedObject);

                element.NamedObjects.Remove(namedObject);
            }
            containingNos = null;

            if (wasRemovedFromIndex == -1 && element != null)
            {
                foreach (NamedObjectSave containerNos in element.NamedObjects)
                {
                    if (containerNos.ContainedObjects.Contains(namedObject))
                    {
                        wasRemovedFromIndex = containerNos.ContainedObjects.IndexOf(namedObject);
                        containerNos.ContainedObjects.Remove(namedObject);
                        containingNos = containerNos;
                        break;
                    }
                }
            }
        }
        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);
        }
 protected virtual void AddVariableToNos(NamedObjectSave toReturn, string memberName, object currentValue)
 {
     CustomVariableInNamedObject cvino = new CustomVariableInNamedObject();
     cvino.Member = memberName;
     cvino.Value = currentValue;
     toReturn.InstructionSaves.Add(cvino);
 }
Example #22
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);

            
        }
Example #23
0
        internal static void AddExistingNamedObjectToElement(IElement element, NamedObjectSave newNamedObject, bool modifyNamedObject)
        {
            element.NamedObjects.Add(newNamedObject);
            GlueCommands.Self.RefreshCommands.RefreshUi(element);
            GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(element);

            GlueState.Self.CurrentNamedObjectSave = newNamedObject;
        }
Example #24
0
        public AvailableStates(NamedObjectSave currentNamedObject, IElement currentElement, CustomVariable currentCustomVariable, StateSave currentStateSave) : base()
        {
            CurrentNamedObject = currentNamedObject;
            CurrentElement = currentElement;
            CurrentCustomVariable = currentCustomVariable;
            CurrentStateSave = currentStateSave;

        }
        private void AdjustCircle(NamedObjectSave nos, IElement element)
        {
            if (Is2D(element))
            {

                nos.SetPropertyValue("Radius", 16f);
            }
        }
        protected override void AddVariableToNos(NamedObjectSave toReturn, string memberName, object currentValue)
        {
            if (memberName == "Texture" && !string.IsNullOrEmpty((string)currentValue))
            {
                currentValue = FileManager.RemoveExtension( FileManager.RemovePath(currentValue as string));
            }
            base.AddVariableToNos(toReturn, memberName, currentValue);

        }
        public static void ReactToValueSet(NamedObjectSave instance, TypedMemberBase typedMember, object value, DataGridItem instanceMember, Type memberType)
        {
            instanceMember.IsDefault = false;

            TryAdjustingValue(instance, typedMember, ref value, instanceMember);

            PerformStandardVariableAssignments(instance, typedMember, value, instanceMember, memberType);

        }
Example #28
0
        public static AssetTypeInfo GetAssetTypeInfo(this NamedObjectSave instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            if (string.IsNullOrEmpty(instance.ClassType))
            {
                return(null);
            }

            // If this NOS uses an EntireFile, then we should ask the file for its AssetTypeInfo,
            // as there may be multiple file types that produce the same class type.
            // For example
            AssetTypeInfo returnAti = null;

            if (instance.IsEntireFile)
            {
                var container = instance.GetContainer();

                var rfs = container?.GetReferencedFileSave(instance.SourceFile);

                if (rfs != null)
                {
                    var candidateAti = rfs.GetAssetTypeInfo();

                    // The user may use a file, but may change the runtime type through the
                    // SourceName property, so we need to make sure they match:
                    if (candidateAti != null && candidateAti.RuntimeTypeName == instance.ClassType)
                    {
                        returnAti = candidateAti;
                    }
                }
            }

            if (returnAti == null)
            {
                returnAti = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(instance.ClassType, instance, isObject: true);
            }

            if (instance.ClassType.StartsWith("PositionedObjectList<"))
            {
                return(null);
            }
            else
            {
                // Vic says: I don't think this should throw an exception anymore
                //if (returnAti == null)
                //{
                //    throw new InvalidOperationException("You probably need to add the class type " + this.ClassType +
                //        " to the ContentTypes.csv");
                //}

                return(returnAti);
            }
        }
Example #29
0
        public static string GetQualifiedClassType(this NamedObjectSave instance)
        {
            if (instance.SourceType == SourceType.FlatRedBallType && !string.IsNullOrEmpty(instance.InstanceType) &&
                instance.InstanceType.Contains("<T>"))
            {
                string genericType = instance.SourceClassGenericType;

                if (genericType == null)
                {
                    return(null);
                }
                else
                {
                    // For now we are going to try to qualify this by using the ATIs, but eventually we may want to change the source class generic type to be fully qualified
                    var ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(genericType, true);
                    if (ati != null)
                    {
                        genericType = ati.QualifiedRuntimeTypeName.QualifiedType;
                    }

                    string instanceType = instance.InstanceType;

                    if (instanceType == "List<T>")
                    {
                        instanceType = "System.Collections.Generic.List<T>";
                    }
                    else if (instanceType == "PositionedObjectList<T>")
                    {
                        instanceType = "FlatRedBall.Math.PositionedObjectList<T>";
                    }

                    if (genericType.StartsWith("Entities\\") || genericType.StartsWith("Entities/"))
                    {
                        genericType =
                            ProjectManager.ProjectNamespace + '.' + genericType.Replace('\\', '.');
                        return(instanceType.Replace("<T>", "<" + genericType + ">"));
                    }
                    else
                    {
                        if (genericType.Contains("\\"))
                        {
                            // The namespace is part of it, so let's remove it
                            int lastSlash = genericType.LastIndexOf('\\');
                            genericType = genericType.Substring(lastSlash + 1);
                        }


                        return(instanceType.Replace("<T>", "<" + genericType + ">"));
                    }
                }
            }
            else
            {
                return(instance.InstanceType);
            }
        }
Example #30
0
        public void CreateNamedObject(SourceType sourceType, string namedObjectType)
        {
            IElement element = GlueViewState.Self.CurrentElement;
            ///////////////////////Early Out//////////////////////
            if (element == null)
            {
                return;
            }
            /////////////////////End Early Out////////////////////

            //PositionedObject whatToAdd = null;

            NamedObjectSave newNos = new NamedObjectSave();
            newNos.SourceType = sourceType;
            newNos.SourceClassType = namedObjectType;

            if (newNos.SourceType == SourceType.FlatRedBallType)
            {
                newNos.InstanceName = namedObjectType;
            }
            else if (newNos.SourceType == SourceType.Entity)
            {
                newNos.InstanceName = FileManager.RemovePath(namedObjectType) + "Instance";
            }
            newNos.AddToManagers = true;
            newNos.AttachToContainer = true;
            newNos.CallActivity = true;

            StringFunctions.MakeNameUnique<NamedObjectSave>(newNos, element.NamedObjects);

            element.NamedObjects.Add(newNos);

            bool is2D = (element is EntitySave && ((EntitySave)element).Is2D) || SpriteManager.Camera.Orthogonal;

            //// This will need to change as the plugin grows in complexity
            if (namedObjectType == typeof(AxisAlignedRectangle).Name)
            {
                AddAxisAlignedRectangleValues(newNos, is2D);
            }
            else if (namedObjectType == typeof(Circle).Name)
            {
                AddCircleValues(newNos, is2D);
            }
            else if (namedObjectType == typeof(Sprite).Name)
            {
                AddSpriteValues(newNos, is2D);
            }
            else if (namedObjectType == typeof(Text).Name)
            {
                AddTextValues(newNos, is2D);
            }

            GlueViewCommands.Self.GlueProjectSaveCommands.SaveGlux();
            GlueViewCommands.Self.ElementCommands.ReloadCurrentElement();

        }
Example #31
0
        public static bool GetIsScalableEntity(this NamedObjectSave instance)
        {
            if (instance.SourceType == SourceType.Entity && !string.IsNullOrEmpty(instance.SourceClassType))
            {
                EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                return(entitySave.GetCustomVariableRecursively("ScaleX") != null && entitySave.GetCustomVariableRecursively("ScaleY") != null);
            }
            return(false);
        }
        private void AdjustSpriteFrame(NamedObjectSave nos, IElement element)
        {

            if (Is2D(element))
            {

                nos.SetPropertyValue("PixelSize", .5f);

            }
        }
Example #33
0
 public static void PostLoadLogic(this NamedObjectSave instance)
 {
     for (int i = instance.InstructionSaves.Count - 1; i > -1; i--)
     {
         if (instance.InstructionSaves[i].Value == null)
         {
             instance.InstructionSaves.RemoveAt(i);
         }
     }
 }
        internal void HandleCoordinateChanged(TextureCoordinateSelectionWindow selectionWindow, NamedObjectSave nos)
        {
            AssignTextureCoordinateValues(selectionWindow, nos);

            GlueCommands.Self.GluxCommands.SaveGlux();

            GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();

            GlueCommands.Self.GenerateCodeCommands.GenerateCurrentElementCode();
        }
        private void CreateButtonList()
        {
            mButtonList = new EntitySave();
            mButtonList.Name = "ButtonListInCodeGenerationTests";
            ObjectFinder.Self.GlueProject.Entities.Add(mButtonList);

            mButtonInButtonList = new NamedObjectSave();
            mButtonInButtonList.SourceType = SourceType.Entity;
            mButtonInButtonList.SourceClassType = mButton.Name;
            mButtonList.NamedObjects.Add(mButtonInButtonList);
        }
Example #36
0
 public static IElement GetReferencedElement(this NamedObjectSave instance)
 {
     if (string.IsNullOrEmpty(instance.SourceClassType))
     {
         return(null);
     }
     else
     {
         return(ObjectFinder.Self.GetEntitySave(instance.SourceClassType));
     }
 }
Example #37
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);
        }
Example #38
0
        public void TestLayerOrthoValues()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "LayerTestTestLayerOrthoValuesEntity";

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Layer";
            nos.InstanceName = "Layer1";
            nos.IndependentOfCamera = true;
            nos.Is2D = true;
            nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel;
            nos.LayerCoordinateType = LayerCoordinateType.MatchCamera;
            entitySave.NamedObjects.Add(nos);

            nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Layer";
            nos.InstanceName = "Layer2";
            nos.IndependentOfCamera = true;
            nos.Is2D = true;
            nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel;
            nos.LayerCoordinateType = LayerCoordinateType.MatchCamera;
            nos.DestinationRectangle = new FloatRectangle(0, 0, 80, 64);
            entitySave.NamedObjects.Add(nos);

            SpriteManager.Camera.Orthogonal = true;
            SpriteManager.Camera.OrthogonalWidth = 800;
            SpriteManager.Camera.OrthogonalHeight = 640;


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

            Layer layer = (elementRuntime.ContainedElements[0].DirectObjectReference as Layer);

            if (layer.LayerCameraSettings.OrthogonalWidth != 800 ||
                layer.LayerCameraSettings.OrthogonalHeight != 640)
            {
                throw new Exception("A Layer using MatchCamera coordinate types is not matching the Camera's ortho values");
            }


            layer = (elementRuntime.ContainedElements[1].DirectObjectReference as Layer);

            if (layer.LayerCameraSettings.OrthogonalWidth != 80 ||
                layer.LayerCameraSettings.OrthogonalHeight != 64)
            {
                throw new Exception("A Layer using MatchCamera with a destination rectangle does not have proper coordinates");
            }
        }
        private void CreateScreenSaves()
        {
            mScreenSave = new ScreenSave();
            mScreenSave.Name = "NamedObjectSaveTestsScreen";
            ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave);

            mDerivedNos = new NamedObjectSave();
            mDerivedNos.SourceType = SourceType.Entity;
            mDerivedNos.SourceClassType = mDerivedEntitySave.Name;
            mScreenSave.NamedObjects.Add(mDerivedNos);
        }
Example #40
0
 public static CustomVariableInNamedObject GetCustomVariable(this NamedObjectSave namedObject, string variableName)
 {
     foreach (var variable in namedObject.InstructionSaves)
     {
         if (variable.Member == variableName)
         {
             return(variable);
         }
     }
     return(null);
 }
        void Initialize(IElement element, NamedObjectSave referencedNos, StateSave stateSave = null)
        {
            this.element = element;
            this.stateSave = stateSave;
            this.referencedNos = referencedNos;


            RefreshList();


        }
Example #42
0
 public static IElement GetContainer(this NamedObjectSave instance)
 {
     if (ObjectFinder.Self.GlueProject != null)
     {
         return(ObjectFinder.Self.GetElementContaining(instance));
     }
     else
     {
         return(null);
     }
 }
Example #43
0
        public static bool CanBeInShapeCollection(this NamedObjectSave instance)
        {
            var isOfCorrectType = instance.SourceType == SourceType.FlatRedBallType &&
                                  (
                instance.SourceClassType == "Circle" ||
                instance.SourceClassType == "AxisAlignedRectangle" ||
                instance.SourceClassType == "Polygon"
                                  );

            return(isOfCorrectType);
        }
 public void Show(ElementRuntime elementRuntime, NamedObjectSave nosToShow)
 {
     mCurrentElementRuntime = elementRuntime;
     if (nosToShow != null)
     {
         nosToShow.UpdateCustomProperties();
     }
     mCurrentNos = nosToShow;
     mNosDisplayer.CurrentElement = GlueViewState.Self.CurrentElement;
     mNosDisplayer.Instance = mCurrentNos;
     mNosDisplayer.PropertyGrid = mPropertyGrid;
 }
        public NamedObjectSave RectangleSaveToNamedObjectSave(AxisAlignedRectangleSave rectangle)
        {
            NamedObjectSave toReturn = new NamedObjectSave();

            toReturn.SourceType = SourceType.FlatRedBallType;
            toReturn.SourceClassType = "AxisAlignedRectangle";
            toReturn.InstanceName = rectangle.Name;

            AddVariablesForAllProperties(rectangle, toReturn);

            return toReturn;
        }
        public override void AddVariablesForAllProperties(object saveObject, NamedObjectSave toModify)
        {
            ArrowElementInstance elementInstance = saveObject as ArrowElementInstance;
            toModify.InstructionSaves.Clear();
            foreach (var variable in elementInstance.Variables)
            {

                var toAdd = variable.Clone<CustomVariableInNamedObject>();
                toModify.InstructionSaves.Add(toAdd);

            }
        }
        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");
            }
        }
        public NamedObjectSave CircleSaveToNamedObjectSave(CircleSave circle)
        {
            NamedObjectSave toReturn = new NamedObjectSave();

            toReturn.SourceType = SourceType.FlatRedBallType;
            toReturn.SourceClassType = "Circle";
            toReturn.InstanceName = circle.Name;

            AddVariablesForAllProperties(circle, toReturn);

            return toReturn;
        }
        public NamedObjectSave SpriteSaveToNamedObjectSave(FlatRedBall.Content.Scene.SpriteSave sprite)
        {
            NamedObjectSave toReturn = new NamedObjectSave();

            toReturn.SourceType = SourceType.FlatRedBallType;
            toReturn.SourceClassType = "Sprite";
            toReturn.InstanceName = sprite.Name;

            AddVariablesForAllProperties(sprite, toReturn);

            return toReturn;
        }
Example #50
0
        public static string NamedObjectSaveToString(NamedObjectSave nos)
        {
            IElement container = nos.GetContainer();

            string containerName = " (Uncontained)";

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

            return(nos.ClassType + " " + nos.FieldName + containerName);
        }
Example #51
0
        public static CustomVariableInNamedObject AddNewGenericInstructionFor(this NamedObjectSave instance, string member, Type type)
        {
            CustomVariableInNamedObject instructionSave = new CustomVariableInNamedObject();

            instructionSave.Value = null; // make it the default

            instructionSave.Type   = type.Name;
            instructionSave.Type   = TypeManager.ConvertToCommonType(instructionSave.Type);
            instructionSave.Member = member;
            // Create a new instruction

            instance.InstructionSaves.Add(instructionSave);
            return(instructionSave);
        }
        public static NamedObjectSave GetNamedObjectThatIsContainerFor(INamedObjectContainer element, NamedObjectSave containedNamedObject)
        {
            foreach (NamedObjectSave namedObjectSave in element.NamedObjects)
            {
                NamedObjectSave returnValue = GetNamedObjectThatIsContainerFor(namedObjectSave, containedNamedObject);

                if (returnValue != null)
                {
                    return(returnValue);
                }
            }

            return(null);
        }
Example #53
0
        public static bool DoesMemberNeedToBeSetByContainer(this NamedObjectSave instance, string memberName)
        {
            if (instance.SourceType == SourceType.Entity)
            {
                EntitySave sourceEntity = ObjectFinder.Self.GetEntitySave(instance.SourceClassType);

                if (sourceEntity != null)
                {
                    return(sourceEntity.DoesMemberNeedToBeSetByContainer(memberName));
                }
            }

            return(false);
        }
Example #54
0
 public static IElement GetReferencedElement(this NamedObjectSave instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException(nameof(instance));
     }
     if (string.IsNullOrEmpty(instance.SourceClassType))
     {
         return(null);
     }
     else
     {
         return(ObjectFinder.Self.GetEntitySave(instance.SourceClassType));
     }
 }
        public static NamedObjectSave AddNewNamedObjectToSelectedElement(string objectName, MembershipInfo membershipInfo, bool raisePluginResponse = true)
        {
            NamedObjectSave namedObject = new NamedObjectSave();

            namedObject.InstanceName = objectName;

            namedObject.DefinedByBase = membershipInfo == MembershipInfo.ContainedInBase;

            #region Adding to a NamedObject (PositionedObjectList)

            if (EditorLogic.CurrentNamedObject != null)
            {
                AddNamedObjectToCurrentNamedObjectList(namedObject);
            }
            #endregion

            #region else adding to Screen

            else if (EditorLogic.CurrentScreenTreeNode != null)
            {
                ScreenTreeNode screenTreeNode =
                    EditorLogic.CurrentScreenTreeNode;
                AddNewNamedObjectToElementTreeNode(screenTreeNode, namedObject, true);
            }

            #endregion

            #region else adding to an Entity
            else if (EditorLogic.CurrentEntityTreeNode != null)
            {
                EntityTreeNode entityTreeNode =
                    EditorLogic.CurrentEntityTreeNode;

                AddNewNamedObjectToElementTreeNode(entityTreeNode, namedObject, true);
            }
            #endregion


            if (raisePluginResponse)
            {
                PluginManager.ReactToNewObject(namedObject);
            }
            MainGlueWindow.Self.PropertyGrid.Refresh();
            ElementViewWindow.GenerateSelectedElementCode();
            GluxCommands.Self.SaveGlux();

            return(namedObject);
        }
Example #56
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);
        }
        public static bool ReactToRenamedReferencedFile(this INamedObjectContainer namedObjectContainer, string oldName, string newName)
        {
            bool toReturn = false;

            for (int i = 0; i < namedObjectContainer.NamedObjects.Count; i++)
            {
                NamedObjectSave namedObject = namedObjectContainer.NamedObjects[i];

                if (namedObject.SourceFile == oldName)
                {
                    toReturn = true;
                    namedObject.SourceFile = newName;
                }
            }

            return(toReturn);
        }
Example #58
0
        public static ContainerType GetContainerType(this NamedObjectSave instance)
        {
            IElement container = instance.GetContainer();

            if (container == null)
            {
                return(SaveClasses.ContainerType.None);
            }
            else if (container is EntitySave)
            {
                return(SaveClasses.ContainerType.Entity);
            }
            else
            {
                return(SaveClasses.ContainerType.Screen);
            }
        }
Example #59
0
        public static void ResetVariablesReferencing(this NamedObjectSave namedObject, ReferencedFileSave rfs)
        {
            for (int i = namedObject.InstructionSaves.Count - 1; i > -1; i--)
            {
                var variable = namedObject.InstructionSaves[i];

                if (CustomVariableExtensionMethods.GetIsFile(variable.Type) && (string)(variable.Value) == rfs.GetInstanceName())
                {
                    // We're going to make it null, but
                    // we don't save null instructions in
                    // NOS's so that our .glux stays small
                    // and so there's less chances of conflicts
                    // occurring because of undefined sorting behavior.
                    namedObject.InstructionSaves.RemoveAt(i);
                }
            }
        }
Example #60
0
        public static NamedObjectSave GetDefiningNamedObjectSave(this NamedObjectSave instance, IElement container)
        {
            if (instance.DefinedByBase == false)
            {
                return(instance);
            }
            else
            {
                // it's defined by base
                if (string.IsNullOrEmpty(container.BaseElement))
                {
                    throw new Exception("The instance is DefinedByBase, but the container doesn't have a BaseElement");
                }

                NamedObjectSave foundNos = null;

                IElement currentElement = ObjectFinder.Self.GetIElement(container.BaseElement);

                while (currentElement != null)
                {
                    foundNos = currentElement.NamedObjects.FirstOrDefault(
                        item => item.InstanceName == instance.InstanceName);

                    if (foundNos != null && foundNos.SetByDerived)
                    {
                        break;
                    }
                    else
                    {
                        currentElement = ObjectFinder.Self.GetIElement(currentElement.BaseElement);

                        if (currentElement == null)
                        {
                            if (foundNos == null || (foundNos.ExposedInDerived == false && foundNos.SetByDerived == false))
                            {
                                foundNos = null;
                            }
                        }
                    }
                }

                return(foundNos);
            }
        }