コード例 #1
0
        public static AnimationSet DeserializeAnimationSet(this AnimationDeserializeContext context)
        {
            var animationSet = new AnimationSet();

            animationSet.friendlyName = context.br.ReadNullableString();
            animationSet.importOrigin = context.br.ReadPoint();
            animationSet.behaviour    = context.br.ReadNullableString();

            if (context.br.ReadBoolean())
            {
                animationSet.Heightmap = new Heightmap(context);
            }

            if (animationSet.Heightmap != null)
            {
                animationSet.physicsStartX = animationSet.Heightmap.StartX;
                animationSet.physicsEndX   = animationSet.Heightmap.EndX;
                animationSet.physicsStartZ = animationSet.Heightmap.StartZ;
                animationSet.physicsEndZ   = animationSet.Heightmap.EndZ;

                // Assume that reading is faster than walking the heightmap:
                animationSet.physicsHeight = context.br.ReadInt32();
                if (animationSet.physicsHeight > 0)
                {
                    animationSet.depthBounds = new DepthBounds(context);
                }
                animationSet.flatDirection =
                    context.br.ReadOblique();                     // <- for the sake of editing, keep this value around
            }
            else
            {
                animationSet.physicsStartX = context.br.ReadInt32();
                animationSet.physicsEndX   = context.br.ReadInt32();
                animationSet.physicsStartZ = context.br.ReadInt32();
                animationSet.physicsHeight = context.br.ReadInt32();
                animationSet.flatDirection = context.br.ReadOblique();

                if (animationSet.physicsHeight == 0)
                {
                    animationSet.physicsEndZ =
                        context.br.ReadInt32();                       // physicsEndZ gets auto-set during regen, except for carpets
                }
                animationSet.RegenerateDepthBounds();                 // <- Know this is reasonably fast to generate
            }

            if (context.Version >= 38)
            {
                animationSet.coplanarPriority = context.br.ReadInt32();
            }

            if (context.Version >= 36)
            {
                animationSet.doAboveCheck = context.br.ReadBoolean();
            }

            if (context.br.ReadBoolean())
            {
                animationSet.Ceiling = new Heightmap(context);
            }

            animationSet.animations = context.DeserializeTagLookup(() => context.DeserializeAnimation());

            // Unused Animations
            {
                int count = context.br.ReadInt32();
                if (count > 0)                 // unusedAnimations is lazy-initialized
                {
                    animationSet.unusedAnimations = new List <Animation>(count);
                    for (var i = 0; i < count; i++)
                    {
                        animationSet.unusedAnimations.Add(context.DeserializeAnimation());
                    }
                }
            }

            animationSet.cue = context.br.ReadNullableString();

            // Shadow layers
            {
                int shadowLayerCount = context.br.ReadInt32();
                if (shadowLayerCount <= 0)
                {
                    animationSet.shadowLayers = null;
                }
                else
                {
                    animationSet.shadowLayers = new List <ShadowLayer>();
                    for (var i = 0; i < shadowLayerCount; i++)
                    {
                        animationSet.shadowLayers.Add(new ShadowLayer(context.br.ReadInt32(), new SpriteRef(context)));
                    }

                    animationSet.cachedShadowBounds = context.br.ReadBounds();
                }
            }

            // Properties:
            if (context.Version >= 40)
            {
                int count = context.br.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    animationSet.properties.Add(context.br.ReadString(), context.br.ReadString());
                }
            }

            return(animationSet);
        }
コード例 #2
0
        public static AnimationFrame DeserializeAnimationFrame(this AnimationDeserializeContext context)
        {
            var animationFrame = new AnimationFrame();

            animationFrame.delay         = context.br.ReadInt32();
            animationFrame.positionDelta = context.br.ReadPosition();
            animationFrame.shadowOffset  = context.br.ReadPosition();

            animationFrame.SnapToGround = context.br.ReadBoolean();

            int layersCount = context.br.ReadInt32();

            if (layersCount > 0)
            {
                Cel currentCel;
                animationFrame.firstLayer = currentCel = new Cel(context);
                for (var i = 1; i < layersCount; i++)
                {
                    currentCel.next = new Cel(context);
                    currentCel      = currentCel.next;
                }
            }

            if (context.Version >= 39)
            {
                animationFrame.masks = context.DeserializeOrderedDictionary(() => new Mask(context));
                animationFrame.outgoingAttachments = context.DeserializeOrderedDictionary(() => new OutgoingAttachment(context));
            }
            else
            {
                //
                // Masks:
                {
                    var legacy = context.DeserializeTagLookup(() => new Mask(context));
                    animationFrame.masks = new OrderedDictionary <string, Mask>();
                    foreach (var mask in legacy)
                    {
                        Debug.Assert(mask.Key.Count < 2, "we don't support multi-tags yet");
                        animationFrame.masks.Add(mask.Key.ToString(), mask.Value);
                    }
                }

                //
                // Outgoing Attachments:
                {
                    var legacy = context.DeserializeTagLookup(() => new OutgoingAttachment(context));
                    animationFrame.outgoingAttachments = new OrderedDictionary <string, OutgoingAttachment>();
                    foreach (var outgoingAttachment in legacy)
                    {
                        Debug.Assert(outgoingAttachment.Key.Count < 2, "we don't support multi-tags yet");
                        animationFrame.outgoingAttachments.Add(outgoingAttachment.Key.ToString(),
                                                               outgoingAttachment.Value);
                    }
                }
            }

            animationFrame.incomingAttachments = context.DeserializeTagLookup(() => context.br.ReadPosition());

            int triggerCount = context.br.ReadInt32();

            if (triggerCount > 0)
            {
                animationFrame.triggers = new List <string>(triggerCount);
                for (var i = 0; i < triggerCount; i++)
                {
                    animationFrame.triggers.Add(context.br.ReadString());
                }
            }

            animationFrame.attachAtLayer = context.br.ReadInt32();
            animationFrame.canDrawLayersAboveSortedAttachees = context.br.ReadBoolean();

            animationFrame.cue = context.br.ReadNullableString();

            return(animationFrame);
        }