From 91209fd5406d1135b5b5ea64db787a5db6c25dd2 Mon Sep 17 00:00:00 2001 From: gravestench Date: Tue, 30 Mar 2021 11:04:25 -0700 Subject: [PATCH] add more ds1version methods --- d2common/d2fileformats/d2ds1/ds1.go | 8 ++++---- d2common/d2fileformats/d2ds1/ds1_version.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/d2common/d2fileformats/d2ds1/ds1.go b/d2common/d2fileformats/d2ds1/ds1.go index 8635c416..d78d553d 100644 --- a/d2common/d2fileformats/d2ds1/ds1.go +++ b/d2common/d2fileformats/d2ds1/ds1.go @@ -340,7 +340,7 @@ func (ds1 *DS1) loadSubstitutions(br *d2datautils.StreamReader) error { func (ds1 *DS1) getLayerSchema() []layerStreamType { var layerStream []layerStreamType - if ds1.version < v4 { + if ds1.version.hasStandardLayers() { layerStream = []layerStreamType{ layerStreamWall1, layerStreamFloor1, @@ -391,7 +391,7 @@ func (ds1 *DS1) getLayerSchema() []layerStreamType { func (ds1 *DS1) loadNPCs(br *d2datautils.StreamReader) error { var err error - if ds1.version < v14 { + if !ds1.version.specifiesNPCs() { return nil } @@ -432,7 +432,7 @@ func (ds1 *DS1) loadNPCs(br *d2datautils.StreamReader) error { return fmt.Errorf("loading paths for NPC %d: %v", npcIdx, err) } } else { - if ds1.version >= v15 { + if ds1.version.specifiesNPCActions() { br.SkipBytes(int(numPaths) * 3) //nolint:gomnd // Unknown data } else { br.SkipBytes(int(numPaths) * 2) //nolint:gomnd // Unknown data @@ -463,7 +463,7 @@ func (ds1 *DS1) loadNpcPaths(br *d2datautils.StreamReader, objIdx, numPaths int) newPath.Position = d2vector.NewPosition(float64(px), float64(py)) - if ds1.version >= v15 { + if ds1.version.specifiesNPCActions() { action, err := br.ReadInt32() if err != nil { return fmt.Errorf("reading action for path %d: %v", pathIdx, err) diff --git a/d2common/d2fileformats/d2ds1/ds1_version.go b/d2common/d2fileformats/d2ds1/ds1_version.go index b424c28d..94d9afa4 100644 --- a/d2common/d2fileformats/d2ds1/ds1_version.go +++ b/d2common/d2fileformats/d2ds1/ds1_version.go @@ -36,6 +36,11 @@ func (v ds1version) specifiesSubstitutionType() bool { return v >= v10 } +func (v ds1version) hasStandardLayers() bool { + // 1 of each layer, very simple ds1 + return v < v4 +} + func (v ds1version) specifiesWalls() bool { // just after header, specifies number of Walls return v >= v4 @@ -57,3 +62,11 @@ func (v ds1version) hasObjects() bool { func (v ds1version) hasSubstitutions() bool { return v >= v12 } + +func (v ds1version) specifiesNPCs() bool { + return v > v14 +} + +func (v ds1version) specifiesNPCActions() bool { + return v > v15 +}