Trim map based on trailer data
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user