1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 09:20:44 +00:00

Merge pull request #1039 from gucio321/data-converting

data encoding: DC6
This commit is contained in:
Tim Sarbin 2021-02-03 09:57:07 -05:00 committed by GitHub
commit 7ec8921f18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -13,7 +13,7 @@ func TestStreamWriterByte(t *testing.T) {
output := sr.GetBytes()
for i, d := range data {
if output[i] != d {
t.Fatalf("sr.PushByte() pushed %X, but wrote %X instead", d, output[i])
t.Fatalf("sr.PushBytes() pushed %X, but wrote %X instead", d, output[i])
}
}
}

View File

@ -146,6 +146,41 @@ func (d *DC6) loadFrames(r *d2datautils.StreamReader) error {
return nil
}
// Marshal encodes dc6 animation back into byte slice
func (d *DC6) Marshal() []byte {
sw := d2datautils.CreateStreamWriter()
// Encode header
sw.PushInt32(d.Version)
sw.PushUint32(d.Flags)
sw.PushUint32(d.Encoding)
sw.PushBytes(d.Termination...)
sw.PushUint32(d.Directions)
sw.PushUint32(d.FramesPerDirection)
// load frames
for _, i := range d.FramePointers {
sw.PushUint32(i)
}
for i := range d.Frames {
sw.PushUint32(d.Frames[i].Flipped)
sw.PushUint32(d.Frames[i].Width)
sw.PushUint32(d.Frames[i].Height)
sw.PushInt32(d.Frames[i].OffsetX)
sw.PushInt32(d.Frames[i].OffsetY)
sw.PushUint32(d.Frames[i].Unknown)
sw.PushUint32(d.Frames[i].NextBlock)
sw.PushUint32(d.Frames[i].Length)
sw.PushBytes(d.Frames[i].FrameData...)
sw.PushBytes(d.Frames[i].Terminator...)
}
return sw.GetBytes()
}
// DecodeFrame decodes the given frame to an indexed color texture
func (d *DC6) DecodeFrame(frameIndex int) []byte {
frame := d.Frames[frameIndex]