1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 01:51:14 -05:00
OpenDiablo2/d2common/d2fileformats/d2ds1/ds1_test.go

198 lines
3.5 KiB
Go
Raw Normal View History

package d2ds1
import (
"testing"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2path"
)
func exampleData() *DS1 { //nolint:funlen // not a big deal if this is long func
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{
Ds1 refactor (#11) * Refactoring d2ds1 * Adding setters/getters so that state management can be maintained internally when the ds1 struct is altered * Adding unit tests for DS1 * unit tests for ds1 (#4) * ds1 refactor: added test fore some methods; put tests in right order * ds1 refactor: unit tests for all methods * ds1 refactor: fixed build errors * ds1 refactor: lintfix * ds1 refactor: fixed bug with SetWidth, SetHeight methods * ds1 refactor: rename tile_record.go -> tile.go * ds1 refactor: unit test for SetTiles Co-authored-by: M. Sz <mszeptuch@protonmail.com> * renamed some files in d2ds1 * d2ds1.FloorShadow is now private * renamed another file * DS1.Tile() now calls update if dirty * Ds1 refactor: some test improvement (#5) * ds1 refactor: floor_shadow.go: methods Encode, Decode an Hidden are methods of floorShadow * ds1 refactor: test checks, if our methods sets all fields correctly * ds1 refactor: minor bugfixes * i don't remember what's this, but i commit it ;-) * ds1 refactor: reverted some pushed by mistake things Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: test bugs + descriptive errors + SetNumberOfWall/FloorLayers (#6) * ds1 refactor: - removed DS1.layerStreamTypes field - written unit test for setupStreamLayerTypes method - added more descriptive error messages for LoadDS1 (and submethods) * ds1 refactor: added some missing error messages * ds1 refactor: fixed test bugs * ds1 refactor: removed unnecessary c1. and c2. comments in ds1_test errors * ds1 refactor: removed fmt from ds1_test * ds1 refactor: fixed bug with SetTiles test + lintfix * ds1 refactor: SetNumberOfWalls * ds1 refactor: SetTile(s) now changes walls/floors length if neccesary * ds1 refactor: removed unnecessary debugging fmt * ds1 refactor: added substitution layer and object with paths to example data Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: removed npcIndexes field+fixed SetNumberOfWalls bug (#7) * ds1 refactor: removed npcIndexes field it was unnecessary, because described a number of objects with paths to use in encoder, but we can calculate manually * ds1 refactor: fixed set number of (layers) bug * ds1 refactor: SetNumberOf...Layers now returns error if incorrect number given * ds1 refactor: lintfix * ds1 refactor: rename: setupStreamLayerTypes -> GetStreamLayerTypes Co-authored-by: M. Sz <mszeptuch@protonmail.com> * WIP * Ds1 refactor - tests (#10) * ds1 refactor test: example data * added loader check * ds1 refactor: fixed bug, with loading substitutions; added descriptive error message in engine.go:118 and changed Logger.Error with Logger.Fatal * ds1 refactor: fixed loading bug * ds1 refactor: fixed bug when walls wasn't rendered (now we can see only walls :-) Co-authored-by: M. Sz <mszeptuch@protonmail.com> * ds1: floor rendering bugfix * ds1: implemented encode layers method * ds1: implemented encoder * ds1: update of ds1_test Co-authored-by: gravestench <dknuth0101@gmail.com> Co-authored-by: M. Sz <mszeptuch@protonmail.com>
2021-03-24 13:28:02 -04:00
width: 2,
height: 2,
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
}
Ds1 refactor (#11) * Refactoring d2ds1 * Adding setters/getters so that state management can be maintained internally when the ds1 struct is altered * Adding unit tests for DS1 * unit tests for ds1 (#4) * ds1 refactor: added test fore some methods; put tests in right order * ds1 refactor: unit tests for all methods * ds1 refactor: fixed build errors * ds1 refactor: lintfix * ds1 refactor: fixed bug with SetWidth, SetHeight methods * ds1 refactor: rename tile_record.go -> tile.go * ds1 refactor: unit test for SetTiles Co-authored-by: M. Sz <mszeptuch@protonmail.com> * renamed some files in d2ds1 * d2ds1.FloorShadow is now private * renamed another file * DS1.Tile() now calls update if dirty * Ds1 refactor: some test improvement (#5) * ds1 refactor: floor_shadow.go: methods Encode, Decode an Hidden are methods of floorShadow * ds1 refactor: test checks, if our methods sets all fields correctly * ds1 refactor: minor bugfixes * i don't remember what's this, but i commit it ;-) * ds1 refactor: reverted some pushed by mistake things Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: test bugs + descriptive errors + SetNumberOfWall/FloorLayers (#6) * ds1 refactor: - removed DS1.layerStreamTypes field - written unit test for setupStreamLayerTypes method - added more descriptive error messages for LoadDS1 (and submethods) * ds1 refactor: added some missing error messages * ds1 refactor: fixed test bugs * ds1 refactor: removed unnecessary c1. and c2. comments in ds1_test errors * ds1 refactor: removed fmt from ds1_test * ds1 refactor: fixed bug with SetTiles test + lintfix * ds1 refactor: SetNumberOfWalls * ds1 refactor: SetTile(s) now changes walls/floors length if neccesary * ds1 refactor: removed unnecessary debugging fmt * ds1 refactor: added substitution layer and object with paths to example data Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: removed npcIndexes field+fixed SetNumberOfWalls bug (#7) * ds1 refactor: removed npcIndexes field it was unnecessary, because described a number of objects with paths to use in encoder, but we can calculate manually * ds1 refactor: fixed set number of (layers) bug * ds1 refactor: SetNumberOf...Layers now returns error if incorrect number given * ds1 refactor: lintfix * ds1 refactor: rename: setupStreamLayerTypes -> GetStreamLayerTypes Co-authored-by: M. Sz <mszeptuch@protonmail.com> * WIP * Ds1 refactor - tests (#10) * ds1 refactor test: example data * added loader check * ds1 refactor: fixed bug, with loading substitutions; added descriptive error message in engine.go:118 and changed Logger.Error with Logger.Fatal * ds1 refactor: fixed loading bug * ds1 refactor: fixed bug when walls wasn't rendered (now we can see only walls :-) Co-authored-by: M. Sz <mszeptuch@protonmail.com> * ds1: floor rendering bugfix * ds1: implemented encode layers method * ds1: implemented encoder * ds1: update of ds1_test Co-authored-by: gravestench <dknuth0101@gmail.com> Co-authored-by: M. Sz <mszeptuch@protonmail.com>
2021-03-24 13:28:02 -04:00
func TestDS1_MarshalUnmarshal(t *testing.T) {
ds1 := exampleData()
Ds1 refactor (#11) * Refactoring d2ds1 * Adding setters/getters so that state management can be maintained internally when the ds1 struct is altered * Adding unit tests for DS1 * unit tests for ds1 (#4) * ds1 refactor: added test fore some methods; put tests in right order * ds1 refactor: unit tests for all methods * ds1 refactor: fixed build errors * ds1 refactor: lintfix * ds1 refactor: fixed bug with SetWidth, SetHeight methods * ds1 refactor: rename tile_record.go -> tile.go * ds1 refactor: unit test for SetTiles Co-authored-by: M. Sz <mszeptuch@protonmail.com> * renamed some files in d2ds1 * d2ds1.FloorShadow is now private * renamed another file * DS1.Tile() now calls update if dirty * Ds1 refactor: some test improvement (#5) * ds1 refactor: floor_shadow.go: methods Encode, Decode an Hidden are methods of floorShadow * ds1 refactor: test checks, if our methods sets all fields correctly * ds1 refactor: minor bugfixes * i don't remember what's this, but i commit it ;-) * ds1 refactor: reverted some pushed by mistake things Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: test bugs + descriptive errors + SetNumberOfWall/FloorLayers (#6) * ds1 refactor: - removed DS1.layerStreamTypes field - written unit test for setupStreamLayerTypes method - added more descriptive error messages for LoadDS1 (and submethods) * ds1 refactor: added some missing error messages * ds1 refactor: fixed test bugs * ds1 refactor: removed unnecessary c1. and c2. comments in ds1_test errors * ds1 refactor: removed fmt from ds1_test * ds1 refactor: fixed bug with SetTiles test + lintfix * ds1 refactor: SetNumberOfWalls * ds1 refactor: SetTile(s) now changes walls/floors length if neccesary * ds1 refactor: removed unnecessary debugging fmt * ds1 refactor: added substitution layer and object with paths to example data Co-authored-by: M. Sz <mszeptuch@protonmail.com> * Ds1 refactor: removed npcIndexes field+fixed SetNumberOfWalls bug (#7) * ds1 refactor: removed npcIndexes field it was unnecessary, because described a number of objects with paths to use in encoder, but we can calculate manually * ds1 refactor: fixed set number of (layers) bug * ds1 refactor: SetNumberOf...Layers now returns error if incorrect number given * ds1 refactor: lintfix * ds1 refactor: rename: setupStreamLayerTypes -> GetStreamLayerTypes Co-authored-by: M. Sz <mszeptuch@protonmail.com> * WIP * Ds1 refactor - tests (#10) * ds1 refactor test: example data * added loader check * ds1 refactor: fixed bug, with loading substitutions; added descriptive error message in engine.go:118 and changed Logger.Error with Logger.Fatal * ds1 refactor: fixed loading bug * ds1 refactor: fixed bug when walls wasn't rendered (now we can see only walls :-) Co-authored-by: M. Sz <mszeptuch@protonmail.com> * ds1: floor rendering bugfix * ds1: implemented encode layers method * ds1: implemented encoder * ds1: update of ds1_test Co-authored-by: gravestench <dknuth0101@gmail.com> Co-authored-by: M. Sz <mszeptuch@protonmail.com>
2021-03-24 13:28:02 -04:00
data := ds1.Marshal()
_, loadErr := Unmarshal(data)
if loadErr != nil {
t.Error(loadErr)
}
}