You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
3 years ago
|
package state
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
// HexOrientation is the enum for the direction hexes are facing.
|
||
|
type HexOrientation uint8
|
||
|
|
||
|
const (
|
||
|
// PointyTop indicates hexes that have a pair of sides on either side in the horizontal direction,
|
||
|
// and points on the top and bottom in the vertical direction.
|
||
|
PointyTop HexOrientation = 1
|
||
|
// FlatTop indicates hexes that have a pair of points on either side in the horizontal direction,
|
||
|
// and sides on the top and bottom in the vertical direction.
|
||
|
FlatTop HexOrientation = 2
|
||
|
)
|
||
|
|
||
|
// UnmarshalText unmarshals from the equivalent Javascript constant name.
|
||
|
func (o *HexOrientation) UnmarshalText(text []byte) error {
|
||
|
switch string(text) {
|
||
|
case "POINTY_TOP":
|
||
|
*o = PointyTop
|
||
|
return nil
|
||
|
case "FLAT_TOP":
|
||
|
*o = FlatTop
|
||
|
return nil
|
||
|
default:
|
||
|
return fmt.Errorf("can't unmarshal unknown HexOrientation %s", text)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// MarshalText marshals into the equivalent JavaScript constant name.
|
||
|
func (o HexOrientation) MarshalText() (text []byte, err error) {
|
||
|
switch o {
|
||
|
case PointyTop, FlatTop:
|
||
|
return []byte(o.String()), nil
|
||
|
default:
|
||
|
return nil, fmt.Errorf("can't marshal unknown HexOrientation %d", o)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// String returns the equivalent JavaScript constant name.
|
||
|
func (o HexOrientation) String() string {
|
||
|
switch o {
|
||
|
case PointyTop:
|
||
|
return "POINTY_TOP"
|
||
|
case FlatTop:
|
||
|
return "FLAT_TOP"
|
||
|
default:
|
||
|
return fmt.Sprintf("[unknown HexOrientation %d]", o)
|
||
|
}
|
||
|
}
|