public void Serialize(ThingType thingType, Net.OutputMessage binaryWriter, int fromVersion, int newVersion, sbyte startPhase, byte phasesLimit) { binaryWriter.AddU8(Width); binaryWriter.AddU8(Height); if (Width > 1 || Height > 1) { binaryWriter.AddU8(ExactSize); } binaryWriter.AddU8(Layers); binaryWriter.AddU8(PatternWidth); binaryWriter.AddU8(PatternHeight); if (newVersion >= 755) { binaryWriter.AddU8(PatternDepth); } binaryWriter.AddU8(phasesLimit); if (fromVersion < 1050) { if (phasesLimit > 1 && newVersion >= 1050) { FrameGroupAnimator.SerializeLegacy(thingType, binaryWriter, startPhase, phasesLimit); } } else { if (phasesLimit > 1 && newVersion >= 1050) { Animator.Serialize(binaryWriter, startPhase, phasesLimit); } } int spritesPerPhase = Width * Height * Layers * PatternWidth * PatternHeight * PatternDepth; int totalSprites = phasesLimit * spritesPerPhase; int offset = startPhase * spritesPerPhase; for (int j = 0; j < totalSprites; j++) { uint spriteId = Sprites[offset + j]; if (newVersion >= 960) { binaryWriter.AddU32(spriteId); } else { binaryWriter.AddU16((ushort)spriteId); } } }
public static void SerializeLegacy(ThingType thingType, Net.OutputMessage binaryWriter, int startPhase, int phasesLimit) { binaryWriter.AddU8(1); binaryWriter.AddS32(thingType.HasAttribute(AttributesUniform.AnimateAlways) || thingType.Category == ThingCategory.Item ? 0 : 1); binaryWriter.AddU8(0); int duration; if (thingType.Category == ThingCategory.Effect) { duration = 75; } else { duration = phasesLimit > 0 ? 1000 / phasesLimit : 40; } for (int i = 0; i < phasesLimit; i++) { binaryWriter.AddS32(duration); // force legacy animation binaryWriter.AddS32(duration); } }
public void Serialize(Net.OutputMessage binaryWriter, int startPhase, int phasesLimit) { binaryWriter.AddU8(Async ? (byte)1 : (byte)0); binaryWriter.AddS32(LoopCount); int minPhase = startPhase; int maxPhase = startPhase = phasesLimit; if (StartPhase > 0 && (StartPhase < minPhase || StartPhase > maxPhase)) { binaryWriter.AddS8((sbyte)minPhase); } else { binaryWriter.AddS8(StartPhase); } for (int i = 0; i < phasesLimit; i++) { var frameGroupDuration = FrameGroupDurations[startPhase + i]; binaryWriter.AddS32(frameGroupDuration.Minimum); binaryWriter.AddS32(frameGroupDuration.Maximum); } }