hermeticum/server/witch/direction.go

77 lines
1.3 KiB
Go
Raw Normal View History

2023-05-03 03:35:15 +00:00
package witch
const (
dirEast = "_DIR_EAST"
dirWest = "_DIR_WEST"
dirNorth = "_DIR_NORTH"
dirSouth = "_DIR_SOUTH"
dirAbove = "_DIR_ABOVE"
dirBelow = "_DIR_BELOW"
)
type Direction struct {
raw string
}
func (d Direction) Reverse() Direction {
2023-05-10 02:31:02 +00:00
raw := ""
switch d.raw {
case dirAbove:
raw = dirBelow
case dirBelow:
raw = dirAbove
case dirEast:
raw = dirWest
case dirWest:
raw = dirEast
case dirNorth:
raw = dirSouth
case dirSouth:
raw = dirNorth
}
return Direction{raw: raw}
2023-05-03 03:35:15 +00:00
}
// NormalizeHuman takes a direction someone might type like "up" or "north" and returns the correct Direction struct
func NormalizeHuman(humanDir string) Direction {
2023-05-10 02:31:02 +00:00
raw := ""
switch humanDir {
case "up":
case "above":
raw = dirAbove
case "down":
case "below":
raw = dirBelow
case "east":
raw = dirEast
case "west":
raw = dirWest
case "north":
raw = dirNorth
case "south":
raw = dirSouth
}
return Direction{raw: raw}
2023-05-03 03:35:15 +00:00
}
// Human returns a string form of this direction like "above" or "north"
2023-05-10 02:31:02 +00:00
func (d Direction) Human() (humanDir string) {
switch d.raw {
case dirAbove:
humanDir = "above"
case dirBelow:
humanDir = "below"
case dirEast:
humanDir = "east"
case dirWest:
humanDir = "west"
case dirNorth:
humanDir = "north"
case dirSouth:
humanDir = "south"
}
return humanDir
2023-05-03 03:35:15 +00:00
}