From 494fe4eb0202846fc10a2229b434d07848ad5ef9 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 8 Jun 2020 00:53:45 +0100 Subject: [PATCH] Trim map based on trailer data --- internal/maps/maps.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/internal/maps/maps.go b/internal/maps/maps.go index ac53311..9dd461b 100644 --- a/internal/maps/maps.go +++ b/internal/maps/maps.go @@ -72,18 +72,6 @@ type Thingy struct {} type Thingies []Thingy -func (h Header) Width() int { - return MaxWidth -} - -func (h Header) Length() int { - return MaxLength -} - -func (h Header) Height() int { - return MaxHeight -} - func (h Header) MapSetName() string { idx := bytes.IndexByte(h.SetName[:], 0) if idx < 0 { @@ -233,10 +221,10 @@ type GameMap struct { func (m *GameMap) Rect() image.Rectangle { return image.Rect( - int(0), - int(0), - int(m.Width()-1), - int(m.Length()-1), + int(m.TrailerHeader.MinWidth), + int(m.TrailerHeader.MinLength), + int(m.TrailerHeader.MaxWidth-1), + int(m.TrailerHeader.MaxLength-1), ) } @@ -343,6 +331,11 @@ func loadMapFile(filename string) (*GameMap, error) { return nil, fmt.Errorf("Error parsing cells for %s: %v", filename, err) } + // no gzip.SeekReader, so discard unread trailer bytes for now + if _, err := io.CopyN(ioutil.Discard, zr, int64(3320-2)); err != nil { // observed + return nil, err + } + if err := binary.Read(zr, binary.LittleEndian, &out.TrailerHeader); err != nil { return nil, fmt.Errorf("Error parsing trailer header for %s: %v", filename, err) }