Inheritance: IFileReferencer, IElement, ITaggable
コード例 #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);
        }
コード例 #2
0
        public List <ReferencedFileSave> GetAllReferencedFiles()
        {
            List <ReferencedFileSave> allFiles = new List <ReferencedFileSave>();

            for (int i = 0; i < Entities.Count; i++)
            {
                EntitySave entitySave = Entities[i];

                for (int j = 0; j < entitySave.ReferencedFiles.Count; j++)
                {
                    ReferencedFileSave rfs = entitySave.ReferencedFiles[j];
                    allFiles.Add(rfs);
                }
            }

            for (int i = 0; i < Screens.Count; i++)
            {
                ScreenSave screenSave = Screens[i];

                for (int j = 0; j < screenSave.ReferencedFiles.Count; j++)
                {
                    ReferencedFileSave rfs = screenSave.ReferencedFiles[j];
                    allFiles.Add(rfs);
                }
            }

            for (int i = 0; i < GlobalFiles.Count; i++)
            {
                ReferencedFileSave rfs = GlobalFiles[i];
                allFiles.Add(rfs);
            }

            return(allFiles);
        }
コード例 #3
0
        public static bool IsEntityNameValid(string name, EntitySave entitySave, out string whyItIsntValid)
        {
            whyItIsntValid = "";

            CheckForCommonImproperNames(name, ref whyItIsntValid);


            CheckForExistingEntity(name, ref whyItIsntValid);

            if (ObjectFinder.Self.GetEntitySaveUnqualified(name) != null)
            {
                whyItIsntValid = "There is already an entity named " + name;
            }
            else if (ObjectFinder.Self.GetReferencedFileSaveFromFile("Entities\\" + name) != null)
            {
                whyItIsntValid = "There is already a file named " + name;
            }
            else if (mReservedClassNames.Contains(name))
            {
                whyItIsntValid = "The name " + name + " is a reserved class name, so it can't be used for an Entity";
            }
            else if (ObjectFinder.Self.GetScreenSaveUnqualified(name) != null)
            {
                whyItIsntValid = "There is already a Screen named " + name + ".\n\nGlue recommends not naming your Screens and Entities the same because " +
                                 "adding an Entity to a Screen that has the same name may cause problems in the generated code.";
            }
            else if (name == ProjectManager.ProjectNamespace)
            {
                whyItIsntValid = "The Entity cannot be named the same as the root namespace (which is usually the same name as the project)";
            }


            return(string.IsNullOrEmpty(whyItIsntValid));
        }
コード例 #4
0
ファイル: StateTests.cs プロジェクト: vchelaru/FlatRedBall
        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);

            
        }
コード例 #5
0
        public void TestSceneTypes()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "NosSceneTest";

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.InstanceName = "NamedScene";
            nos.SourceClassType = "Scene";
            entitySave.NamedObjects.Add(nos);

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

            if (elementRuntime.ContainedElements.Count == 0)
            {
                throw new Exception("ElementRuntimes with Scene NOS's should create ElementRuntimes for the Scene NOS");
            }

            if (elementRuntime.ContainedElements[0].DirectObjectReference is Scene == false)
            {
                throw new Exception("Scene NOS's should create Scenes");
            }

            if (((Scene)elementRuntime.ContainedElements[0].DirectObjectReference).Name != nos.InstanceName)
            {
                throw new Exception("Name on Scenes are not being set from NOS's");
            }

        }
コード例 #6
0
        public IElement ToGlueIElement(ArrowElementSave arrowElement)
        {
            List<string> referencedFiles = new List<string>();


            IElement glueElement;

            if (arrowElement.ElementType == ElementType.Screen)
            {
                glueElement = new ScreenSave();
                glueElement.Name = "Screens/" + arrowElement.Name;
            }
            else
            {
                glueElement = new EntitySave();
                glueElement.Name = "Entities/" + arrowElement.Name;
            }


            AddSpritesToElement(arrowElement, glueElement, referencedFiles);

            AddCirclesToElement(arrowElement, glueElement);
            AddRectanglesToElement(arrowElement, glueElement);

            AddElementInstancesToElement(arrowElement, glueElement);

            AddReferencedFileSaves(referencedFiles, glueElement);

            AddCustomVariables(glueElement);

            return glueElement;
        }
コード例 #7
0
ファイル: StateTests.cs プロジェクト: vchelaru/FlatRedBall
        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();

        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public static List<ExposableEvent> GetExposableEventsFor(EntitySave entitySave, bool removeAlreadyExposed)
        {
            List<ExposableEvent> returnValues = new List<ExposableEvent>();

            // February 18, 2012
            // Not sure why this checks
            // both if the Entity is IClickable
            // and IWindow, but only IWindow has
            // these events.  Let's fix that:
            //if (entitySave.ImplementsIClickable || entitySave.ImplementsIWindow)
            if (entitySave.GetImplementsIWindowRecursively())
            {
                AddIWindowEvents(returnValues);

            }

            if (entitySave.GetImplementsIVisibleRecursively())
            {
                returnValues.Add(new ExposableEvent( "AfterVisibleSet", "Visible", BeforeOrAfter.After));
                returnValues.Add(new ExposableEvent("BeforeVisibleSet", "Visible", BeforeOrAfter.Before));
            }

            // todo:  Will want to implement after Enabled set events

            GetExposableEventsFor(entitySave, returnValues);


            returnValues.Sort(Sort);
            if (removeAlreadyExposed)
            {
                RemoveAlreadyExposed(entitySave, returnValues);
            }

            return returnValues;
        }
コード例 #10
0
        public SaveClasses.EntitySave AddEntity(string entityName, bool is2D)
        {

            string fileName = entityName + ".cs";

            if (!entityName.ToLower().StartsWith("entities\\") && !entityName.ToLower().StartsWith("entities/"))
            {
                fileName = @"Entities\" + fileName;
            }



            EntitySave entitySave = new EntitySave();
            entitySave.Is2D = is2D;
            entitySave.Name = FileManager.RemoveExtension(fileName);

            const bool AddXYZ = true;

            if (AddXYZ)
            {
                entitySave.CustomVariables.Add(new CustomVariable() { Name = "X", Type = "float" });
                entitySave.CustomVariables.Add(new CustomVariable() { Name = "Y", Type = "float" });
                entitySave.CustomVariables.Add(new CustomVariable() { Name = "Z", Type = "float" });
            }

            AddEntity(entitySave);

            return entitySave;

        }
コード例 #11
0
        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?
        }
コード例 #12
0
        public void Initialize()
        {
            OverallInitializer.Initialize();

            mEntitySave = new EntitySave();
            mEntitySave.Name = "EntitySaveInNamedObjectSaveTests";
        }
コード例 #13
0
        public static List <EntitySave> GetAllBaseEntities(this EntitySave instance)
        {
            List <EntitySave> listToReturn = new List <EntitySave>();

            instance.GetAllBaseEntities(listToReturn);

            return(listToReturn);
        }
コード例 #14
0
        private void CreateDerivedEntitySave()
        {
            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.Name = "DerivedCustomVariableTestsEntity";
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);

            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            mDerivedEntitySave.UpdateFromBaseType();
        }
コード例 #15
0
        private void GenerateAbsoluteVisible(ICodeBlock codeBlock, EntitySave entitySave)
        {
            if (!entitySave.GetInheritsFromIVisible())
            {
                var prop = codeBlock.Property("AbsoluteVisible", Public: true, Override: false, Type: "bool");
                prop.Get().Line("return Visible && (Parent == null || IgnoresParentVisibility || Parent is FlatRedBall.Graphics.IVisible == false || (Parent as FlatRedBall.Graphics.IVisible).AbsoluteVisible);");
            }

        }
コード例 #16
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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        private void CreateCsvContainerEntitySave()
        {
            mCsvContainerEntitySave = new EntitySave();
            mCsvContainerEntitySave.Name = "CsvContainerEntityInExposedVariableTests";
            ObjectFinder.Self.GlueProject.Entities.Add(mCsvContainerEntitySave);

            ReferencedFileSave rfs = new ReferencedFileSave();
            rfs.SourceFile = "Whatever.csv";
            rfs.Name = "Whatever.csv";
            mCsvContainerEntitySave.ReferencedFiles.Add(rfs);
        }
コード例 #19
0
ファイル: LayerTests.cs プロジェクト: vchelaru/FlatRedBall
        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");
            }
        }
コード例 #20
0
        public void TestRecursion()
        {
            EntitySave container = new EntitySave();
            container.Name = "TestRecursionContainer";
            ObjectFinder.Self.GlueProject.Entities.Add(container);

            if (RecursionManager.Self.CanContainInstanceOf(container, container.Name) == true)
            {
                throw new Exception("A type cannot contain itself");
            }

        }
コード例 #21
0
 private void GenerateIVisibleParent(ICodeBlock codeBlock, EntitySave entitySave)
 {
     if (!entitySave.GetInheritsFromIVisible())
     {
         var prop = codeBlock.Property("FlatRedBall.Graphics.IVisible.Parent", Override: false, Type: "FlatRedBall.Graphics.IVisible");
         var get = prop.Get();
         get.If("this.Parent != null && this.Parent is FlatRedBall.Graphics.IVisible")
             .Line("return this.Parent as FlatRedBall.Graphics.IVisible;").End()
             .Else()
             .Line("return null;");
     }
 }
コード例 #22
0
        public static bool UpdateFromBaseType(this EntitySave instance)
        {
            bool haveChangesOccurred = false;

            if (ObjectFinder.Self.GlueProject != null)
            {
                haveChangesOccurred |= NamedObjectContainerHelper.UpdateNamedObjectsFromBaseType(instance);

                IBehaviorContainerHelper.UpdateCustomVariablesFromBaseType(instance);
            }
            return(haveChangesOccurred);
        }
コード例 #23
0
        public void TestNamedObjectSave()
        {
            EntitySave entitySave = new EntitySave();

            NamedObjectSave nos = new NamedObjectSave();

            string whyNot;
            NameVerifier.IsNamedObjectNameValid("Parent", nos, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Parent should not be  avalid name for a PositionedObject, but Glue allows it");
            }
        }
コード例 #24
0
        /// <summary>
        /// Returns whether the calling Entity inherits from another Entity that implements IClickable
        /// </summary>
        /// <param name="instance">The calling Entity</param>
        /// <returns>Whether the implementation is found in a base Entity.</returns>
        public static bool GetInheritsFromIClickable(this EntitySave instance)
        {
            if (string.IsNullOrEmpty(instance.BaseEntity))
            {
                return(false);
            }
            else
            {
                EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.BaseEntity);

                return(entitySave != null && (entitySave.ImplementsIClickable || entitySave.GetInheritsFromIClickable()));
            }
        }
コード例 #25
0
        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();
        }
コード例 #26
0
        private void CreateDerivedElementRuntime()
        {
            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.Name = "DerivedVariableSettingEntity";
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);
            mDerivedEntitySave.UpdateFromBaseType();
            mDerivedEntitySave.GetCustomVariable("CurrentState").DefaultValue = "Uncategorized";


            mDerivedElementRuntime = new ElementRuntime(mDerivedEntitySave, null, null, null, null);


        }
コード例 #27
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);
        }
コード例 #28
0
        public static void GetAllBaseEntities(this EntitySave instance, List <EntitySave> entityListToFill)
        {
            if (!string.IsNullOrEmpty(instance.BaseEntity))
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(instance.BaseEntity);

                if (baseEntity != null)
                {
                    entityListToFill.Add(baseEntity);

                    baseEntity.GetAllBaseEntities(entityListToFill);
                }
            }
        }
コード例 #29
0
        public static ReferencedFileSave GetReferencedFileSaveRecursively(this IElement instance, string fileName)
        {
            ReferencedFileSave rfs = FileReferencerHelper.GetReferencedFileSave(instance, fileName);

            if (rfs == null && !string.IsNullOrEmpty(instance.BaseObject))
            {
                EntitySave baseEntitySave = GlueState.CurrentGlueProject.GetEntitySave(instance.BaseObject);
                if (baseEntitySave != null)
                {
                    rfs = baseEntitySave.GetReferencedFileSaveRecursively(fileName);
                }
            }

            return(rfs);
        }
コード例 #30
0
ファイル: LayerTests.cs プロジェクト: vchelaru/FlatRedBall
        public void TestPercentageLayers()
        {
            EntitySave entitySave = new EntitySave();
            entitySave.Name = "LayerTestTestPercentageLayersEntity";

            NamedObjectSave nos = new NamedObjectSave();

            nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Layer";
            nos.InstanceName = "PercentageLayer";
            nos.IndependentOfCamera = true;
            nos.Is2D = true;
            nos.LayerCoordinateUnit = LayerCoordinateUnit.Percent;
            nos.LayerCoordinateType = LayerCoordinateType.MatchCamera;
            nos.DestinationRectangle = new FloatRectangle(0, 0, 10, 10);
            entitySave.NamedObjects.Add(nos);
            NamedObjectSave percentageLayerNos = nos;


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


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

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

            float destinationWidth = layer.LayerCameraSettings.RightDestination - layer.LayerCameraSettings.LeftDestination;

            if (System.Math.Abs(destinationWidth - (percentageLayerNos.DestinationRectangle.Value.Width * Camera.Main.DestinationRectangle.Width / 100.0f)) > .01)
            {
                throw new Exception("Percentage based layers are not properly setting the destination rectangle");
            }

            if (System.Math.Abs(layer.LayerCameraSettings.OrthogonalWidth - destinationWidth) > .01)
            {
                throw new Exception("Percentage based 2D layers are not properly setting their orthogonal values");
            }



        }
コード例 #31
0
        public static ReferencedFileSave GetReferencedFileSaveByInstanceNameRecursively(this IElement element, string instanceName)
        {
            ReferencedFileSave rfs = element.GetReferencedFileSaveByInstanceName(instanceName);

            if (rfs == null && !string.IsNullOrEmpty(element.BaseElement))
            {
                EntitySave baseEntitySave = GlueState.CurrentGlueProject.GetEntitySave(element.BaseElement);

                if (baseEntitySave != null)
                {
                    rfs = baseEntitySave.GetReferencedFileSaveByInstanceNameRecursively(instanceName);
                }
            }

            return(rfs);
        }
コード例 #32
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);
        }
コード例 #33
0
ファイル: StateTests.cs プロジェクト: vchelaru/FlatRedBall
        public void Initialize()
        {
            OverallInitializer.Initialize();

            CreateEntitySave();

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

            CreateContainerEntitySave();

            CreateDerivedContainerEntitySave();

            Container.Set(new StateSaveSetVariableLogic());
        }
コード例 #34
0
ファイル: EventTests.cs プロジェクト: vchelaru/FlatRedBall
        public void Initialize()
        {
            OverallInitializer.Initialize();

            mEntitySave = new EntitySave();
            mEntitySave.ImplementsIWindow = true;
            mEntitySave.Name = "EventTestEntity";
            mEntitySave.ImplementsIWindow = true;
            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            mScreenSave = new ScreenSave();
            mScreenSave.Name = "EventTestScreen";
            ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave);

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.Entity;
            nos.SourceClassType = "EventTestEntity";
            mScreenSave.NamedObjects.Add(nos);


            EventResponseSave ers = new EventResponseSave();
            ers.SourceObject = "EventTestEntity";
            ers.SourceObjectEvent = "Click";
            ers.EventName = "EventTestEntityClick";
            mScreenSave.Events.Add(ers);

            EventResponseSave pushErs = new EventResponseSave();
            pushErs.SourceObject = "EventTestEntity";
            pushErs.SourceObjectEvent = "Push";
            pushErs.EventName = "EventTestEntityPush";
            mScreenSave.Events.Add(pushErs);

            // Create a POList so we can expose its event(s)
            mListNos = new NamedObjectSave();
            mListNos.SourceType = SourceType.FlatRedBallType;
            mListNos.SourceClassType = "PositionedObjectList<T>";
            mListNos.SourceClassGenericType = "Sprite";
            mScreenSave.NamedObjects.Add(mListNos);

            mDerivedEntitySave = new EntitySave();
            mDerivedEntitySave.Name = "EventTestsDerivedEntity";
            mDerivedEntitySave.BaseEntity = mEntitySave.Name;
            ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave);
        }
コード例 #35
0
ファイル: IVisibleTests.cs プロジェクト: vchelaru/FlatRedBall
        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);

        }
コード例 #36
0
        //public static void CleanUnusedVariablesFromStates(this ScreenSave screenSave)
        //{
        //    IElementHelper.CleanUnusedVariablesFromStates(screenSave);
        //}


        public static bool InheritsFrom(this ScreenSave instance, string screen)
        {
            if (instance.BaseScreen == screen)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(instance.BaseScreen))
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(instance.BaseScreen);

                if (baseEntity != null)
                {
                    return(baseEntity.InheritsFrom(screen));
                }
            }

            return(false);
        }
コード例 #37
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");
            }

        }
コード例 #38
0
        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);
        }
コード例 #39
0
        public static bool DoesMemberNeedToBeSetByContainer(this IElement namedObjectContainer, string memberName)
        {
            foreach (NamedObjectSave namedObject in namedObjectContainer.NamedObjects)
            {
                if (namedObject.InstanceName == memberName && namedObject.SetByContainer)
                {
                    return(namedObject.SetByContainer);
                }
            }

            if (namedObjectContainer.InheritsFromElement())
            {
                EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                return(baseEntity.DoesMemberNeedToBeSetByContainer(memberName));
            }


            return(false);
        }
コード例 #40
0
        public void Initialize()
        {

            // Couldn't run tests here because it requires FRB to be initialized.  
            OverallInitializer.Initialize();

            mBaseEntity = new EntitySave();
            mBaseEntity.Name = "ReferencedFileSaveTestsBaseEntity";

            ReferencedFileSave rfs = new ReferencedFileSave();


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

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

        }
コード例 #41
0
        /// <summary>
        /// Returns whether the calling Entity inherits from another class that implements ICollidable.
        /// Whether the calling Entity itself implements ICollidable doesn't matter.
        /// </summary>
        /// <param name="instance">The calling Entity</param>
        /// <returns>Whether the implementation is found in a base Entity.</returns>
        public static bool GetHasImplementsCollidableProperty(this EntitySave instance)
        {
            if (string.IsNullOrEmpty(instance.BaseEntity))
            {
                return(true);
            }
            else
            {
                if (instance.InheritsFromFrbType())
                {
                    AssetTypeInfo ati = AvailableAssetTypes.Self.GetAssetTypeFromRuntimeType(instance.BaseEntity, instance);

                    if (ati != null)
                    {
                        return(!ati.ImplementsICollidable);
                    }
                }
                return(true);
            }
        }
コード例 #42
0
        public static EntitySave GetRootBaseEntitySave(this EntitySave instance)
        {
            if (string.IsNullOrEmpty(instance.BaseEntity) || instance.InheritsFromFrbType())
            {
                return(instance);
            }
            else
            {
                EntitySave entitySave = ObjectFinder.Self.GetEntitySave(instance.BaseEntity);

                if (entitySave == null)
                {
                    // The user will get errors for this in other parts of Glue.
                    return(null);
                }
                else
                {
                    return(entitySave.GetRootBaseEntitySave());
                }
            }
        }
コード例 #43
0
        public static MembershipInfo GetMemberMembershipInfoForNamedObjectList(this EntitySave instance, string memberName, List <NamedObjectSave> namedObjectList)
        {
            for (int i = 0; i < namedObjectList.Count; i++)
            {
                if (namedObjectList[i].FieldName == memberName)
                {
                    return(MembershipInfo.ContainedInThis);
                }

                MembershipInfo membershipInfo = instance.GetMemberMembershipInfoForNamedObjectList(memberName, namedObjectList[i].ContainedObjects);

                if (membershipInfo != MembershipInfo.NotContained)
                {
                    return(membershipInfo);
                }
            }



            return(MembershipInfo.NotContained);
        }
コード例 #44
0
        public EntitySave GetEntitySave(string entityName)
        {
            if (!string.IsNullOrEmpty(entityName))
            {
                // We don't know what project is using the Glue classes, and it may prefer
                // forward slashes or back slashes.  Therefore we should tolerate either when
                // making comparisons
                entityName = entityName.Replace('/', '\\');

                for (int i = 0; i < Entities.Count; i++)
                {
                    EntitySave entitySave = Entities[i];

                    if (entitySave.Name.Replace('/', '\\') == entityName)
                    {
                        return(entitySave);
                    }
                }
            }
            return(null);
        }
コード例 #45
0
        public void TestReferencedFileSave()
        {
            EntitySave entitySave = new EntitySave();

            ReferencedFileSave rfs = new ReferencedFileSave();
            rfs.Name = "File.png";
            entitySave.ReferencedFiles.Add(rfs);

            string whyNot;
            NameVerifier.IsReferencedFileNameValid("File", null, null, entitySave, out whyNot);
            if(string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it.");
            }

            NameVerifier.IsReferencedFileNameValid("File.wav", null, null, entitySave, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it.");
            }

            NameVerifier.IsReferencedFileNameValid("Folder/File.wav", null, null, entitySave, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it.");
            }

            NameVerifier.IsReferencedFileNameValid("Folder/File", null, null, entitySave, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it.");
            }

            NameVerifier.IsReferencedFileNameValid("if", null, null, entitySave, out whyNot);
            if (string.IsNullOrEmpty(whyNot))
            {
                throw new Exception("'if' is a reserved keyword and should not be allowed as a file name");
            }

        }
コード例 #46
0
ファイル: GumToGlueConverter.cs プロジェクト: patridge/Gum
        internal IElement ConvertElement(ElementSave element)
        {
            if (element is GumScreen)
            {
                var glueScreen = new FlatRedBall.Glue.SaveClasses.ScreenSave();
                glueScreen.Name = $"Screens\\{element.Name}";

                return(glueScreen);
            }
            else if (element is ComponentSave)
            {
                var glueEntity = new FlatRedBall.Glue.SaveClasses.EntitySave();
                glueEntity.Name = $"Entities\\{element.Name}";

                // components should have some variables by default:
                glueEntity.CustomVariables.Add(new CustomVariable()
                {
                    Name = "X",
                    Type = "float",
                });

                glueEntity.CustomVariables.Add(new CustomVariable()
                {
                    Name = "Y",
                    Type = "float",
                });

                glueEntity.CustomVariables.Add(new CustomVariable()
                {
                    Name = "RotationZ",
                    Type = "float",
                });

                return(glueEntity);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
コード例 #47
0
        public void TestStateCodeGeneration()
        {
            ICodeBlock codeBlock = new CodeDocument(0);
            
            mButtonInButtonList.CurrentState = "InvalidState";

            StateCodeGenerator.WriteSetStateOnNamedObject(mButtonInButtonList, codeBlock);
            string result = codeBlock.ToString();
            if (result.Contains(mButtonInButtonList.CurrentState))
            {
                throw new Exception("Code generation for NamedObjects is generating state setting code when states don't really exist");
            }

            // Make sure generation doesn't mess up on a entity with a "" base (instead of null)
            StateCodeGenerator scg = new StateCodeGenerator();
            EntitySave entitySave = new EntitySave();

            entitySave.States.Add(new StateSave());

            entitySave.BaseEntity = "";
            scg.GenerateFields(codeBlock, entitySave);
        }
コード例 #48
0
        public static NamedObjectSave GetNamedObjectRecursively(this INamedObjectContainer namedObjectContainer, string namedObjectName)
        {
            List <NamedObjectSave> namedObjectList = namedObjectContainer.NamedObjects;

            NamedObjectSave foundNos = GetNamedObjectInList(namedObjectList, namedObjectName);

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

            // These methods need to check if the baseScreen/baseEntity is not null.
            // They can be null if the user deletes a base Screen/Entity and the tool
            // managing the Glux doesn't handle the changes.

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject))
            {
                if (namedObjectContainer is EntitySave)
                {
                    EntitySave baseEntity = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);
                    if (baseEntity != null)
                    {
                        return(GetNamedObjectRecursively(baseEntity, namedObjectName));
                    }
                }

                else if (namedObjectContainer is ScreenSave)
                {
                    ScreenSave baseScreen = ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject);

                    if (baseScreen != null)
                    {
                        return(GetNamedObjectRecursively(baseScreen, namedObjectName));
                    }
                }
            }

            return(null);
        }
コード例 #49
0
        public static void RenameElement(this IElement elementToRename, string value)
        {
            bool   isValid = true;
            string whyItIsntValid;

            if (elementToRename is ScreenSave)
            {
                isValid = NameVerifier.IsScreenNameValid(value, elementToRename as ScreenSave, out whyItIsntValid);
            }
            else
            {
                isValid = NameVerifier.IsEntityNameValid(value, elementToRename as EntitySave, out whyItIsntValid);
            }

            if (!isValid)
            {
                MessageBox.Show(whyItIsntValid);
            }
            else
            {
                string oldName = elementToRename.Name;
                string newName = oldName.Substring(0, oldName.Length - elementToRename.ClassName.Length) + value;

                DialogResult result = ChangeClassNamesInCodeAndFileName(elementToRename, value, oldName, newName);

                if (result == DialogResult.Yes)
                {
                    // Set the name first because that's going
                    // to be used by code that follows to modify
                    // inheritance.
                    elementToRename.Name = newName;


                    if (elementToRename is EntitySave)
                    {
                        // Change any Entities that depend on this
                        for (int i = 0; i < ProjectManager.GlueProjectSave.Entities.Count; i++)
                        {
                            EntitySave entitySave = ProjectManager.GlueProjectSave.Entities[i];
                            if (entitySave.BaseEntity == oldName)
                            {
                                entitySave.BaseEntity = newName;
                            }
                        }

                        // Change any NamedObjects that use this as their type (whether in Entity, or as a generic class)
                        List <NamedObjectSave> namedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(oldName);

                        foreach (NamedObjectSave nos in namedObjects)
                        {
                            if (nos.SourceType == SourceType.Entity && nos.SourceClassType == oldName)
                            {
                                nos.SourceClassType = newName;
                                nos.UpdateCustomProperties();
                            }
                            else if (nos.SourceType == SourceType.FlatRedBallType && nos.SourceClassGenericType == oldName)
                            {
                                nos.SourceClassGenericType = newName;
                            }
                        }
                    }
                    else
                    {
                        // Change any Screens that depend on this
                        for (int i = 0; i < ProjectManager.GlueProjectSave.Screens.Count; i++)
                        {
                            ScreenSave screenSave = ProjectManager.GlueProjectSave.Screens[i];
                            if (screenSave.BaseScreen == oldName)
                            {
                                screenSave.BaseScreen = newName;
                            }
                        }

                        if (ProjectManager.StartUpScreen == oldName)
                        {
                            ProjectManager.StartUpScreen = newName;
                        }


                        // Don't do anything with NamedObjects and Screens since they can't (currently) be named objects
                    }

                    ProjectManager.SaveProjects();
                    GluxCommands.Self.SaveGlux();


                    TreeNode treeNode = GlueState.Self.Find.ElementTreeNode(elementToRename);
                    if (treeNode is ScreenTreeNode)
                    {
                        ((ScreenTreeNode)treeNode).UpdateReferencedTreeNodes();
                    }
                    else if (treeNode is EntityTreeNode)
                    {
                        ((EntityTreeNode)treeNode).UpdateReferencedTreeNodes();
                    }

                    if (elementToRename is EntitySave)
                    {
                        ProjectManager.SortAndUpdateUI(elementToRename as EntitySave);
                    }

                    else if (elementToRename is ScreenSave)
                    {
                        ProjectManager.SortAndUpdateUI(elementToRename as ScreenSave);
                    }
                }
            }
        }
コード例 #50
0
 public static bool GetImplementsIClickableRecursively(this EntitySave instance)
 {
     return(instance.ImplementsIClickable || instance.GetInheritsFromIClickable());
 }
コード例 #51
0
        public static List <NamedObjectSave> GetNamedObjectsToBeExposedInDerived(this INamedObjectContainer namedObjectContainer)
        {
            List <NamedObjectSave> namedObjectsToBeExposedInDerived = new List <NamedObjectSave>();

            if (!string.IsNullOrEmpty(namedObjectContainer.BaseObject) && namedObjectContainer.BaseObject != "<NONE>")
            {
                //If this is a Screen
                if ((namedObjectContainer as EntitySave) == null)
                {
                    namedObjectsToBeExposedInDerived.AddRange(
                        ObjectFinder.Self.GetScreenSave(namedObjectContainer.BaseObject).GetNamedObjectsToBeExposedInDerived());
                }
                //Otherwise it's an Entity
                else
                {
                    EntitySave baseEntitySave = ObjectFinder.Self.GetEntitySave(namedObjectContainer.BaseObject);

                    if (baseEntitySave == null)
                    {
                        bool inheritsFromFrbType =
                            namedObjectContainer is EntitySave && (namedObjectContainer as EntitySave).InheritsFromFrbType();

                        if (!inheritsFromFrbType)
                        {
                            System.Windows.Forms.MessageBox.Show("The Element\n\n" + namedObjectContainer.ToString() + "\n\nhas a base type\n\n" + namedObjectContainer.BaseObject +
                                                                 "\n\nbut this base type can't be found.  " +
                                                                 "It was probably removed from the project.  You will need to set the base object to NONE.");
                        }
                    }
                    else
                    {
                        namedObjectsToBeExposedInDerived.AddRange(
                            baseEntitySave.GetNamedObjectsToBeExposedInDerived());
                    }
                }
            }

            foreach (NamedObjectSave nos in namedObjectContainer.NamedObjects)
            {
                if (nos.ExposedInDerived)
                {
                    bool isAlreadyThere = false;

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {
                            isAlreadyThere = true;
                            break;
                        }
                    }

                    if (!isAlreadyThere)
                    {
                        namedObjectsToBeExposedInDerived.Add(nos);
                    }
                }
                else if (nos.DefinedByBase)
                {
                    // This guy is handling the named object save, so let's remove it from the list

                    for (int i = namedObjectsToBeExposedInDerived.Count - 1; i > -1; i--)
                    {
                        if (namedObjectsToBeExposedInDerived[i].InstanceName == nos.InstanceName)
                        {
                            namedObjectsToBeExposedInDerived.RemoveAt(i);
                        }
                    }
                }
            }

            return(namedObjectsToBeExposedInDerived);
        }
コード例 #52
0
 public static bool GetImplementsIWindowRecursively(this EntitySave instance)
 {
     return(instance.ImplementsIWindow || instance.GetInheritsFromIWindow());
 }
コード例 #53
0
 public static List <StateSave> GetAllStatesReferencingObject(this EntitySave instance, string objectName)
 {
     return(IElementHelper.GetAllStatesReferencingObject(instance, objectName));
 }
コード例 #54
0
 public static bool HasMemberWithName(this EntitySave instance, string memberName)
 {
     return(instance.GetMemberMembershipInfo(memberName) != MembershipInfo.NotContained);
 }
コード例 #55
0
ファイル: GluxCommands.cs プロジェクト: vchelaru/FlatRedBall
        public bool MoveEntityToDirectory(EntitySave entitySave, string newRelativeDirectory)
        {
            bool succeeded = true;

            string targetDirectory = FileManager.RelativeDirectory + newRelativeDirectory;
            string oldName = entitySave.Name;
            string newName = newRelativeDirectory.Replace("/", "\\") + entitySave.ClassName;
            succeeded = MoveEntityCodeFilesToDirectory(entitySave, targetDirectory);

            if (succeeded)
            {
                entitySave.Name = newName;
            }

            if (succeeded)
            {
                // Do this after changing the name of the Entity so
                // namespaces come over properly
                succeeded = UpdateNamespaceOnCodeFiles(entitySave);
            }

            if (succeeded)
            {
                // 5: Change namespaces
                string newNamespace = ProjectManager.ProjectNamespace + "." + FileManager.MakeRelative(targetDirectory).Replace("/", ".");
                newNamespace = newNamespace.Substring(0, newNamespace.Length - 1);
                string customFileContents = FileManager.FromFileText(FileManager.RelativeDirectory + newName + ".cs");
                customFileContents = CodeWriter.ReplaceNamespace(customFileContents, newNamespace);
                FileManager.SaveText(customFileContents, FileManager.RelativeDirectory + newName + ".cs");

                // Generated will automatically have its namespace changed when it is re-generated

                // 6:  Find all objects referending this NamedObjectSave and re-generate the code

                if (entitySave.CreatedByOtherEntities)
                {
                    // Vic says: I'm tired.  For now just ignore the directory.  Fix this when it becomes a problem.
                    FactoryCodeGenerator.UpdateFactoryClass(entitySave);
                }

                List<NamedObjectSave> namedObjects = ObjectFinder.Self.GetAllNamedObjectsThatUseEntity(oldName);


                // Let's get all the TreeNodes to regenerate.
                // We want to store them in a list so we only generate
                // each tree node once.
                List<BaseElementTreeNode> treeNodesForElementsToRegenerate = new List<BaseElementTreeNode>();

                foreach (NamedObjectSave nos in namedObjects)
                {
                    if (nos.SourceClassGenericType == oldName)
                    {
                        nos.SourceClassGenericType = newName;
                    }

                    if (nos.SourceClassType == oldName)
                    {
                        nos.SourceClassType = newName;
                    }

                    IElement element = nos.GetContainer();

                    BaseElementTreeNode treeNode = GlueState.Self.Find.ElementTreeNode(element);
                    if (!treeNodesForElementsToRegenerate.Contains(treeNode))
                    {
                        treeNodesForElementsToRegenerate.Add(treeNode);
                    }
                }


                foreach (EntitySave esToTestForInheritance in ProjectManager.GlueProjectSave.Entities)
                {
                    if (esToTestForInheritance.BaseEntity == oldName)
                    {
                        esToTestForInheritance.BaseEntity = newName;

                        BaseElementTreeNode treeNode = GlueState.Self.Find.EntityTreeNode(esToTestForInheritance);
                        if (!treeNodesForElementsToRegenerate.Contains(treeNode))
                        {
                            treeNodesForElementsToRegenerate.Add(treeNode);
                        }
                    }
                }

                foreach (BaseElementTreeNode treeNode in treeNodesForElementsToRegenerate)
                {
                    CodeWriter.GenerateCode(treeNode.SaveObjectAsElement);
                }
            }

            return succeeded;
        }
コード例 #56
0
        private static void UpdateTypedMembers(this NamedObjectSave instance)
        {
            if (instance.SourceType == SourceType.Entity)
            {
                if (string.IsNullOrEmpty(instance.SourceClassType) || instance.SourceClassType == "<NONE>")
                {
                    instance.TypedMembers.Clear();
                }
                else
                {
                    EntitySave entitySave = ObjectFinder.Self.GetEntitySave(
                        instance.SourceClassType);
                    if (entitySave != null)
                    {
                        instance.TypedMembers.Clear();
                        // This is null if a property that calls
                        // UpdateProperties is called before the project
                        // is loaded - as is the case when the GLUX is
                        // deserialized.
                        instance.TypedMembers.AddRange(entitySave.GetTypedMembers());
                    }
                }
            }
            else if (string.IsNullOrEmpty(instance.ClassType) || instance.ClassType.Contains("PositionedObjectList<"))
            {
                instance.TypedMembers.Clear();
            }
            else if (instance.IsList)
            {
                // do nothing.
            }
            else
            {
                instance.TypedMembers.Clear();
                // We used to only include members in the
                // ATI.  Now we want to include every possible
                // variable so that they all show up in the PropertyGrid.
                //AssetTypeInfo ati = instance.GetAssetTypeInfo();

                //if (ati == null)
                //{
                //    throw new NullReferenceException("Could not find an AssetType for the type " +
                //        instance.SourceClassType + ".  This either means that your ContenTypes CSV is corrupt, out of date, missing, or that you have not loaded a content types CSV if you are using teh GluxViewManager in a custom app.");
                //    instance.TypedMembers.Clear();
                //}
                //else
                //{
                //    instance.TypedMembers.Clear();
                //    instance.TypedMembers.AddRange(ati.GetTypedMembers());
                //}

                List <MemberWithType> variables = ExposedVariableManager.GetExposableMembersFor(instance);

                foreach (var member in variables)
                {
                    int errorCode = 0;
                    try
                    {
                        errorCode = 0;
                        string memberType = member.Type;
                        errorCode  = 1;
                        memberType = TypeManager.ConvertToCommonType(memberType);
                        errorCode  = 2;

                        Type type = TypeManager.GetTypeFromString(memberType);
                        errorCode = 3;
                        // Glue can't do anything with generic properties (yet)
                        // Update: I'm adding support for it now
                        //if (type != null && type.IsGenericType == false)
                        TypedMemberBase typedMember = null;

                        if (type != null)
                        {
                            typedMember = TypedMemberBase.GetTypedMemberUnequatable(member.Member, type);
                        }
                        else
                        {
                            typedMember = TypedMemberBase.GetTypedMemberUnequatable(member.Member, typeof(object));
                            typedMember.CustomTypeName = memberType;
                        }
                        instance.TypedMembers.Add(typedMember);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error trying to fix member " + member + " in object " + instance + ". Error code: " + errorCode + "Additional info:\n\n\n" + e.ToString(), e);
                    }
                }

                var ati = instance.GetAssetTypeInfo();

                if (ati != null)
                {
                    foreach (var member in ati.VariableDefinitions)
                    {
                        // Only consider this if it's not already handled:
                        bool isAlreadyHandled = instance.TypedMembers.Any(item => item.MemberName == member.Name);

                        if (!isAlreadyHandled)
                        {
                            string memberType = member.Type;
                            memberType = TypeManager.ConvertToCommonType(memberType);

                            Type type = TypeManager.GetTypeFromString(memberType);
                            // Glue can't do anything with generic properties (yet)
                            // Update: I'm adding support for it now
                            //if (type != null && type.IsGenericType == false)
                            TypedMemberBase typedMember = null;

                            if (type != null)
                            {
                                typedMember = TypedMemberBase.GetTypedMemberUnequatable(member.Name, type);
                            }
                            else
                            {
                                typedMember = TypedMemberBase.GetTypedMemberUnequatable(member.Name, typeof(object));
                                typedMember.CustomTypeName = memberType;
                            }
                            instance.TypedMembers.Add(typedMember);
                        }
                    }
                }
            }
        }
コード例 #57
0
        public static List <FlatRedBall.Instructions.Reflection.TypedMemberBase> GetTypedMembers(this EntitySave instance)
        {
            List <TypedMemberBase> typedMembers = new List <TypedMemberBase>();

            foreach (var customVariable in instance.CustomVariables)
            {
                if (customVariable.Scope == Scope.Public || customVariable.Scope == Scope.Internal)
                {
                    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);
        }
コード例 #58
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
            }
        }