Esempio n. 1
0
        /// <summary>
        /// Gets a common animation from the animation descriptor
        /// </summary>
        /// <param name="animationDescriptor">The animation descriptor</param>
        /// <returns>The common animation</returns>
        public Unity_ObjAnimation ToCommonAnimation(R1Jaguar_EventDefinition eventDefinition)
        {
            // Create the animation
            var animation = new Unity_ObjAnimation {
                Frames = new Unity_ObjAnimationFrame[FrameCount],
            };

            // The layer index
            var layer = 0;

            var ignoreYBit = Context.Settings.EngineVersion == EngineVersion.R1Jaguar_Proto && AnimationPointer.AbsoluteOffset == 0x00811DDC;

            // Create each frame
            for (int i = 0; i < FrameCount; i++)
            {
                // Create the frame
                var frame = new Unity_ObjAnimationFrame(new Unity_ObjAnimationPart[LayersPerFrame]);

                if (Layers != null)
                {
                    // Create each layer
                    for (var layerIndex = 0; layerIndex < LayersPerFrame; layerIndex++)
                    {
                        var animationLayer = Layers[layer];
                        layer++;

                        // Create the animation part
                        Unity_ObjAnimationPart part;
                        if (eventDefinition.UShort_12 == 5 || eventDefinition.StructType == 31)
                        {
                            part = new Unity_ObjAnimationPart {
                                ImageIndex            = BitHelpers.ExtractBits(animationLayer.ImageIndex, 7, 0),
                                XPosition             = animationLayer.XPosition,
                                YPosition             = ignoreYBit ? BitHelpers.ExtractBits(animationLayer.YPosition, 7, 0) : animationLayer.YPosition,
                                IsFlippedHorizontally = BitHelpers.ExtractBits(animationLayer.ImageIndex, 1, 7) != 0
                            };
                        }
                        else
                        {
                            part = new Unity_ObjAnimationPart {
                                ImageIndex            = animationLayer.ImageIndex,
                                XPosition             = BitHelpers.ExtractBits(animationLayer.XPosition, 7, 0),
                                YPosition             = ignoreYBit ? BitHelpers.ExtractBits(animationLayer.YPosition, 7, 0) : animationLayer.YPosition,
                                IsFlippedHorizontally = BitHelpers.ExtractBits(animationLayer.XPosition, 1, 7) != 0
                            };
                        }

                        // Add the part
                        frame.SpriteLayers[layerIndex] = part;
                    }
                }
                // Set the frame
                animation.Frames[i] = frame;
            }

            return(animation);
        }
        /// <summary>
        /// Gets a common animation from the animation descriptor
        /// </summary>
        /// <param name="animationDescriptor">The animation descriptor</param>
        /// <returns>The common animation</returns>
        public static Unity_ObjAnimation ToCommonAnimation(this IR1_AnimationDescriptor animationDescriptor)
        {
            // Create the animation
            var animation = new Unity_ObjAnimation
            {
                Frames = new Unity_ObjAnimationFrame[animationDescriptor.FrameCount],
            };

            // The layer index
            var layer = 0;

            var frames = animationDescriptor.Frames;
            var layers = animationDescriptor.Layers;

            // Create each frame
            for (int i = 0; i < animationDescriptor.FrameCount; i++)
            {
                // Create the frame
                var frame = new Unity_ObjAnimationFrame(new Unity_ObjAnimationPart[animationDescriptor.LayersPerFrame]);

                if (layers != null)
                {
                    // Create each layer
                    for (var layerIndex = 0; layerIndex < animationDescriptor.LayersPerFrame; layerIndex++)
                    {
                        var animationLayer = layers[layer];
                        layer++;

                        // Create the animation part
                        var part = new Unity_ObjAnimationPart {
                            ImageIndex            = animationLayer.ImageIndex,
                            XPosition             = animationLayer.XPosition,
                            YPosition             = animationLayer.YPosition,
                            IsFlippedHorizontally = animationLayer.IsFlippedHorizontally,
                            IsFlippedVertically   = animationLayer.IsFlippedVertically
                        };

                        // Add the part
                        frame.SpriteLayers[layerIndex] = part;
                    }
                }
                // Set the frame
                animation.Frames[i] = frame;
            }

            return(animation);
        }