2021-02-17 05:18:37 -05:00
|
|
|
package d2ds1
|
2021-03-02 18:20:44 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2path"
|
|
|
|
)
|
|
|
|
|
2021-03-24 13:54:54 -04:00
|
|
|
func exampleData() *DS1 { //nolint:funlen // not a big deal if this is long func
|
2021-03-02 18:20:44 -05:00
|
|
|
exampleFloor1 := Tile{
|
|
|
|
// common fields
|
|
|
|
tileCommonFields: tileCommonFields{
|
|
|
|
Prop1: 2,
|
|
|
|
Sequence: 89,
|
|
|
|
Unknown1: 123,
|
|
|
|
Style: 20,
|
|
|
|
Unknown2: 53,
|
|
|
|
HiddenBytes: 1,
|
|
|
|
RandomIndex: 2,
|
|
|
|
YAdjust: 21,
|
|
|
|
},
|
|
|
|
tileFloorShadowFields: tileFloorShadowFields{
|
|
|
|
Animated: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exampleFloor2 := Tile{
|
|
|
|
// common fields
|
|
|
|
tileCommonFields: tileCommonFields{
|
|
|
|
Prop1: 3,
|
|
|
|
Sequence: 89,
|
|
|
|
Unknown1: 213,
|
|
|
|
Style: 28,
|
|
|
|
Unknown2: 53,
|
|
|
|
HiddenBytes: 7,
|
|
|
|
RandomIndex: 3,
|
|
|
|
YAdjust: 28,
|
|
|
|
},
|
|
|
|
tileFloorShadowFields: tileFloorShadowFields{
|
|
|
|
Animated: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exampleWall1 := Tile{
|
|
|
|
// common fields
|
|
|
|
tileCommonFields: tileCommonFields{
|
|
|
|
Prop1: 3,
|
|
|
|
Sequence: 89,
|
|
|
|
Unknown1: 213,
|
|
|
|
Style: 28,
|
|
|
|
Unknown2: 53,
|
|
|
|
HiddenBytes: 7,
|
|
|
|
RandomIndex: 3,
|
|
|
|
YAdjust: 28,
|
|
|
|
},
|
|
|
|
tileWallFields: tileWallFields{
|
|
|
|
Type: d2enum.TileRightWall,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exampleWall2 := Tile{
|
|
|
|
// common fields
|
|
|
|
tileCommonFields: tileCommonFields{
|
|
|
|
Prop1: 3,
|
|
|
|
Sequence: 93,
|
|
|
|
Unknown1: 193,
|
|
|
|
Style: 17,
|
|
|
|
Unknown2: 13,
|
|
|
|
HiddenBytes: 1,
|
|
|
|
RandomIndex: 1,
|
|
|
|
YAdjust: 22,
|
|
|
|
},
|
|
|
|
tileWallFields: tileWallFields{
|
|
|
|
Type: d2enum.TileLeftWall,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exampleShadow := Tile{
|
|
|
|
// common fields
|
|
|
|
tileCommonFields: tileCommonFields{
|
|
|
|
Prop1: 3,
|
|
|
|
Sequence: 93,
|
|
|
|
Unknown1: 173,
|
|
|
|
Style: 17,
|
|
|
|
Unknown2: 12,
|
|
|
|
HiddenBytes: 1,
|
|
|
|
RandomIndex: 1,
|
|
|
|
YAdjust: 22,
|
|
|
|
},
|
|
|
|
tileFloorShadowFields: tileFloorShadowFields{
|
|
|
|
Animated: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
result := &DS1{
|
|
|
|
ds1Layers: &ds1Layers{
|
2021-03-24 13:28:02 -04:00
|
|
|
width: 2,
|
|
|
|
height: 2,
|
2021-03-02 18:20:44 -05:00
|
|
|
Floors: layerGroup{
|
|
|
|
// number of floors (one floor)
|
|
|
|
{
|
|
|
|
// tile grid = []tileRow
|
|
|
|
tiles: tileGrid{
|
|
|
|
// tile rows = []Tile
|
|
|
|
// 2x2 tiles
|
|
|
|
{
|
|
|
|
exampleFloor1,
|
|
|
|
exampleFloor2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exampleFloor2,
|
|
|
|
exampleFloor1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Walls: layerGroup{
|
|
|
|
// number of walls (two floors)
|
|
|
|
{
|
|
|
|
// tile grid = []tileRow
|
|
|
|
tiles: tileGrid{
|
|
|
|
// tile rows = []Tile
|
|
|
|
// 2x2 tiles
|
|
|
|
{
|
|
|
|
exampleWall1,
|
|
|
|
exampleWall2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exampleWall2,
|
|
|
|
exampleWall1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// tile grid = []tileRow
|
|
|
|
tiles: tileGrid{
|
|
|
|
// tile rows = []Tile
|
|
|
|
// 2x2 tiles
|
|
|
|
{
|
|
|
|
exampleWall1,
|
|
|
|
exampleWall2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exampleWall2,
|
|
|
|
exampleWall1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Shadows: layerGroup{
|
|
|
|
// number of shadows (always 1)
|
|
|
|
{
|
|
|
|
// tile grid = []tileRow
|
|
|
|
tiles: tileGrid{
|
|
|
|
// tile rows = []Tile
|
|
|
|
// 2x2 tiles
|
|
|
|
{
|
|
|
|
exampleShadow,
|
|
|
|
exampleShadow,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
exampleShadow,
|
|
|
|
exampleShadow,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Files: []string{"a.dt1", "bfile.dt1"},
|
|
|
|
Objects: []Object{
|
|
|
|
{0, 0, 0, 0, 0, nil},
|
|
|
|
{0, 1, 0, 0, 0, []d2path.Path{{}}},
|
|
|
|
{0, 2, 0, 0, 0, nil},
|
|
|
|
{0, 3, 0, 0, 0, nil},
|
|
|
|
},
|
|
|
|
substitutionGroups: nil,
|
|
|
|
version: 17,
|
|
|
|
Act: 1,
|
|
|
|
substitutionType: 0,
|
|
|
|
unknown1: make([]byte, 8),
|
|
|
|
unknown2: 20,
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2021-03-24 13:28:02 -04:00
|
|
|
func TestDS1_MarshalUnmarshal(t *testing.T) {
|
|
|
|
ds1 := exampleData()
|
2021-03-02 18:20:44 -05:00
|
|
|
|
2021-03-24 13:28:02 -04:00
|
|
|
data := ds1.Marshal()
|
2021-03-02 18:20:44 -05:00
|
|
|
|
|
|
|
_, loadErr := Unmarshal(data)
|
|
|
|
if loadErr != nil {
|
|
|
|
t.Error(loadErr)
|
|
|
|
}
|
|
|
|
}
|