krampus19/soko/entitylocations.go

32 lines
589 B
Go
Raw Normal View History

package soko
import "opslag.de/schobers/geom"
type EntityLocations map[geom.Point]int
func (l EntityLocations) Add(p geom.Point, id int) { l[p] = id }
func (l EntityLocations) Clone() EntityLocations {
clone := EntityLocations{}
for p, id := range l {
clone[p] = id
}
return clone
}
func (l EntityLocations) Has(p geom.Point) bool {
_, ok := l[p]
return ok
}
func (l EntityLocations) Move(from, to geom.Point) {
id, ok := l[from]
if !ok {
panic("no entitiy at position")
}
l.Remove(from)
l.Add(to, id)
}
func (l EntityLocations) Remove(p geom.Point) { delete(l, p) }