From edf243d2f82d93073a7a21120e3df07dfe5c552c Mon Sep 17 00:00:00 2001 From: Braedon Date: Thu, 10 Feb 2022 17:34:15 -0500 Subject: [PATCH] Update BCCAD.cs --- Assets/Editor/bread2unity/BCCAD.cs | 101 ++++++++++------------------- 1 file changed, 36 insertions(+), 65 deletions(-) diff --git a/Assets/Editor/bread2unity/BCCAD.cs b/Assets/Editor/bread2unity/BCCAD.cs index 2749a1ab..ff9efdc4 100644 --- a/Assets/Editor/bread2unity/BCCAD.cs +++ b/Assets/Editor/bread2unity/BCCAD.cs @@ -10,63 +10,49 @@ namespace Bread2Unity public BCCAD Read(byte[] bytes) { - sheetW = (ushort)bytes[4]; - sheetH = (ushort)bytes[6]; + sheetW = BitConverter.ToUInt16(bytes, 4); + sheetH = BitConverter.ToUInt16(bytes, 6); - ISprite spriteParts_ = new ISprite(); - int max = (bytes[8] * 2) + 12; - int loopTimes = 0; - - // this is pretty bad spaghetti code, and I wrote this when I had the flu at 3 AM. so you're welcome --Starpelly - - for (int i = 12; i < max; i+=2) // 16 bit bytes, skip every 2nd byte + // int max = (bytes[8] * 2) + 12; + int max = 64 * bytes[8] + 12; + + // note this doesn't account for empty sprites, but I'll get there when i get there + for (int i = 12; i < max; i += 2) // 16 bit bytes, skip every 2nd byte { - int ind = i + 4; // the first 4 contain the number of parts and an unknown number, I can skip these for now - - ISpritePart part = new ISpritePart(); - part.regionX = BitConverter.ToUInt16(bytes, ind + 0); - part.regionY = BitConverter.ToUInt16(bytes, ind + 2); - part.regionW = BitConverter.ToUInt16(bytes,ind + 4); - part.regionH = BitConverter.ToUInt16(bytes, ind + 6); - part.posX = BitConverter.ToInt16(bytes, ind + 8); - part.posY = BitConverter.ToInt16(bytes, ind + 10); - part.stretchX = BitConverter.ToSingle(bytes, ind + 12); - part.stretchY = BitConverter.ToSingle(bytes, ind + 14); - part.rotation = BitConverter.ToSingle(bytes, ind + 16); - part.flipX = bytes[ind + 18] != (byte)0; - part.flipY = bytes[ind + 20] != (byte)0; - // im sure the values between 20 and 28 are important so remind me to come back to these - part.opacity = bytes[ind + 28]; - - // Debug.Log(part.regionX); - - spriteParts_.parts.Add(part); - - int compare = 32; - if (loopTimes < 1) + ISprite spriteParts_ = new ISprite(); + int compare = 0; + for (int j = 0; j < bytes[i]; j++) { - compare = 32; - } - else if (loopTimes >= 1) - { - if (loopTimes % 2 == 0) - { - compare = 32; - } - else - { - compare = 34; - } - } - max += compare * 2; - i += compare * 2; - loopTimes++; + int ind = i + 4 + (64 * j); - Debug.Log("offset: " + (ind + (compare - loopTimes + 1) * 2) + ", val: " + BitConverter.ToUInt16(bytes, (ind + (compare - loopTimes + 1) * 2))); + ISpritePart part = new ISpritePart(); + part.regionX = BitConverter.ToUInt16(bytes, ind + 0); + part.regionY = BitConverter.ToUInt16(bytes, ind + 2); + part.regionW = BitConverter.ToUInt16(bytes, ind + 4); + part.regionH = BitConverter.ToUInt16(bytes, ind + 6); + part.posX = BitConverter.ToInt16(bytes, ind + 8); + part.posY = BitConverter.ToInt16(bytes, ind + 10); + part.stretchX = BitConverter.ToSingle(bytes, ind + 12); + part.stretchY = BitConverter.ToSingle(bytes, ind + 14); + part.rotation = BitConverter.ToSingle(bytes, ind + 16); + part.flipX = bytes[ind + 18] != (byte)0; + part.flipY = bytes[ind + 20] != (byte)0; + // im sure the values between 20 and 28 are important so remind me to come back to these + part.opacity = bytes[ind + 28]; + + Debug.Log("offset: " + ind + ", val: " + part.regionX); + + spriteParts_.parts.Add(part); + + compare += 64; + } + + sprites.Add(spriteParts_); + + i += compare; } - sprites.Add(spriteParts_); return new BCCAD() { @@ -75,20 +61,5 @@ namespace Bread2Unity /// sprites length bytes start = 12 - - /// 20 = 1 - /// 84 = 2 - /// 152 = 3 - /// 216 = 4 - /// 284 - 5 - /// - /// - /// 64 - /// 64 - /// -- Loop - /// 68 - /// 64 - /// 68 - /// 64 } } \ No newline at end of file