Beispiel #1
0
        private void GetEventSignatureAndArgs(NamedObjectSave namedObjectSave, EventResponseSave eventResponseSave, out string type, out string signatureArgs)
        {
            if (namedObjectSave == null)
            {
                throw new ArgumentNullException(nameof(namedObjectSave));
            }

            if (namedObjectSave.GetAssetTypeInfo() == AssetTypeInfoManager.Self.CollisionRelationshipAti &&
                eventResponseSave.SourceObjectEvent == "CollisionOccurred")
            {
                bool firstThrowaway;
                bool secondThrowaway;

                var firstType  = AssetTypeInfoManager.GetFirstGenericType(namedObjectSave, out firstThrowaway);
                var secondType = AssetTypeInfoManager.GetSecondGenericType(namedObjectSave, out secondThrowaway);

                type          = $"System.Action<{firstType}, {secondType}>";
                signatureArgs = $"{firstType} first, {secondType} second";
            }
            else
            {
                type          = null;
                signatureArgs = null;
            }
        }
Beispiel #2
0
        public static void GenerateInitializeCodeFor(NamedObjectSave namedObject, ICodeBlock codeBlock)
        {
            var firstCollidable = namedObject.Properties.GetValue <string>(
                nameof(CollisionRelationshipViewModel.FirstCollisionName));

            var secondCollidable = namedObject.Properties.GetValue <string>(
                nameof(CollisionRelationshipViewModel.SecondCollisionName));

            //////////////Early Out/////////////////////
            if (string.IsNullOrEmpty(firstCollidable) || string.IsNullOrEmpty(secondCollidable))
            {
                return;
            }


            ///////////End Early Out///////////////////

            var collisionType = namedObject.Properties.GetValue <CollisionType>(
                nameof(CollisionRelationshipViewModel.CollisionType));

            var firstMass = namedObject.Properties.GetValue <float>(
                nameof(CollisionRelationshipViewModel.FirstCollisionMass))
                            .ToString(CultureInfo.InvariantCulture) + "f";

            var secondMass = namedObject.Properties.GetValue <float>(
                nameof(CollisionRelationshipViewModel.SecondCollisionMass))
                             .ToString(CultureInfo.InvariantCulture) + "f";

            var elasticity = namedObject.Properties.GetValue <float>(
                nameof(CollisionRelationshipViewModel.CollisionElasticity))
                             .ToString(CultureInfo.InvariantCulture) + "f";

            var firstSubCollision = namedObject.Properties.GetValue <string>(
                nameof(CollisionRelationshipViewModel.FirstSubCollisionSelectedItem));

            var secondSubCollision = namedObject.Properties.GetValue <string>(
                nameof(CollisionRelationshipViewModel.SecondSubCollisionSelectedItem));

            var isCollisionActive = namedObject.Properties.GetValue <bool>(
                nameof(CollisionRelationshipViewModel.IsCollisionActive));

            var instanceName = namedObject.InstanceName;

            bool isFirstList;
            var  firstType = AssetTypeInfoManager.GetFirstGenericType(namedObject, out isFirstList);

            bool isSecondList;
            var  secondType = AssetTypeInfoManager.GetSecondGenericType(namedObject, out isSecondList);

            var isFirstTileShapeCollection  = firstType == "FlatRedBall.TileCollisions.TileShapeCollection";
            var isSecondTileShapeCollection = secondType == "FlatRedBall.TileCollisions.TileShapeCollection";

            var isFirstShapeCollection  = firstType == "FlatRedBall.Math.Geometry.ShapeCollection";
            var isSecondShapeCollection = secondType == "FlatRedBall.Math.Geometry.ShapeCollection";

            if (isSecondTileShapeCollection)
            {
                // same method used for both list and non-list
                codeBlock.Line($"{instanceName} = " +
                               $"FlatRedBall.Math.Collision.CollisionManagerTileShapeCollectionExtensions.CreateTileRelationship(" +
                               $"FlatRedBall.Math.Collision.CollisionManager.Self, " +
                               $"{firstCollidable}, {secondCollidable});");
            }
            //else if(isSecondShapeCollection)
            //{
            //    codeBlock.Line($"{instanceName} = FlatRedBall.Math.Collision.CollisionManager.Self.CreateRelationship(" +
            //        $"{firstCollidable});");
            //}
            else
            {
                codeBlock.Line($"{instanceName} = FlatRedBall.Math.Collision.CollisionManager.Self.CreateRelationship(" +
                               $"{firstCollidable}, {secondCollidable});");
            }

            if (!string.IsNullOrEmpty(firstSubCollision) &&
                firstSubCollision != CollisionRelationshipViewModel.EntireObject)
            {
                codeBlock.Line($"{instanceName}.SetFirstSubCollision(item => item.{firstSubCollision});");
            }
            if (!string.IsNullOrEmpty(secondSubCollision) &&
                secondSubCollision != CollisionRelationshipViewModel.EntireObject)
            {
                codeBlock.Line($"{instanceName}.SetSecondSubCollision(item => item.{secondSubCollision});");
            }

            codeBlock.Line($"{instanceName}.Name = \"{instanceName}\";");



            switch (collisionType)
            {
            case CollisionType.NoPhysics:
                // don't do anything
                break;

            case CollisionType.MoveCollision:

                codeBlock.Line($"{instanceName}.SetMoveCollision({firstMass}, {secondMass});");
                break;

            case CollisionType.BounceCollision:
                //var relationship = new FlatRedBall.Math.Collision.CollisionRelationship();
                //relationship.SetBounceCollision(firstMass, secondMass, elasticity);
                codeBlock.Line($"{instanceName}.SetBounceCollision({firstMass}, {secondMass}, {elasticity});");
                break;
            }

            if (!isCollisionActive)
            {
                codeBlock.Line(
                    $"{instanceName}.{nameof(FlatRedBall.Math.Collision.CollisionRelationship.IsActive)} = false;");
            }
        }