Skip to content

Commit

Permalink
Make sure MapData.TileSet doesn't remain nil
Browse files Browse the repository at this point in the history
  • Loading branch information
icza committed Apr 11, 2024
1 parent 47039e1 commit e4bb2b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/screp/screp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
appName = "screp"
appVersion = "v1.11.3"
appVersion = "v1.11.4"
appAuthor = "Andras Belicza"
appHome = "https://github.com/icza/screp"
)
Expand Down
2 changes: 2 additions & 0 deletions rep/mapdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type MapData struct {
// TileSet defines the tile set used on the map.
TileSet *repcore.TileSet

TileSetMissing bool `json:"tileSetMissing,omitempty"`

// Scenario name
Name string

Expand Down
9 changes: 8 additions & 1 deletion repparser/repparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import (

const (
// Version is a Semver2 compatible version of the parser.
Version = "v1.11.3"
Version = "v1.11.4"
)

var (
Expand Down Expand Up @@ -775,6 +775,12 @@ func parseMapData(data []byte, r *rep.Replay, cfg Config) error {
md.MapGraphics = &rep.MapGraphics{}
}

// Even though "ERA " section is mandatory, I've seen reps where it was missing.
// TileSet may be cruitial for some apps, let's ensure it doesn't remain nil.
// Somewhat arbitrary default:
md.TileSet = repcore.TileSetTwilight
md.TileSetMissing = true

var (
scenarioNameIdx uint16 // String index
scenarioDescriptionIdx uint16 // String index
Expand All @@ -793,6 +799,7 @@ func parseMapData(data []byte, r *rep.Replay, cfg Config) error {
md.Version = sr.getUint16()
case "ERA ": // Tile set sub-section
md.TileSet = repcore.TileSetByID(sr.getUint16() & 0x07)
md.TileSetMissing = false
case "DIM ": // Dimension sub-section
// If map has a non-standard size, the replay header contains
// invalid map size, this is the correct one.
Expand Down

0 comments on commit e4bb2b0

Please sign in to comment.