objects.go 871 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package aoi
  2. import (
  3. "f1-game/internal/types"
  4. "maps"
  5. )
  6. type (
  7. Objects map[int64]*Object
  8. )
  9. func (p Objects) Get(objectID int64) *Object {
  10. object := p[objectID]
  11. return object
  12. }
  13. func (p Objects) Contains(objectID int64) bool {
  14. _, found := p[objectID]
  15. return found
  16. }
  17. func (p Objects) Add(object *Object) {
  18. p[object.ObjectID] = object
  19. }
  20. func (p Objects) Adds(objects Objects) {
  21. maps.Copy(p, objects)
  22. }
  23. func (p Objects) Remove(objectID int64) {
  24. delete(p, objectID)
  25. }
  26. func (p Objects) IsEmpty() bool {
  27. return len(p) < 1
  28. }
  29. func (p Objects) OnwerIDs() types.Set[int64] {
  30. ownerIDs := types.NewSet[int64]()
  31. for _, object := range p {
  32. ownerIDs.Add(object.OwnerID())
  33. }
  34. return ownerIDs
  35. }
  36. func (p Objects) ObjectIDs() types.Set[int64] {
  37. objectIDs := types.NewSet[int64]()
  38. for _, object := range p {
  39. objectIDs.Add(object.ObjectID)
  40. }
  41. return objectIDs
  42. }