Internalise the map rect
This commit is contained in:
@@ -47,12 +47,7 @@ func (a *AssetStore) Map(name string) (*Map, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := &Map{
|
m := &Map{
|
||||||
Rect: image.Rect(
|
Rect: raw.Rect(),
|
||||||
int(raw.MinWidth),
|
|
||||||
int(raw.MinLength),
|
|
||||||
int(raw.MaxWidth),
|
|
||||||
int(raw.MaxLength),
|
|
||||||
),
|
|
||||||
assets: a,
|
assets: a,
|
||||||
raw: raw,
|
raw: raw,
|
||||||
set: set,
|
set: set,
|
||||||
@@ -65,8 +60,8 @@ func (a *AssetStore) Map(name string) (*Map, error) {
|
|||||||
|
|
||||||
func (m *Map) LoadSprites() error {
|
func (m *Map) LoadSprites() error {
|
||||||
// Eager load the sprites we use
|
// Eager load the sprites we use
|
||||||
for x := m.Rect.Min.X; x <= m.Rect.Max.X; x++ {
|
for x := m.Rect.Min.X; x < m.Rect.Max.X; x++ {
|
||||||
for y := m.Rect.Min.Y; y <= m.Rect.Max.Y; y++ {
|
for y := m.Rect.Min.Y; y < m.Rect.Max.Y; y++ {
|
||||||
for z := 0; z < maps.MaxHeight; z++ {
|
for z := 0; z < maps.MaxHeight; z++ {
|
||||||
if _, err := m.SpritesForCell(x, y, z); err != nil {
|
if _, err := m.SpritesForCell(x, y, z); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@@ -173,6 +174,15 @@ type GameMap struct {
|
|||||||
Text string
|
Text string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *GameMap) Rect() image.Rectangle {
|
||||||
|
return image.Rect(
|
||||||
|
int(m.Header.MinWidth),
|
||||||
|
int(m.Header.MinLength),
|
||||||
|
int(m.Header.MaxWidth),
|
||||||
|
int(m.Header.MaxLength),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// A game map contains a .txt and a .map. If they're in the same directory,
|
// A game map contains a .txt and a .map. If they're in the same directory,
|
||||||
// just pass the directory + basename to load both
|
// just pass the directory + basename to load both
|
||||||
func LoadGameMap(prefix string) (*GameMap, error) {
|
func LoadGameMap(prefix string) (*GameMap, error) {
|
||||||
|
Reference in New Issue
Block a user