public ObjectData GetThingData(ushort id, ThingCategory category, bool singleFrameGroup) { ThingType thing = this.Things.GetThing(id, category); if (thing == null) { return(null); } if (singleFrameGroup) { thing = ThingType.ToSingleFrameGroup(thing); } SpriteGroup spriteGroups = new SpriteGroup(); Console.WriteLine(thing.FrameGroupCount); for (byte i = 0; i < thing.FrameGroupCount; i++) { FrameGroupType groupType = (FrameGroupType)i; FrameGroup frameGroup = thing.GetFrameGroup(groupType); int length = frameGroup.SpriteIDs.Length; Sprite[] sprites = new Sprite[length]; for (int s = 0; s < length; s++) { sprites[s] = this.Sprites.GetSprite(frameGroup.SpriteIDs[s]); } spriteGroups.Add(groupType, sprites); } return(new ObjectData(thing, spriteGroups)); }
private static ObjectData DecodeV1(BinaryReader reader) { reader.BaseStream.Position = 0; Console.WriteLine(reader.ReadUInt16()); ushort nameLength = reader.ReadUInt16(); byte[] buffer = reader.ReadBytes(nameLength); string categoryStr = Encoding.UTF8.GetString(buffer, 0, buffer.Length); ThingCategory category = ThingCategory.Invalid; switch (categoryStr) { case "item": category = ThingCategory.Item; break; case "outfit": category = ThingCategory.Outfit; break; case "effect": category = ThingCategory.Effect; break; case "missile": category = ThingCategory.Missile; break; } ThingType thing = new ThingType(category); if (!ThingTypeSerializer.ReadProperties(thing, DatFormat.Format_1010, reader)) { return(null); } FrameGroup group = new FrameGroup(); group.Width = reader.ReadByte(); group.Height = reader.ReadByte(); if (group.Width > 1 || group.Height > 1) { group.ExactSize = reader.ReadByte(); } else { group.ExactSize = Sprite.DefaultSize; } group.Layers = reader.ReadByte(); group.PatternX = reader.ReadByte(); group.PatternY = reader.ReadByte(); group.PatternZ = reader.ReadByte(); group.Frames = reader.ReadByte(); if (group.Frames > 1) { group.IsAnimation = true; group.AnimationMode = AnimationMode.Asynchronous; group.LoopCount = 0; group.StartFrame = 0; group.FrameDurations = new FrameDuration[group.Frames]; for (byte i = 0; i < group.Frames; i++) { group.FrameDurations[i] = new FrameDuration(category); } } int totalSprites = group.GetTotalSprites(); if (totalSprites > 4096) { throw new Exception("The ThingData has more than 4096 sprites."); } group.SpriteIDs = new uint[totalSprites]; SpriteGroup spriteGroup = new SpriteGroup(); Sprite[] sprites = new Sprite[totalSprites]; for (int i = 0; i < totalSprites; i++) { uint spriteID = reader.ReadUInt32(); group.SpriteIDs[i] = spriteID; uint dataSize = reader.ReadUInt32(); if (dataSize > Sprite.PixelsDataSize) { throw new Exception("Invalid sprite data size."); } byte[] pixels = reader.ReadBytes((int)dataSize); Sprite sprite = new Sprite(spriteID, true); sprite.SetPixelsARGB(pixels); sprites[i] = sprite; } thing.SetFrameGroup(FrameGroupType.Default, group); spriteGroup.Add(FrameGroupType.Default, sprites); return(new ObjectData(thing, spriteGroup)); }
public ThingData GetThingData(ushort id, ThingCategory category, bool singleFrameGroup) { ThingType thing = this.Things.GetThing(id, category); if (thing == null) { return null; } if (singleFrameGroup) { thing = ThingType.ToSingleFrameGroup(thing); } SpriteGroup spriteGroups = new SpriteGroup(); Console.WriteLine(thing.FrameGroupCount); for (byte i = 0; i < thing.FrameGroupCount; i++) { FrameGroupType groupType = (FrameGroupType)i; FrameGroup frameGroup = thing.GetFrameGroup(groupType); int length = frameGroup.SpriteIDs.Length; Sprite[] sprites = new Sprite[length]; for (int s = 0; s < length; s++) { sprites[s] = this.Sprites.GetSprite(frameGroup.SpriteIDs[s]); } spriteGroups.Add(groupType, sprites); } return new ThingData(thing, spriteGroups); }
private static ThingData DecodeV1(BinaryReader reader) { reader.BaseStream.Position = 0; Console.WriteLine(reader.ReadUInt16()); ushort nameLength = reader.ReadUInt16(); byte[] buffer = reader.ReadBytes(nameLength); string categoryStr = Encoding.UTF8.GetString(buffer, 0, buffer.Length); ThingCategory category = ThingCategory.Invalid; switch (categoryStr) { case "item": category = ThingCategory.Item; break; case "outfit": category = ThingCategory.Outfit; break; case "effect": category = ThingCategory.Effect; break; case "missile": category = ThingCategory.Missile; break; } ThingType thing = new ThingType(category); if (!ThingTypeSerializer.ReadProperties(thing, DatFormat.Format_1010, reader)) { return null; } FrameGroup group = new FrameGroup(); group.Width = reader.ReadByte(); group.Height = reader.ReadByte(); if (group.Width > 1 || group.Height > 1) { group.ExactSize = reader.ReadByte(); } else { group.ExactSize = Sprite.DefaultSize; } group.Layers = reader.ReadByte(); group.PatternX = reader.ReadByte(); group.PatternY = reader.ReadByte(); group.PatternZ = reader.ReadByte(); group.Frames = reader.ReadByte(); if (group.Frames > 1) { group.IsAnimation = true; group.AnimationMode = AnimationMode.Asynchronous; group.LoopCount = 0; group.StartFrame = 0; group.FrameDurations = new FrameDuration[group.Frames]; for (byte i = 0; i < group.Frames; i++) { group.FrameDurations[i] = new FrameDuration(category); } } int totalSprites = group.GetTotalSprites(); if (totalSprites > 4096) { throw new Exception("The ThingData has more than 4096 sprites."); } group.SpriteIDs = new uint[totalSprites]; SpriteGroup spriteGroup = new SpriteGroup(); Sprite[] sprites = new Sprite[totalSprites]; for (int i = 0; i < totalSprites; i++) { uint spriteID = reader.ReadUInt32(); group.SpriteIDs[i] = spriteID; uint dataSize = reader.ReadUInt32(); if (dataSize > Sprite.PixelsDataSize) { throw new Exception("Invalid sprite data size."); } byte[] pixels = reader.ReadBytes((int)dataSize); Sprite sprite = new Sprite(spriteID, true); sprite.SetPixelsARGB(pixels); sprites[i] = sprite; } thing.SetFrameGroup(FrameGroupType.Default, group); spriteGroup.Add(FrameGroupType.Default, sprites); return new ThingData(thing, spriteGroup); }