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
2020-07-19 11:54:11 +01:00
ObjectNone = iota
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectRover represents a live rover
2020-07-19 11:54:11 +01:00
ObjectRover
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectSmallRock is a small stashable rock
2020-07-19 11:54:11 +01:00
ObjectSmallRock
2020-06-30 23:59:58 +01:00
2020-07-10 18:39:33 +01:00
// ObjectLargeRock is a large blocking rock
2020-07-19 11:54:11 +01:00
ObjectLargeRock
)
// Glyph returns the glyph for this object type
func (o ObjectType) Glyph() Glyph {
switch o {
case ObjectNone:
return GlyphNone
case ObjectRover:
return GlyphRover
case ObjectSmallRock:
return GlyphSmallRock
case ObjectLargeRock:
return GlyphLargeRock
}
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-10 18:39:33 +01:00
ObjectRover,
ObjectLargeRock,
}
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-10 18:39:33 +01:00
ObjectSmallRock,
}
for _, t := range stashable {
if o.Type == t {
return true
}
}
return false
}