rove/pkg/atlas/objects.go

74 lines
1.3 KiB
Go
Raw Normal View History

2020-07-10 18:39:33 +01:00
package atlas
import "log"
2020-07-19 11:47:19 +01:00
// ObjectType represents an object type
type ObjectType byte
// Types of objects
const (
2020-07-10 18:39:33 +01:00
// ObjectNone represents no object at all
ObjectNone = ObjectType(0)
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectRover represents a live rover
ObjectRoverLive = ObjectType(1)
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectSmallRock is a small stashable rock
ObjectRockSmall = ObjectType(2)
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectLargeRock is a large blocking rock
ObjectRockLarge = ObjectType(3)
)
// Glyph returns the glyph for this object type
func (o ObjectType) Glyph() Glyph {
switch o {
case ObjectNone:
return GlyphNone
2020-07-19 11:56:05 +01:00
case ObjectRoverLive:
return GlyphRoverLive
case ObjectRockSmall:
return GlyphRockSmall
case ObjectRockLarge:
return GlyphRockLarge
}
log.Fatalf("Unknown object type: %c", o)
return GlyphNone
}
// Object represents an object in the world
type Object struct {
2020-07-19 11:47:19 +01:00
// The type of the object
Type ObjectType `json:"type"`
}
2020-06-30 23:59:58 +01:00
// IsBlocking checks if an object is a blocking object
func (o *Object) IsBlocking() bool {
2020-07-19 11:47:19 +01:00
var blocking = [...]ObjectType{
2020-07-19 11:56:05 +01:00
ObjectRoverLive,
ObjectRockLarge,
}
for _, t := range blocking {
if o.Type == t {
return true
}
}
return false
}
2020-06-30 23:59:58 +01:00
// IsStashable checks if an object is stashable
func (o *Object) IsStashable() bool {
2020-07-19 11:47:19 +01:00
var stashable = [...]ObjectType{
2020-07-19 11:56:05 +01:00
ObjectRockSmall,
}
for _, t := range stashable {
if o.Type == t {
return true
}
}
return false
}