public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; int groupCount = 1; // write frame group count. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = thing.FrameGroupCount; writer.Write((byte)groupCount); // cast to 1 byte } for (byte k = 0; k < groupCount; k++) { // write frame group type. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { writer.Write(k); } FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); writer.Write(group.Width); // write width writer.Write(group.Height); // write heigh // write exact size if (group.Width > 1 || group.Height > 1) { writer.Write(group.ExactSize); } writer.Write(group.Layers); // write layers writer.Write(group.PatternX); // write pattern X writer.Write(group.PatternY); // write pattern Y if (patternZEnabled) { writer.Write(group.PatternZ); // write pattern Z } writer.Write(group.Frames); // write frames if (frameDurationsEnabled && group.Frames > 1) { writer.Write((byte)group.AnimationMode); // write animation type writer.Write(group.LoopCount); // write frame strategy writer.Write(group.StartFrame); // write start frame FrameDuration[] durations = group.FrameDurations; for (int i = 0; i < durations.Length; i++) { writer.Write((uint)durations[i].Minimum); // write minimum duration writer.Write((uint)durations[i].Maximum); // write maximum duration } } uint[] sprites = group.SpriteIDs; for (int i = 0; i < sprites.Length; i++) { // write sprite index if (extendedEnabled) { writer.Write(sprites[i]); } else { writer.Write((ushort)sprites[i]); } } } return(true); }
public static bool WriteTexturePatterns(ThingType thing, ClientFeatures features, BinaryWriter writer) { bool patternZEnabled = (features & ClientFeatures.PatternZ) == ClientFeatures.PatternZ; bool extendedEnabled = (features & ClientFeatures.Extended) == ClientFeatures.Extended; bool frameDurationsEnabled = (features & ClientFeatures.FrameDurations) == ClientFeatures.FrameDurations; bool frameGroupsEnabled = (features & ClientFeatures.FrameGroups) == ClientFeatures.FrameGroups; byte groupCount = 1; // write frame group count. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { groupCount = thing.FrameGroupCount; writer.Write(groupCount); } for (byte k = 0; k < groupCount; k++) { // write frame group type. if (frameGroupsEnabled && thing.Category == ThingCategory.Outfit) { writer.Write(k); } FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); writer.Write(group.Width); // write width writer.Write(group.Height); // write heigh // write exact size if (group.Width > 1 || group.Height > 1) { writer.Write(group.ExactSize); } writer.Write(group.Layers); // write layers writer.Write(group.PatternX); // write pattern X writer.Write(group.PatternY); // write pattern Y if (patternZEnabled) { writer.Write(group.PatternZ); // write pattern Z } writer.Write(group.Frames); // write frames if (frameDurationsEnabled && group.Frames > 1) { writer.Write((byte)group.AnimationMode); // write animation type writer.Write(group.LoopCount); // write frame strategy writer.Write(group.StartFrame); // write start frame FrameDuration[] durations = group.FrameDurations; for (int i = 0; i < durations.Length; i++) { writer.Write((uint)durations[i].Minimum); // write minimum duration writer.Write((uint)durations[i].Maximum); // write maximum duration } } uint[] sprites = group.SpriteIDs; for (int i = 0; i < sprites.Length; i++) { // write sprite index if (extendedEnabled) { writer.Write(sprites[i]); } else { writer.Write((ushort)sprites[i]); } } } return true; }
public static ThingType ToSingleFrameGroup(ThingType thing) { if (thing.Category != ThingCategory.Outfit || thing.FrameGroupCount != 2) { return(thing); } FrameGroup walkingFrameGroup = thing.GetFrameGroup(FrameGroupType.Walking); FrameGroup newGroup = walkingFrameGroup.Clone(); if (walkingFrameGroup.Frames > 1) { newGroup.Frames = (byte)(newGroup.Frames + 1); newGroup.SpriteIDs = new uint[newGroup.GetTotalSprites()]; newGroup.IsAnimation = true; newGroup.FrameDurations = new FrameDuration[newGroup.Frames]; for (int i = 0; i < newGroup.Frames; i++) { if (newGroup.FrameDurations[i] != null) { newGroup.FrameDurations[i] = newGroup.FrameDurations[i]; } else { newGroup.FrameDurations[i] = new FrameDuration(ThingCategory.Outfit); } } } for (byte k = 0; k < thing.FrameGroupCount; k++) { FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); for (byte f = 0; f < group.Frames; f++) { for (byte z = 0; z < group.PatternZ; z++) { for (byte y = 0; y < group.PatternY; y++) { for (byte x = 0; x < group.PatternX; x++) { for (byte l = 0; l < group.Layers; l++) { for (byte w = 0; w < group.Width; w++) { for (byte h = 0; h < group.Height; h++) { if (k == (byte)FrameGroupType.Default && f == 0) { int i = group.GetSpriteIndex(w, h, l, x, y, z, f); int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f); newGroup.SpriteIDs[ni] = group.SpriteIDs[i]; } else if (k == (byte)FrameGroupType.Walking) { int i = group.GetSpriteIndex(w, h, l, x, y, z, f); int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f + 1); newGroup.SpriteIDs[ni] = group.SpriteIDs[i]; } } } } } } } } } thing.FrameGroups = new Dictionary <FrameGroupType, FrameGroup>(); thing.FrameGroups.Add(FrameGroupType.Default, newGroup); return(thing); }
public static ThingType ToSingleFrameGroup(ThingType thing) { if (thing.Category != ThingCategory.Outfit || thing.FrameGroupCount != 2) { return thing; } FrameGroup walkingFrameGroup = thing.GetFrameGroup(FrameGroupType.Walking); FrameGroup newGroup = walkingFrameGroup.Clone(); if (walkingFrameGroup.Frames > 1) { newGroup.Frames = (byte)(newGroup.Frames + 1); newGroup.SpriteIDs = new uint[newGroup.GetTotalSprites()]; newGroup.IsAnimation = true; newGroup.FrameDurations = new FrameDuration[newGroup.Frames]; for (int i = 0; i < newGroup.Frames; i++) { if (newGroup.FrameDurations[i] != null) { newGroup.FrameDurations[i] = newGroup.FrameDurations[i]; } else { newGroup.FrameDurations[i] = new FrameDuration(ThingCategory.Outfit); } } } for (byte k = 0; k < thing.FrameGroupCount; k++) { FrameGroup group = thing.GetFrameGroup((FrameGroupType)k); for (byte f = 0; f < group.Frames; f++) { for (byte z = 0; z < group.PatternZ; z++) { for (byte y = 0; y < group.PatternY; y++) { for (byte x = 0; x < group.PatternX; x++) { for (byte l = 0; l < group.Layers; l++) { for (byte w = 0; w < group.Width; w++) { for (byte h = 0; h < group.Height; h++) { if (k == (byte)FrameGroupType.Default && f == 0) { int i = group.GetSpriteIndex(w, h, l, x, y, z, f); int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f); newGroup.SpriteIDs[ni] = group.SpriteIDs[i]; } else if (k == (byte)FrameGroupType.Walking) { int i = group.GetSpriteIndex(w, h, l, x, y, z, f); int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f + 1); newGroup.SpriteIDs[ni] = group.SpriteIDs[i]; } } } } } } } } } thing.frameGroups = new Dictionary<FrameGroupType, FrameGroup>(); thing.frameGroups.Add(FrameGroupType.Default, newGroup); return thing; }