package ecs

// ECS system by jcerise, github.com/jcerise/gogue

// IntInSlice will return true if the integer value provided is present in the slice provided, false otherwise.
func IntInSlice(a int, list []int) bool {
	for _, b := range list {
		if b == a {
			return true
		}
	}
	return false
}

// TypeInSlice will return true if the reflect.Type provided is present in the slice provided, false otherwise.
func TypeInSlice(a string, list []string) bool {
	for _, b := range list {
		if b == a {
			return true
		}
	}
	return false
}

func DeleteFromEntitySlice(haystack []Entity, needle Entity) ([]Entity, Entity) {
	var excluded Entity
	for i, _ := range haystack {
		if haystack[i] == needle {
			excluded = haystack[i]
			if len(haystack) - 1 > i {
				haystack = append(haystack[:i], haystack[i+1:] ...)
			} else {
				haystack = haystack[:i]
			}
		}
	}
	return haystack, excluded
}