public static AnimationChainGridSave FromAnimationChainGrid(
            TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid)
        {
            AnimationChainGridSave ags = new AnimationChainGridSave();

            int numberOfTextures = animationChainGrid.Textures.Count;

            ags.ReferenceGrid = new ReferencedAnimationChain[numberOfTextures][];

            ags.FirstPaintedX = animationChainGrid.FirstPaintedX;
            ags.FirstPaintedY = animationChainGrid.FirstPaintedY;

            for (int i = 0; i < animationChainGrid.Textures.Count; i++)
            {
                ags.ReferenceGrid[i] = new ReferencedAnimationChain[animationChainGrid[i].Count];

                for (int j = 0; j < animationChainGrid.Textures[i].Count; j++)
                {
                    if (animationChainGrid.Textures[i][j] != null)
                    {
                        ags.ReferenceGrid[i][j] = ReferencedAnimationChain.FromAnimationChain(
                            animationChainGrid.Textures[i][j]);
                    }
                }
            }

            return(ags);
        }
Exemple #2
0
        private void CreateAnimationChainGrid(string contentManagerName, FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid)
        {
            #region Create the AnimationChainGrid
            if (AnimationChainGridSave != null)
            {
                TextureGrid <FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid =
                    AnimationChainGridSave.ToAnimationChainGrid(contentManagerName, GridSpacing);

                spriteGrid.AnimationChainGrid = animationChainGrid;
            }
            #endregion
        }
        public static AnimationChainGridSave FromXElement(System.Xml.Linq.XElement element)
        {
            AnimationChainGridSave acs = new AnimationChainGridSave();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "FirstPaintedY":
                    acs.FirstPaintedY = SceneSave.AsFloat(subElement);
                    break;

                case "ReferenceGrid":
                    acs.ReferenceGrid = ToAnimationChainReferenceArrayArray(subElement);
                    break;

                default:
                    throw new NotImplementedException("Node not understood: " + subElement.Name.LocalName);
                }
            }

            return(acs);
        }
Exemple #4
0
        internal static SpriteGridSave FromXElement(System.Xml.Linq.XElement element)
        {
            SpriteGridSave sgs = new SpriteGridSave();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                case "AnimationChainGridSave":
                    sgs.AnimationChainGridSave = AnimationChainGridSave.FromXElement(subElement);
                    break;

                case "Axis":
                    sgs.Axis = SpriteEditorScene.AsChar(subElement);
                    break;

                case "Blueprint":
                    sgs.Blueprint = SpriteSave.FromXElement(subElement);
                    break;

                case "BaseTexture":
                    sgs.BaseTexture = (string)subElement.Value;
                    break;

                case "CreatesAutomaticallyUpdatedSprites":
                    sgs.CreatesAutomaticallyUpdatedSprites = SpriteEditorScene.AsBool(subElement);
                    break;

                case "CreatesParticleSprites":
                    sgs.CreatesParticleSprites = SpriteEditorScene.AsBool(subElement);
                    break;

                case "DisplayRegionGridSave":
                    sgs.DisplayRegionGridSave = DisplayRegionGridSave.FromXElement(subElement);
                    break;

                case "DrawableBatch":
                    sgs.DrawableBatch = SpriteEditorScene.AsBool(subElement);
                    break;

                case "DrawDefaultTile":
                    sgs.DrawDefaultTile = SpriteEditorScene.AsBool(subElement);
                    break;

                case "FirstPaintedX":
                    sgs.FirstPaintedX = SpriteEditorScene.AsFloatList(subElement);
                    break;

                case "FirstPaintedY":
                    sgs.FirstPaintedY = SceneSave.AsFloat(subElement);
                    break;

                case "GridSpacing":
                    sgs.GridSpacing = SceneSave.AsFloat(subElement);
                    break;

                case "GridTexturesArray":
                    sgs.GridTexturesArray = SpriteEditorScene.AsStringArrayArray(subElement);
                    break;

                case "Name":
                    sgs.Name = subElement.Value;
                    break;

                case "OrderingMode":
                    sgs.OrderingMode = (Graphics.OrderingMode)Enum.Parse(typeof(Graphics.OrderingMode), subElement.Value, true);
                    break;

                case "XLeftBound":
                    sgs.XLeftBound = SceneSave.AsFloat(subElement);
                    break;

                case "XRightBound":
                    sgs.XRightBound = SceneSave.AsFloat(subElement);
                    break;

                case "YBottomBound":
                    sgs.YBottomBound = SceneSave.AsFloat(subElement);
                    break;

                case "YTopBound":
                    sgs.YTopBound = SceneSave.AsFloat(subElement);
                    break;

                case "ZCloseBound":
                    sgs.ZCloseBound = SceneSave.AsFloat(subElement);
                    break;

                case "ZFarBound":
                    sgs.ZFarBound = SceneSave.AsFloat(subElement);
                    break;

                default:
                    throw new NotImplementedException("Node not understood: " + subElement.Name.LocalName);
                }
            }


            return(sgs);
        }
Exemple #5
0
        public static SpriteGridSave FromSpriteGrid(FlatRedBall.ManagedSpriteGroups.SpriteGrid spriteGrid)
        {
            SpriteGridSave spriteGridSave = new SpriteGridSave();

            if (spriteGrid.Name != null)
            {
                spriteGridSave.Name = spriteGrid.Name;
            }

            spriteGridSave.Blueprint = SpriteSave.FromSprite(spriteGrid.Blueprint);

            #region Set the GridPlane (Axis in SpriteSave)

            if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XY)
            {
                spriteGridSave.Axis = 'y';
            }
            else
            {
                spriteGridSave.Axis = 'z';
            }

            #endregion

            // Create new lists here instead of just assigning them (like we used to do) because
            // the SpriteGridSave will make modifications to these to make file sizes smaller.  If
            // we don't make new lists, then the SpriteGridSave will make modifications to the original
            // SpriteGrid which causes problems.
            spriteGridSave.FirstPaintedX = new List <float>(spriteGrid.TextureGrid.FirstPaintedX);
            spriteGridSave.FirstPaintedY = spriteGrid.TextureGrid.FirstPaintedY;



            spriteGridSave.GridSpacing = spriteGrid.GridSpacing;

            // Right now there's no sprite type.  Should there be Ordered/Unordered?

            #region set the bounds
            spriteGridSave.XRightBound  = spriteGrid.XRightBound;
            spriteGridSave.XLeftBound   = spriteGrid.XLeftBound;
            spriteGridSave.YTopBound    = spriteGrid.YTopBound;
            spriteGridSave.YBottomBound = spriteGrid.YBottomBound;
            spriteGridSave.ZCloseBound  = spriteGrid.ZCloseBound;
            spriteGridSave.ZFarBound    = spriteGrid.ZFarBound;
            #endregion


            #region fill up the strings for the FRBTextures

            if (spriteGrid.TextureGrid.BaseTexture != null)
            {
                spriteGridSave.BaseTexture = spriteGrid.TextureGrid.BaseTexture.SourceFile();
            }
            else
            {
                spriteGridSave.BaseTexture = "";
            }

            #region Chop off the bottom (or near in XZ)

            int numberToChopOffBottom = 0;

            float yValue      = spriteGrid.TextureGrid.FirstPaintedY;
            float bottomBound = spriteGrid.YBottomBound;
            if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XZ)
            {
                bottomBound = spriteGrid.ZCloseBound;
            }

            // This will usually include one extra row beyond the bounds, but that's ok because
            // it's possible that someone creates a really weird grid with overlapping Sprites.
            while (yValue + spriteGrid.GridSpacing / 2.0f < bottomBound)
            {
                numberToChopOffBottom++;
                yValue += spriteGrid.GridSpacing;
                spriteGridSave.FirstPaintedY += spriteGrid.GridSpacing;

                if (spriteGridSave.FirstPaintedX.Count == 0)
                {
                    // we're done here, so exit out
                    break;
                }
                else
                {
                    spriteGridSave.FirstPaintedX.RemoveAt(0);
                }
            }
            #endregion

            #region Chop off the top (or far in XZ)

            int numberToChopOffTop = 0;
            yValue = spriteGrid.TextureGrid.FirstPaintedY + spriteGrid.TextureGrid.FirstPaintedX.Count * spriteGrid.GridSpacing;
            float topBound = spriteGrid.YTopBound;
            if (spriteGrid.GridPlane == FlatRedBall.ManagedSpriteGroups.SpriteGrid.Plane.XZ)
            {
                topBound = spriteGrid.ZFarBound;
            }

            while (yValue - spriteGrid.GridSpacing / 2.0f > topBound)
            {
                numberToChopOffTop++;
                yValue -= spriteGrid.GridSpacing;

                if (spriteGridSave.FirstPaintedX.Count == 0)
                {
                    break;
                }
                else
                {
                    spriteGridSave.FirstPaintedX.RemoveAt(spriteGridSave.FirstPaintedX.Count - 1);
                }
            }

            #endregion

            int numberOfGridTextures = spriteGrid.TextureGrid.Textures.Count - numberToChopOffBottom - numberToChopOffTop;
            numberOfGridTextures = System.Math.Max(numberOfGridTextures, 0); // don't let it be negative

            spriteGridSave.GridTexturesArray =
                new string[numberOfGridTextures][];

            //GridTextures = new StringArrayArray();
            //GridTexturesArray = new string[spriteGrid.textureGrid.textures.Count][];

            TextureGrid <Texture2D> textureGrid = spriteGrid.TextureGrid;

            for (int i = numberToChopOffBottom; i < textureGrid.Textures.Count - numberToChopOffTop; i++)
            {
                int numberToChopOffLeft  = 0;
                int numberToChopOffRight = 0;

                float xValue = textureGrid.FirstPaintedX[i];

                while (xValue + spriteGrid.GridSpacingX / 2.0f < spriteGrid.XLeftBound)
                {
                    xValue += spriteGrid.GridSpacingX;
                    numberToChopOffLeft++;
                    spriteGridSave.FirstPaintedX[i - numberToChopOffBottom] += spriteGrid.GridSpacingX;
                }

                xValue = textureGrid.LastPaintedX[i];

                while (xValue - spriteGrid.GridSpacingX / 2.0f > spriteGrid.XRightBound)
                {
                    xValue -= spriteGrid.GridSpacingX;
                    numberToChopOffRight++;
                }

                int numberOfTexturesInRow = textureGrid.Textures[i].Count - numberToChopOffLeft - numberToChopOffRight;
                numberOfTexturesInRow = System.Math.Max(0, numberOfTexturesInRow);

                spriteGridSave.GridTexturesArray[i - numberToChopOffBottom] =
                    new string[numberOfTexturesInRow];

                for (int j = numberToChopOffLeft; j < textureGrid.Textures[i].Count - numberToChopOffRight; j++)
                {
                    if (textureGrid.Textures[i][j] != null)
                    {
                        spriteGridSave.GridTexturesArray[i - numberToChopOffBottom][j - numberToChopOffLeft] =
                            textureGrid.Textures[i][j].SourceFile();
                    }
                    else
                    {
                        spriteGridSave.GridTexturesArray[i - numberToChopOffBottom][j - numberToChopOffLeft] = null;
                    }
                }
            }
            #endregion

            spriteGridSave.AnimationChainGridSave = AnimationChainGridSave.FromAnimationChainGrid(
                spriteGrid.AnimationChainGrid);

            spriteGridSave.DisplayRegionGridSave = DisplayRegionGridSave.FromDisplayRegionGrid(
                spriteGrid.DisplayRegionGrid);

#if FRB_XNA
            spriteGridSave.Blueprint.Ordered = spriteGrid.OrderingMode == FlatRedBall.Graphics.OrderingMode.DistanceFromCamera;
#else
            spriteGridSave.Blueprint.Ordered = spriteGrid.Blueprint.mOrdered;
#endif
            spriteGridSave.CreatesAutomaticallyUpdatedSprites = spriteGrid.CreatesAutomaticallyUpdatedSprites;
            spriteGridSave.CreatesParticleSprites             = spriteGrid.CreatesParticleSprites;
            //spriteGridSave.DrawDefaultTile = spriteGrid.DrawDefaultTile;
            //spriteGridSave.DrawableBatch = spriteGrid.DrawableBatch;

            spriteGridSave.CropOutOfBoundsPaintedSprites();

            return(spriteGridSave);
        }
        public static AnimationChainGridSave FromXElement(System.Xml.Linq.XElement element)
        {
                        
            AnimationChainGridSave acs = new AnimationChainGridSave();

            foreach (var subElement in element.Elements())
            {
                switch (subElement.Name.LocalName)
                {
                    case "FirstPaintedY":
                        acs.FirstPaintedY = SceneSave.AsFloat(subElement);
                        break;
                    case "ReferenceGrid":
                        acs.ReferenceGrid = ToAnimationChainReferenceArrayArray(subElement);
                        break;
                    default:
                        throw new NotImplementedException("Node not understood: " + subElement.Name.LocalName);
                }
            }

            return acs;
        }
        public static AnimationChainGridSave FromAnimationChainGrid(
            TextureGrid<FlatRedBall.Graphics.Animation.AnimationChain> animationChainGrid)
        {
            AnimationChainGridSave ags = new AnimationChainGridSave();

            int numberOfTextures = animationChainGrid.Textures.Count;

            ags.ReferenceGrid = new ReferencedAnimationChain[numberOfTextures][];

            ags.FirstPaintedX = animationChainGrid.FirstPaintedX;
            ags.FirstPaintedY = animationChainGrid.FirstPaintedY;

            for (int i = 0; i < animationChainGrid.Textures.Count; i++)
            {
                ags.ReferenceGrid[i] = new ReferencedAnimationChain[animationChainGrid[i].Count];

                for (int j = 0; j < animationChainGrid.Textures[i].Count; j++)
                {
                    if (animationChainGrid.Textures[i][j] != null)
                    {
                        ags.ReferenceGrid[i][j] = ReferencedAnimationChain.FromAnimationChain(
                            animationChainGrid.Textures[i][j]);
                    }
                }
            }

            return ags;

        }