mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-12 12:26:31 -05:00
Merge branch 'd2ds1_refactor' into d2ds1_refactor_wip
This commit is contained in:
commit
468f5682ae
@ -38,7 +38,7 @@ func (v *StreamWriter) PushBytes(b ...byte) {
|
||||
// use another Push... method, bits'll not be pushed
|
||||
func (v *StreamWriter) PushBit(b bool) {
|
||||
if b {
|
||||
v.bitCache |= (1 << v.bitOffset)
|
||||
v.bitCache |= 1 << v.bitOffset
|
||||
}
|
||||
v.bitOffset++
|
||||
|
||||
|
@ -232,7 +232,7 @@ func (ad *AnimationData) Marshal() []byte {
|
||||
recordIdx := 0
|
||||
|
||||
// numberOfEntries is a number of entries in all map indexes
|
||||
var numberOfEntries int = 0
|
||||
var numberOfEntries = 0
|
||||
|
||||
for i := 0; i < len(keys); i++ {
|
||||
numberOfEntries += len(ad.entries[keys[i]])
|
||||
|
@ -54,79 +54,14 @@ func Unmarshal(fileData []byte) (*DS1, error) {
|
||||
func (ds1 *DS1) Unmarshal(fileData []byte) (*DS1, error) {
|
||||
ds1.ds1Layers = &ds1Layers{}
|
||||
|
||||
br := d2datautils.CreateStreamReader(fileData)
|
||||
stream := d2datautils.CreateStreamReader(fileData)
|
||||
|
||||
var err error
|
||||
|
||||
var numWalls, numFloors, numShadows, numSubstitutions int32
|
||||
|
||||
numFloors = defaultNumFloors
|
||||
numShadows = defaultNumShadows
|
||||
numSubstitutions = defaultNumSubstitutions
|
||||
|
||||
err = ds1.loadHeader(br)
|
||||
if err != nil {
|
||||
if err := ds1.loadHeader(stream); err != nil {
|
||||
return nil, fmt.Errorf("loading header: %v", err)
|
||||
}
|
||||
|
||||
if ds1.version.hasUnknown1Bytes() {
|
||||
ds1.unknown1, err = br.ReadBytes(unknown1BytesCount)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading unknown1: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if ds1.version.specifiesWalls() {
|
||||
numWalls, err = br.ReadInt32()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading wall number: %v", err)
|
||||
}
|
||||
|
||||
if ds1.version.specifiesFloors() {
|
||||
numFloors, err = br.ReadInt32()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading number of Floors: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ; numWalls > 0; numWalls-- {
|
||||
ds1.PushWall(&layer{})
|
||||
ds1.PushOrientation(&layer{})
|
||||
}
|
||||
|
||||
for ; numShadows > 0; numShadows-- {
|
||||
ds1.PushShadow(&layer{})
|
||||
}
|
||||
|
||||
for ; numFloors > 0; numFloors-- {
|
||||
ds1.PushFloor(&layer{})
|
||||
}
|
||||
|
||||
for ; numSubstitutions > 0; numSubstitutions-- {
|
||||
ds1.PushSubstitution(&layer{})
|
||||
}
|
||||
|
||||
ds1.SetSize(ds1.width, ds1.height)
|
||||
|
||||
err = ds1.loadLayerStreams(br)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loading layer streams: %v", err)
|
||||
}
|
||||
|
||||
err = ds1.loadObjects(br)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loading Objects: %v", err)
|
||||
}
|
||||
|
||||
err = ds1.loadSubstitutions(br)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loading Substitutions: %v", err)
|
||||
}
|
||||
|
||||
err = ds1.loadNPCs(br)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("loading npc's: %v", err)
|
||||
if err := ds1.loadBody(stream); err != nil {
|
||||
return nil, fmt.Errorf("loading body: %v", err)
|
||||
}
|
||||
|
||||
return ds1, nil
|
||||
@ -188,6 +123,76 @@ func (ds1 *DS1) loadHeader(br *d2datautils.StreamReader) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds1 *DS1) loadBody(stream *d2datautils.StreamReader) error {
|
||||
var numWalls, numFloors, numShadows, numSubstitutions int32
|
||||
|
||||
numFloors = defaultNumFloors
|
||||
numShadows = defaultNumShadows
|
||||
numSubstitutions = defaultNumSubstitutions
|
||||
|
||||
if ds1.version.hasUnknown1Bytes() {
|
||||
var err error
|
||||
|
||||
ds1.unknown1, err = stream.ReadBytes(unknown1BytesCount)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading unknown1: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if ds1.version.specifiesWalls() {
|
||||
var err error
|
||||
|
||||
numWalls, err = stream.ReadInt32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading wall number: %v", err)
|
||||
}
|
||||
|
||||
if ds1.version.specifiesFloors() {
|
||||
numFloors, err = stream.ReadInt32()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading number of Floors: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ; numWalls > 0; numWalls-- {
|
||||
ds1.PushWall(&layer{})
|
||||
ds1.PushOrientation(&layer{})
|
||||
}
|
||||
|
||||
for ; numShadows > 0; numShadows-- {
|
||||
ds1.PushShadow(&layer{})
|
||||
}
|
||||
|
||||
for ; numFloors > 0; numFloors-- {
|
||||
ds1.PushFloor(&layer{})
|
||||
}
|
||||
|
||||
for ; numSubstitutions > 0; numSubstitutions-- {
|
||||
ds1.PushSubstitution(&layer{})
|
||||
}
|
||||
|
||||
ds1.SetSize(ds1.width, ds1.height)
|
||||
|
||||
if err := ds1.loadLayerStreams(stream); err != nil {
|
||||
return fmt.Errorf("loading layer streams: %v", err)
|
||||
}
|
||||
|
||||
if err := ds1.loadObjects(stream); err != nil {
|
||||
return fmt.Errorf("loading Objects: %v", err)
|
||||
}
|
||||
|
||||
if err := ds1.loadSubstitutions(stream); err != nil {
|
||||
return fmt.Errorf("loading Substitutions: %v", err)
|
||||
}
|
||||
|
||||
if err := ds1.loadNPCs(stream); err != nil {
|
||||
return fmt.Errorf("loading npc's: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ds1 *DS1) loadFileList(br *d2datautils.StreamReader) error {
|
||||
if !ds1.version.hasFileList() {
|
||||
return nil
|
||||
@ -614,8 +619,8 @@ func (ds1 *DS1) encodeLayers(sw *d2datautils.StreamWriter) {
|
||||
layerStreamTypes := ds1.getLayerSchema()
|
||||
|
||||
for _, layerStreamType := range layerStreamTypes {
|
||||
for y := 0; y < int(ds1.height); y++ {
|
||||
for x := 0; x < int(ds1.width); x++ {
|
||||
for y := 0; y < ds1.height; y++ {
|
||||
for x := 0; x < ds1.width; x++ {
|
||||
dw := uint32(0)
|
||||
|
||||
switch layerStreamType {
|
||||
|
@ -46,23 +46,23 @@ func Test_ds1Layers_PopWall(t *testing.T) {}
|
||||
|
||||
func Test_ds1Layers_Push(t *testing.T) {
|
||||
t.Run("Floor", func(t *testing.T) {
|
||||
test_ds1Layers_PushLayer(floorLayerGroup, t)
|
||||
ds1layerTest(floorLayerGroup, t)
|
||||
})
|
||||
|
||||
t.Run("Wall", func(t *testing.T) {
|
||||
test_ds1Layers_PushLayer(wallLayerGroup, t)
|
||||
ds1layerTest(wallLayerGroup, t)
|
||||
})
|
||||
|
||||
t.Run("Orientation", func(t *testing.T) {
|
||||
test_ds1Layers_PushLayer(orientationLayerGroup, t)
|
||||
ds1layerTest(orientationLayerGroup, t)
|
||||
})
|
||||
|
||||
t.Run("Shadow", func(t *testing.T) {
|
||||
test_ds1Layers_PushLayer(shadowLayerGroup, t)
|
||||
ds1layerTest(shadowLayerGroup, t)
|
||||
})
|
||||
|
||||
t.Run("Substitution", func(t *testing.T) {
|
||||
test_ds1Layers_PushLayer(substitutionLayerGroup, t)
|
||||
ds1layerTest(substitutionLayerGroup, t)
|
||||
})
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func Test_ds1Layers_Push(t *testing.T) {
|
||||
// when we push a layer, we expect an increment, and when we push a bunch of times,
|
||||
// we expect to never exceed the max. we also expect to be able to retrieve a non-nil
|
||||
// layer after we push.
|
||||
func test_ds1Layers_PushLayer(lt layerGroupType, t *testing.T) {
|
||||
func ds1layerTest(lt layerGroupType, t *testing.T) { //nolint:funlen // no biggie
|
||||
layers := &ds1Layers{}
|
||||
|
||||
// we need to set up some shit to handle the test in a generic way
|
||||
@ -139,14 +139,5 @@ func test_ds1Layers_PushLayer(lt layerGroupType, t *testing.T) {
|
||||
push()
|
||||
push()
|
||||
push()
|
||||
push()
|
||||
check(max)
|
||||
}
|
||||
|
||||
func test_ds1Layers_PopLayer(lt layerGroupType, t *testing.T) {}
|
||||
|
||||
func test_ds1Layers_InsertLayer(lt layerGroupType, t *testing.T) {}
|
||||
|
||||
func test_ds1Layers_DeleteLayer(lt layerGroupType, t *testing.T) {}
|
||||
|
||||
func test_ds1Layers_GetLayer(lt layerGroupType, t *testing.T) {}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2path"
|
||||
)
|
||||
|
||||
func exampleData() *DS1 {
|
||||
func exampleData() *DS1 { //nolint:funlen // not a big deal if this is long func
|
||||
exampleFloor1 := Tile{
|
||||
// common fields
|
||||
tileCommonFields: tileCommonFields{
|
||||
|
@ -4,17 +4,17 @@ type ds1version int
|
||||
|
||||
const (
|
||||
v3 ds1version = 3
|
||||
v4 = 4
|
||||
v7 = 7
|
||||
v8 = 8
|
||||
v9 = 9
|
||||
v10 = 10
|
||||
v12 = 12
|
||||
v13 = 13
|
||||
v14 = 14
|
||||
v15 = 15
|
||||
v16 = 16
|
||||
v18 = 18
|
||||
v4 ds1version = 4
|
||||
v7 ds1version = 7
|
||||
v8 ds1version = 8
|
||||
v9 ds1version = 9
|
||||
v10 ds1version = 10
|
||||
v12 ds1version = 12
|
||||
v13 ds1version = 13
|
||||
v14 ds1version = 14
|
||||
v15 ds1version = 15
|
||||
v16 ds1version = 16
|
||||
v18 ds1version = 18
|
||||
)
|
||||
|
||||
func (v ds1version) hasUnknown1Bytes() bool {
|
||||
|
@ -58,9 +58,9 @@ type tileWallFields struct {
|
||||
// Tile represents a tile record in a DS1 file.
|
||||
type Tile struct {
|
||||
tileCommonFields
|
||||
tileFloorShadowFields
|
||||
tileSubstitutionFields
|
||||
tileWallFields
|
||||
tileFloorShadowFields
|
||||
}
|
||||
|
||||
// Hidden returns if wall is hidden
|
||||
|
@ -388,7 +388,7 @@ func (box *Box) setupTitle(sectionHeight int) error {
|
||||
}
|
||||
|
||||
func (box *Box) setupOptions(sectionHeight int) error {
|
||||
box.contentLayout.SetSize(box.width, (box.height - sectionHeight))
|
||||
box.contentLayout.SetSize(box.width, box.height-sectionHeight)
|
||||
|
||||
if !box.disableBorder {
|
||||
cornerLeft, err := box.uiManager.NewSprite(d2resource.BoxPieces, d2resource.PaletteSky)
|
||||
|
@ -54,11 +54,13 @@ func (mr *Stamp) RegionPath() string {
|
||||
return mr.regionPath
|
||||
}
|
||||
|
||||
// Tile represents a map tile, which can have a variable amount of floors, walls, shadows as layers.
|
||||
// Typically, there will be an Orientation layer for each wall layer.
|
||||
type Tile struct {
|
||||
Walls []d2ds1.Tile
|
||||
Orientations []d2ds1.Tile
|
||||
Floors []d2ds1.Tile
|
||||
Shadows []d2ds1.Tile
|
||||
Walls []d2ds1.Tile
|
||||
Orientations []d2ds1.Tile
|
||||
Floors []d2ds1.Tile
|
||||
Shadows []d2ds1.Tile
|
||||
Substitutions []d2ds1.Tile
|
||||
}
|
||||
|
||||
|
4
main.go
4
main.go
@ -8,11 +8,11 @@ import (
|
||||
|
||||
// GitBranch is set by the CI build process to the name of the branch
|
||||
//nolint:gochecknoglobals // This is filled in by the build system
|
||||
var GitBranch string = "local"
|
||||
var GitBranch = "local"
|
||||
|
||||
// GitCommit is set by the CI build process to the commit hash
|
||||
//nolint:gochecknoglobals // This is filled in by the build system
|
||||
var GitCommit string = "build"
|
||||
var GitCommit = "build"
|
||||
|
||||
func main() {
|
||||
log.SetFlags(log.Lshortfile)
|
||||
|
Loading…
Reference in New Issue
Block a user