mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-29 22:56:07 -04:00
bugfix: "insert" bug (#12)
* remove magic 'et' file * ds1 refactor: test for InsertFloors; fixed inserting bug * ds1: global method for getting layers group; fixed Delete.. bug (group var in delete meghod wasn't pointer * ds1: lintfix * ds1: remove ds1.ds1Layers.Orientation * ds1: lintfix * ds1: addet getMaxGroupLen method * ds1: insert now returns if after inserting group will be greater than max number of ... * ds1: add common test for ds1Layers.Insert... Co-authored-by: M. Sz <mszeptuch@protonmail.com>
This commit is contained in:
parent
468f5682ae
commit
41c1d8e874
@ -157,7 +157,6 @@ func (ds1 *DS1) loadBody(stream *d2datautils.StreamReader) error {
|
|||||||
|
|
||||||
for ; numWalls > 0; numWalls-- {
|
for ; numWalls > 0; numWalls-- {
|
||||||
ds1.PushWall(&layer{})
|
ds1.PushWall(&layer{})
|
||||||
ds1.PushOrientation(&layer{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ; numShadows > 0; numShadows-- {
|
for ; numShadows > 0; numShadows-- {
|
||||||
@ -241,8 +240,8 @@ func (ds1 *DS1) loadObjects(br *d2datautils.StreamReader) error {
|
|||||||
|
|
||||||
for objIdx := 0; objIdx < int(numObjects); objIdx++ {
|
for objIdx := 0; objIdx < int(numObjects); objIdx++ {
|
||||||
obj := Object{}
|
obj := Object{}
|
||||||
objType, err := br.ReadInt32()
|
|
||||||
|
|
||||||
|
objType, err := br.ReadInt32()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("reading object's %d type: %v", objIdx, err)
|
return fmt.Errorf("reading object's %d type: %v", objIdx, err)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package d2ds1
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
maxWallLayers = 4
|
maxWallLayers = 4
|
||||||
maxOrientationLayers = 4
|
|
||||||
maxFloorLayers = 2
|
maxFloorLayers = 2
|
||||||
maxShadowLayers = 1
|
maxShadowLayers = 1
|
||||||
maxSubstitutionLayers = 1
|
maxSubstitutionLayers = 1
|
||||||
@ -13,7 +12,6 @@ type layerGroupType int
|
|||||||
const (
|
const (
|
||||||
floorLayerGroup layerGroupType = iota
|
floorLayerGroup layerGroupType = iota
|
||||||
wallLayerGroup
|
wallLayerGroup
|
||||||
orientationLayerGroup
|
|
||||||
shadowLayerGroup
|
shadowLayerGroup
|
||||||
substitutionLayerGroup
|
substitutionLayerGroup
|
||||||
)
|
)
|
||||||
@ -24,7 +22,6 @@ type ds1Layers struct {
|
|||||||
width, height int
|
width, height int
|
||||||
Floors layerGroup
|
Floors layerGroup
|
||||||
Walls layerGroup
|
Walls layerGroup
|
||||||
Orientations layerGroup
|
|
||||||
Shadows layerGroup
|
Shadows layerGroup
|
||||||
Substitutions layerGroup
|
Substitutions layerGroup
|
||||||
}
|
}
|
||||||
@ -38,10 +35,6 @@ func (l *ds1Layers) ensureInit() {
|
|||||||
l.Walls = make(layerGroup, 0)
|
l.Walls = make(layerGroup, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.Orientations == nil {
|
|
||||||
l.Orientations = make(layerGroup, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if l.Shadows == nil {
|
if l.Shadows == nil {
|
||||||
l.Shadows = make(layerGroup, 0)
|
l.Shadows = make(layerGroup, 0)
|
||||||
}
|
}
|
||||||
@ -55,27 +48,14 @@ func (l *ds1Layers) ensureInit() {
|
|||||||
func (l *ds1Layers) cull() {
|
func (l *ds1Layers) cull() {
|
||||||
l.cullNilLayers(floorLayerGroup)
|
l.cullNilLayers(floorLayerGroup)
|
||||||
l.cullNilLayers(wallLayerGroup)
|
l.cullNilLayers(wallLayerGroup)
|
||||||
l.cullNilLayers(orientationLayerGroup)
|
|
||||||
l.cullNilLayers(shadowLayerGroup)
|
l.cullNilLayers(shadowLayerGroup)
|
||||||
l.cullNilLayers(substitutionLayerGroup)
|
l.cullNilLayers(substitutionLayerGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes nil layers of given layer group type
|
// removes nil layers of given layer group type
|
||||||
func (l *ds1Layers) cullNilLayers(t layerGroupType) {
|
func (l *ds1Layers) cullNilLayers(t layerGroupType) {
|
||||||
var group *layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = &l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = &l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = &l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = &l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = &l.Substitutions
|
|
||||||
default:
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +86,6 @@ func (l *ds1Layers) SetSize(w, h int) {
|
|||||||
|
|
||||||
l.enforceSize(floorLayerGroup)
|
l.enforceSize(floorLayerGroup)
|
||||||
l.enforceSize(wallLayerGroup)
|
l.enforceSize(wallLayerGroup)
|
||||||
l.enforceSize(orientationLayerGroup)
|
|
||||||
l.enforceSize(shadowLayerGroup)
|
l.enforceSize(shadowLayerGroup)
|
||||||
l.enforceSize(substitutionLayerGroup)
|
l.enforceSize(substitutionLayerGroup)
|
||||||
}
|
}
|
||||||
@ -115,20 +94,8 @@ func (l *ds1Layers) enforceSize(t layerGroupType) {
|
|||||||
l.ensureInit()
|
l.ensureInit()
|
||||||
l.cull()
|
l.cull()
|
||||||
|
|
||||||
var group *layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = &l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = &l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = &l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = &l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = &l.Substitutions
|
|
||||||
default:
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,29 +127,9 @@ func (l *ds1Layers) push(t layerGroupType, layer *layer) {
|
|||||||
l.ensureInit()
|
l.ensureInit()
|
||||||
l.cull()
|
l.cull()
|
||||||
|
|
||||||
var group *layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
|
||||||
var max int
|
max := getMaxGroupLen(t)
|
||||||
|
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = &l.Floors
|
|
||||||
max = maxFloorLayers
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = &l.Walls
|
|
||||||
max = maxWallLayers
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = &l.Orientations
|
|
||||||
max = maxOrientationLayers
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = &l.Shadows
|
|
||||||
max = maxShadowLayers
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = &l.Substitutions
|
|
||||||
max = maxSubstitutionLayers
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(*group) < max {
|
if len(*group) < max {
|
||||||
*group = append(*group, layer)
|
*group = append(*group, layer)
|
||||||
@ -194,25 +141,13 @@ func (l *ds1Layers) pop(t layerGroupType) *layer {
|
|||||||
l.ensureInit()
|
l.ensureInit()
|
||||||
l.cull()
|
l.cull()
|
||||||
|
|
||||||
var group *layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
var theLayer *layer
|
|
||||||
|
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = &l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = &l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = &l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = &l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = &l.Substitutions
|
|
||||||
default:
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var theLayer *layer
|
||||||
|
|
||||||
// remove last layer of slice and return it
|
// remove last layer of slice and return it
|
||||||
if len(*group) > 0 {
|
if len(*group) > 0 {
|
||||||
lastIdx := len(*group) - 1
|
lastIdx := len(*group) - 1
|
||||||
@ -229,20 +164,8 @@ func (l *ds1Layers) get(t layerGroupType, idx int) *layer {
|
|||||||
l.ensureInit()
|
l.ensureInit()
|
||||||
l.cull()
|
l.cull()
|
||||||
|
|
||||||
var group *layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = &l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = &l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = &l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = &l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = &l.Substitutions
|
|
||||||
default:
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,30 +184,22 @@ func (l *ds1Layers) insert(t layerGroupType, idx int, newLayer *layer) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var group layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = l.Substitutions
|
|
||||||
default:
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(group) == 0 {
|
if len(*group)+1 > getMaxGroupLen(t) {
|
||||||
group = append(group, newLayer) // nolint:staticcheck // we possibly use group later
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx > len(group)-1 {
|
if len(*group) == 0 {
|
||||||
idx = len(group) - 1
|
*group = append(*group, newLayer) // nolint:staticcheck // we possibly use group later
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if l := len(*group) - 1; idx > l {
|
||||||
|
idx = l
|
||||||
}
|
}
|
||||||
|
|
||||||
// example:
|
// example:
|
||||||
@ -292,36 +207,24 @@ func (l *ds1Layers) insert(t layerGroupType, idx int, newLayer *layer) {
|
|||||||
// idx=1
|
// idx=1
|
||||||
// newLayer=c
|
// newLayer=c
|
||||||
// existing layerGroup is [a, b]
|
// existing layerGroup is [a, b]
|
||||||
group = append(group, group[idx:]...) // [a, b] becomes [a, b, b]
|
newGroup := append((*group)[:idx], append([]*layer{newLayer}, (*group)[idx:]...)...)
|
||||||
group[idx] = newLayer // [a, b, b] becomes [a, c, b]
|
*group = newGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ds1Layers) delete(t layerGroupType, idx int) {
|
func (l *ds1Layers) delete(t layerGroupType, idx int) {
|
||||||
l.ensureInit()
|
l.ensureInit()
|
||||||
l.cull()
|
l.cull()
|
||||||
|
|
||||||
var group layerGroup
|
group := l.getLayersGroup(t)
|
||||||
|
if group == nil {
|
||||||
switch t {
|
|
||||||
case floorLayerGroup:
|
|
||||||
group = l.Floors
|
|
||||||
case wallLayerGroup:
|
|
||||||
group = l.Walls
|
|
||||||
case orientationLayerGroup:
|
|
||||||
group = l.Orientations
|
|
||||||
case shadowLayerGroup:
|
|
||||||
group = l.Shadows
|
|
||||||
case substitutionLayerGroup:
|
|
||||||
group = l.Substitutions
|
|
||||||
default:
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if idx >= len(group) || idx < 0 {
|
if idx >= len(*group) || idx < 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group[idx] = nil
|
(*group)[idx] = nil
|
||||||
|
|
||||||
l.cull()
|
l.cull()
|
||||||
}
|
}
|
||||||
@ -368,27 +271,6 @@ func (l *ds1Layers) DeleteWall(idx int) {
|
|||||||
l.delete(wallLayerGroup, idx)
|
l.delete(wallLayerGroup, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ds1Layers) GetOrientation(idx int) *layer {
|
|
||||||
return l.get(orientationLayerGroup, idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ds1Layers) PushOrientation(orientation *layer) *ds1Layers {
|
|
||||||
l.push(orientationLayerGroup, orientation)
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ds1Layers) PopOrientation() *layer {
|
|
||||||
return l.pop(orientationLayerGroup)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ds1Layers) InsertOrientation(idx int, newOrientation *layer) {
|
|
||||||
l.insert(orientationLayerGroup, idx, newOrientation)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ds1Layers) DeleteOrientation(idx int) {
|
|
||||||
l.delete(orientationLayerGroup, idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ds1Layers) GetShadow(idx int) *layer {
|
func (l *ds1Layers) GetShadow(idx int) *layer {
|
||||||
return l.get(shadowLayerGroup, idx)
|
return l.get(shadowLayerGroup, idx)
|
||||||
}
|
}
|
||||||
@ -424,9 +306,43 @@ func (l *ds1Layers) PopSubstitution() *layer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *ds1Layers) InsertSubstitution(idx int, newSubstitution *layer) {
|
func (l *ds1Layers) InsertSubstitution(idx int, newSubstitution *layer) {
|
||||||
l.insert(shadowLayerGroup, idx, newSubstitution)
|
l.insert(substitutionLayerGroup, idx, newSubstitution)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ds1Layers) DeleteSubstitution(idx int) {
|
func (l *ds1Layers) DeleteSubstitution(idx int) {
|
||||||
l.delete(shadowLayerGroup, idx)
|
l.delete(shadowLayerGroup, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *ds1Layers) getLayersGroup(t layerGroupType) (group *layerGroup) {
|
||||||
|
switch t {
|
||||||
|
case floorLayerGroup:
|
||||||
|
group = &l.Floors
|
||||||
|
case wallLayerGroup:
|
||||||
|
group = &l.Walls
|
||||||
|
case shadowLayerGroup:
|
||||||
|
group = &l.Shadows
|
||||||
|
case substitutionLayerGroup:
|
||||||
|
group = &l.Substitutions
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMaxGroupLen(t layerGroupType) (max int) {
|
||||||
|
switch t {
|
||||||
|
case floorLayerGroup:
|
||||||
|
max = maxFloorLayers
|
||||||
|
case wallLayerGroup:
|
||||||
|
max = maxWallLayers
|
||||||
|
case shadowLayerGroup:
|
||||||
|
max = maxShadowLayers
|
||||||
|
case substitutionLayerGroup:
|
||||||
|
max = maxSubstitutionLayers
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
|
|
||||||
func Test_ds1Layers_DeleteFloor(t *testing.T) {}
|
func Test_ds1Layers_DeleteFloor(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_DeleteOrientation(t *testing.T) {}
|
|
||||||
|
|
||||||
func Test_ds1Layers_DeleteShadow(t *testing.T) {}
|
func Test_ds1Layers_DeleteShadow(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_DeleteSubstitution(t *testing.T) {}
|
func Test_ds1Layers_DeleteSubstitution(t *testing.T) {}
|
||||||
@ -16,28 +14,79 @@ func Test_ds1Layers_DeleteWall(t *testing.T) {}
|
|||||||
|
|
||||||
func Test_ds1Layers_GetFloor(t *testing.T) {}
|
func Test_ds1Layers_GetFloor(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_GetOrientation(t *testing.T) {}
|
|
||||||
|
|
||||||
func Test_ds1Layers_GetShadow(t *testing.T) {}
|
func Test_ds1Layers_GetShadow(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_GetSubstitution(t *testing.T) {}
|
func Test_ds1Layers_GetSubstitution(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_GetWall(t *testing.T) {}
|
func Test_ds1Layers_GetWall(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_InsertFloor(t *testing.T) {}
|
func Test_ds1Layers_Insert(t *testing.T) {
|
||||||
|
t.Run("Floors", func(t *testing.T) {
|
||||||
|
ds1LayersInsert(t, floorLayerGroup)
|
||||||
|
})
|
||||||
|
t.Run("Walls", func(t *testing.T) {
|
||||||
|
ds1LayersInsert(t, wallLayerGroup)
|
||||||
|
})
|
||||||
|
t.Run("Shadows", func(t *testing.T) {
|
||||||
|
ds1LayersInsert(t, shadowLayerGroup)
|
||||||
|
})
|
||||||
|
t.Run("Substitution", func(t *testing.T) {
|
||||||
|
ds1LayersInsert(t, substitutionLayerGroup)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func Test_ds1Layers_InsertOrientation(t *testing.T) {}
|
func ds1LayersInsert(t *testing.T, lt layerGroupType) {
|
||||||
|
ds1 := DS1{}
|
||||||
|
|
||||||
func Test_ds1Layers_InsertShadow(t *testing.T) {}
|
layers := make([]*layer, getMaxGroupLen(lt)+1)
|
||||||
|
|
||||||
func Test_ds1Layers_InsertSubstitution(t *testing.T) {}
|
for i := range layers {
|
||||||
|
i := i
|
||||||
|
layers[i] = &layer{}
|
||||||
|
layers[i].tiles = make(tileGrid, 1)
|
||||||
|
layers[i].tiles[0] = make(tileRow, 1)
|
||||||
|
layers[i].SetSize(3, 3)
|
||||||
|
layers[i].tiles[0][0].Prop1 = byte(i)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_ds1Layers_InsertWall(t *testing.T) {}
|
ds1.ds1Layers = &ds1Layers{}
|
||||||
|
|
||||||
|
var insert func(i int)
|
||||||
|
|
||||||
|
group := ds1.getLayersGroup(lt)
|
||||||
|
|
||||||
|
switch lt {
|
||||||
|
case floorLayerGroup:
|
||||||
|
insert = func(i int) { ds1.InsertFloor(0, layers[i]) }
|
||||||
|
case wallLayerGroup:
|
||||||
|
insert = func(i int) { ds1.InsertWall(0, layers[i]) }
|
||||||
|
case shadowLayerGroup:
|
||||||
|
insert = func(i int) { ds1.InsertShadow(0, layers[i]) }
|
||||||
|
case substitutionLayerGroup:
|
||||||
|
insert = func(i int) { ds1.InsertSubstitution(0, layers[i]) }
|
||||||
|
default:
|
||||||
|
t.Fatal("unknown layer type given")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range layers {
|
||||||
|
insert(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(*group) != getMaxGroupLen(lt) {
|
||||||
|
t.Fatal("unexpected floor len after setting")
|
||||||
|
}
|
||||||
|
|
||||||
|
idx := 0
|
||||||
|
for i := len(layers) - 2; i > 0; i-- {
|
||||||
|
if (*group)[idx].tiles[0][0].Prop1 != byte(i) {
|
||||||
|
t.Fatal("unexpected tile inserted")
|
||||||
|
}
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_ds1Layers_PopFloor(t *testing.T) {}
|
func Test_ds1Layers_PopFloor(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_PopOrientation(t *testing.T) {}
|
|
||||||
|
|
||||||
func Test_ds1Layers_PopShadow(t *testing.T) {}
|
func Test_ds1Layers_PopShadow(t *testing.T) {}
|
||||||
|
|
||||||
func Test_ds1Layers_PopSubstitution(t *testing.T) {}
|
func Test_ds1Layers_PopSubstitution(t *testing.T) {}
|
||||||
@ -53,10 +102,6 @@ func Test_ds1Layers_Push(t *testing.T) {
|
|||||||
ds1layerTest(wallLayerGroup, t)
|
ds1layerTest(wallLayerGroup, t)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Orientation", func(t *testing.T) {
|
|
||||||
ds1layerTest(orientationLayerGroup, t)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Shadow", func(t *testing.T) {
|
t.Run("Shadow", func(t *testing.T) {
|
||||||
ds1layerTest(shadowLayerGroup, t)
|
ds1layerTest(shadowLayerGroup, t)
|
||||||
})
|
})
|
||||||
@ -106,11 +151,6 @@ func ds1layerTest(lt layerGroupType, t *testing.T) { //nolint:funlen // no biggi
|
|||||||
get = layers.GetWall
|
get = layers.GetWall
|
||||||
max = maxWallLayers
|
max = maxWallLayers
|
||||||
group = &layers.Walls
|
group = &layers.Walls
|
||||||
case orientationLayerGroup:
|
|
||||||
push = func() { layers.PushOrientation(&layer{}) }
|
|
||||||
get = layers.GetOrientation
|
|
||||||
max = maxOrientationLayers
|
|
||||||
group = &layers.Orientations
|
|
||||||
case shadowLayerGroup:
|
case shadowLayerGroup:
|
||||||
push = func() { layers.PushShadow(&layer{}) }
|
push = func() { layers.PushShadow(&layer{}) }
|
||||||
get = layers.GetShadow
|
get = layers.GetShadow
|
||||||
|
@ -68,7 +68,6 @@ type Tile struct {
|
|||||||
func (mr *Stamp) Tile(x, y int) *Tile {
|
func (mr *Stamp) Tile(x, y int) *Tile {
|
||||||
t := &Tile{
|
t := &Tile{
|
||||||
Walls: make([]d2ds1.Tile, len(mr.ds1.Walls)),
|
Walls: make([]d2ds1.Tile, len(mr.ds1.Walls)),
|
||||||
Orientations: make([]d2ds1.Tile, len(mr.ds1.Orientations)),
|
|
||||||
Floors: make([]d2ds1.Tile, len(mr.ds1.Floors)),
|
Floors: make([]d2ds1.Tile, len(mr.ds1.Floors)),
|
||||||
Shadows: make([]d2ds1.Tile, len(mr.ds1.Shadows)),
|
Shadows: make([]d2ds1.Tile, len(mr.ds1.Shadows)),
|
||||||
Substitutions: make([]d2ds1.Tile, len(mr.ds1.Substitutions)),
|
Substitutions: make([]d2ds1.Tile, len(mr.ds1.Substitutions)),
|
||||||
@ -78,10 +77,6 @@ func (mr *Stamp) Tile(x, y int) *Tile {
|
|||||||
t.Walls[idx] = *mr.ds1.Walls[idx].Tile(x, y)
|
t.Walls[idx] = *mr.ds1.Walls[idx].Tile(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx := range mr.ds1.Orientations {
|
|
||||||
t.Orientations[idx] = *mr.ds1.Orientations[idx].Tile(x, y)
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx := range mr.ds1.Floors {
|
for idx := range mr.ds1.Floors {
|
||||||
t.Floors[idx] = *mr.ds1.Floors[idx].Tile(x, y)
|
t.Floors[idx] = *mr.ds1.Floors[idx].Tile(x, y)
|
||||||
}
|
}
|
||||||
@ -147,7 +142,6 @@ func (mr *Stamp) Entities(tileOffsetX, tileOffsetY int) []d2interface.MapEntity
|
|||||||
// nolint:gomnd // constant
|
// nolint:gomnd // constant
|
||||||
entity, err := mr.entity.NewObject((tileOffsetX*5)+object.X,
|
entity, err := mr.entity.NewObject((tileOffsetX*5)+object.X,
|
||||||
(tileOffsetY*5)+object.Y, objectRecord, d2resource.PaletteUnits)
|
(tileOffsetY*5)+object.Y, objectRecord, d2resource.PaletteUnits)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
73
et
73
et
@ -1,73 +0,0 @@
|
|||||||
[1mdiff --git a/d2common/d2fileformats/d2ds1/ds1_test.go b/d2common/d2fileformats/d2ds1/ds1_test.go[m
|
|
||||||
[1mindex 23035a50..d17527f0 100644[m
|
|
||||||
[1m--- a/d2common/d2fileformats/d2ds1/ds1_test.go[m
|
|
||||||
[1m+++ b/d2common/d2fileformats/d2ds1/ds1_test.go[m
|
|
||||||
[36m@@ -575,6 +575,24 @@[m [mfunc TestDS1_SetNumberOfFloors(t *testing.T) {[m
|
|
||||||
if err := testIfRestorable(ds1, test); err != nil {[m
|
|
||||||
t.Errorf("unable to restore: %v", err)[m
|
|
||||||
}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m [32mnewNumber = 10[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m [32mds1.SetNumberOfFloorLayers(newNumber)[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m [32mtest = func(ds1 *DS1) {[m
|
|
||||||
[32m+[m [32mif len(ds1.tiles[0][0].Floors) != int(newNumber) {[m
|
|
||||||
[32m+[m [32mt.Fatal("unexpected floors length set")[m
|
|
||||||
[32m+[m [32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m [32mif ds1.numberOfFloorLayers != newNumber {[m
|
|
||||||
[32m+[m [32mt.Fatal("unexpected floors length set")[m
|
|
||||||
[32m+[m [32m}[m
|
|
||||||
[32m+[m [32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m [32mif err := testIfRestorable(ds1, test); err != nil {[m
|
|
||||||
[32m+[m [32mt.Errorf("unable to restore: %v", err)[m
|
|
||||||
[32m+[m [32m}[m
|
|
||||||
}[m
|
|
||||||
[m
|
|
||||||
func TestDS1_NumberOfShadowLayers(t *testing.T) {[m
|
|
||||||
[1mdiff --git a/d2common/d2fileformats/d2ds1/layers.go b/d2common/d2fileformats/d2ds1/layers.go[m
|
|
||||||
[1mindex f69ef7f1..b0488a34 100644[m
|
|
||||||
[1m--- a/d2common/d2fileformats/d2ds1/layers.go[m
|
|
||||||
[1m+++ b/d2common/d2fileformats/d2ds1/layers.go[m
|
|
||||||
[36m@@ -1 +1,39 @@[m
|
|
||||||
package d2ds1[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mconst ([m
|
|
||||||
[32m+[m [32mmaxWalls = 4[m
|
|
||||||
[32m+[m[32m)[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mtype WallLayer [][]*Wall[m
|
|
||||||
[32m+[m[32mtype FloorLayer [][]*Floor[m
|
|
||||||
[32m+[m[32mtype ShadowLayer [][]*Shadow[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mtype layers struct {[m
|
|
||||||
[32m+[m [32mWalls []WallLayer[m
|
|
||||||
[32m+[m [32mFloors []FloorLayer[m
|
|
||||||
[32m+[m [32mShadows []ShadowLayer[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PushWallLayer() {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PopWallLayer() WallLayer {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PushFloorLayer() {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PopFloorLayer() FloorLayer {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PushShadowLayer() {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32mfunc (l *layers) PopShadowLayer() ShadowLayer {[m
|
|
||||||
[32m+[m
|
|
||||||
[32m+[m[32m}[m
|
|
Loading…
Reference in New Issue
Block a user