/// <summary>Write to binary stream</summary> public void Serialize(BinaryWriter bw) { lookup.Serialize(bw, sr => { bw.Write(sr.start); bw.Write(sr.count); }); bw.Write(lowercase.Count); for (int i = 0; i < lowercase.Count; i++) { bw.Write(lowercase[i]); } // NOTE: we generate upper-case at load time (for performance) }
public void Serialize(AnimationSerializeContext context) { context.bw.Write(delay); context.bw.Write(positionDelta); context.bw.Write(shadowOffset); context.bw.Write(SnapToGround); // NOTE: This walks the layer linked list twice, but is only O(n), so no biggie int layerCount = layers.Count; context.bw.Write(layerCount); foreach (var cel in layers) { cel.Serialize(context); } masks.Serialize(context, m => m.Serialize(context)); outgoingAttachments.Serialize(context, oa => oa.Serialize(context)); incomingAttachments.Serialize(context, p => context.bw.Write(p)); if (triggers == null) { context.bw.Write((int)0); } else { context.bw.Write(triggers.Count); for (int i = 0; i < triggers.Count; i++) { context.bw.Write(triggers[i]); } } context.bw.Write(attachAtLayer.Clamp(0, layers.Count)); context.bw.Write(canDrawLayersAboveSortedAttachees); context.bw.WriteNullableString(cue); }
public void Serialize(AnimationSerializeContext context) { if (Asserts.enabled && !ValidateAlphaMasks()) { throw new InvalidOperationException("Attempting to save animation set with missing or invalid alpha masks"); } context.bw.WriteNullableString(friendlyName); context.bw.Write(importOrigin); context.bw.WriteNullableString(behaviour); if (context.bw.WriteBoolean(Heightmap != null)) { Heightmap.Serialize(context); } // If you don't seem to have set any physics bounds, I will just generate them... if ((physicsStartX == 0 && physicsEndX == 1 && physicsStartZ == 0 && physicsEndZ == 1 && physicsHeight == 0) || physicsEndX - physicsStartX <= 0) { AutoGeneratePhysicsAndDepthBounds(); } // NOTE: only writing out values that cannot be auto-generated if (Heightmap != null) { Debug.Assert(!Asserts.enabled || Heightmap.IsObjectHeightmap || physicsHeight == 0); context.bw.Write(physicsHeight); if (physicsHeight > 0) { depthBounds.Serialize(context); } context.bw.Write(flatDirection); // <- for the sake of editing, keep this value around } else { context.bw.Write(physicsStartX); context.bw.Write(physicsEndX); context.bw.Write(physicsStartZ); context.bw.Write(physicsHeight); context.bw.Write(flatDirection); if (physicsHeight == 0) { context.bw.Write(physicsEndZ); } } if (context.Version >= 38) { context.bw.Write(coplanarPriority); } if (context.Version >= 36) { context.bw.Write(doAboveCheck); } if (context.bw.WriteBoolean(Ceiling != null)) { Ceiling.Serialize(context); } animations.Serialize(context, a => a.Serialize(context)); // Unused Animations { if (unusedAnimations == null) { context.bw.Write(0); // unused animations is lazy-initialized } else { context.bw.Write(unusedAnimations.Count); foreach (var animation in unusedAnimations) { animation.Serialize(context); } } } context.bw.WriteNullableString(cue); // Shadow layers: { if (shadowLayers == null) { context.bw.Write((int)0); } else { context.bw.Write(shadowLayers.Count); foreach (var sl in shadowLayers) { context.bw.Write(sl.startHeight); sl.shadowSpriteRef.Serialize(context); } RecalculateCachedShadowBounds(); context.bw.Write(cachedShadowBounds); } } }
// NOTE: Pass-through the animation serializer to a simple binary serializer (the format of `TagLookup` is *really* stable, and some folks need to directly serialize us) public static void SerializeTagLookup <T>(this TagLookup <T> tagLookup, AnimationSerializeContext context, Action <T> serializeValue) { tagLookup.Serialize(context.bw, serializeValue); }