mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 21:56:19 -04:00
pl2 encoder + test
This commit is contained in:
parent
d5d93df75c
commit
d61d829b98
@ -41,3 +41,13 @@ func Load(data []byte) (*PL2, error) {
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PL2) Marshal() []byte {
|
||||||
|
restruct.EnableExprBeta()
|
||||||
|
data, err := restruct.Pack(binary.LittleEndian, p)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
39
d2common/d2fileformats/d2pl2/pl2_test.go
Normal file
39
d2common/d2fileformats/d2pl2/pl2_test.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package d2pl2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func exampleData() *PL2 {
|
||||||
|
result := &PL2{
|
||||||
|
BasePalette: PL2Palette{},
|
||||||
|
SelectedUintShift: PL2PaletteTransform{},
|
||||||
|
RedTones: PL2PaletteTransform{},
|
||||||
|
GreenTones: PL2PaletteTransform{},
|
||||||
|
BlueTones: PL2PaletteTransform{},
|
||||||
|
DarkendColorShift: PL2PaletteTransform{},
|
||||||
|
}
|
||||||
|
|
||||||
|
result.BasePalette.Colors[0].R = 8
|
||||||
|
result.DarkendColorShift.Indices[0] = 123
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPL2_MarshalUnmarshal(t *testing.T) {
|
||||||
|
pl2 := exampleData()
|
||||||
|
|
||||||
|
data := pl2.Marshal()
|
||||||
|
|
||||||
|
newPL2, err := Load(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if newPL2.BasePalette.Colors[0] != pl2.BasePalette.Colors[0] {
|
||||||
|
t.Fatal("unexpected length")
|
||||||
|
}
|
||||||
|
|
||||||
|
if pl2.DarkendColorShift.Indices[0] != newPL2.DarkendColorShift.Indices[0] {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user