Allow entity-map:get-entity to accept a default value if none is found

This commit is contained in:
TakeV 2024-05-27 00:30:07 -04:00
parent 43b3681b70
commit bc2e3064d9
Signed by: TakeV
GPG key ID: A64F41345C7400AF

View file

@ -70,10 +70,12 @@ and integer already. Returns false if passed an invalid entity."
((integer? entity) entity)
(else (error "Invalid entity-key parameter" entity))))
(define (get-entity entity-map entity)
(define* (get-entity entity-map entity #:key (default #f))
"Returns the entity with the supplied entity-id if one exists.
Returns false if no entity exists with that id."
(hashtable-ref (entity-map-entities entity-map) (entity-key entity) #f))
(hashtable-ref (entity-map-entities entity-map)
(entity-key entity)
default))
(define* (get-entities entity-map #:key (criteria? game-entity?))
"Returns a list of all entities. When criteria? is provided,