32 lines
1006 B
Go
32 lines
1006 B
Go
package westworldwithmessaging
|
|
|
|
import "fmt"
|
|
|
|
// entMinerBob and entElsa are our own stand-ins for the book's
|
|
// enumerated entity IDs (referenced as "ent_Miner_Bob" and "ent_Elsa"
|
|
// - presumably from an enum in a header we haven't been shown). Since
|
|
// this demo only ever has these two fixed characters, plain named
|
|
// constants do the same job: giving call sites a readable name
|
|
// instead of a bare number.
|
|
const (
|
|
entMinerBob = 1
|
|
entElsa = 2
|
|
)
|
|
|
|
// entityNames is a temporary stand-in for the book's real name
|
|
// lookup table. We still haven't been shown that table, so this is
|
|
// just a small map we're filling in by hand as we meet entities.
|
|
var entityNames = map[int]string{
|
|
entMinerBob: "Miner Bob",
|
|
entElsa: "Elsa",
|
|
}
|
|
|
|
// GetNameOfEntity looks up a friendly name for a given entity ID.
|
|
// Anything not in entityNames falls back to printing the raw ID.
|
|
func GetNameOfEntity(id int) string {
|
|
if name, ok := entityNames[id]; ok {
|
|
return name
|
|
}
|
|
return fmt.Sprintf("Entity %d", id)
|
|
}
|