Add get-entity

This commit is contained in:
BirDt_ 2026-03-31 20:19:20 +08:00
parent 4f8ca4d97b
commit c7373bccf8
2 changed files with 8 additions and 1 deletions

View file

@ -102,7 +102,12 @@
(add-queued-entities))
;; Entity creation/removal interface
(export create-named-entity create-entity remove-entity clear-world)
(export create-named-entity create-entity remove-entity
get-entity clear-world)
(define (get-entity id)
(assert (symbol? id))
(hash-table-ref world id))
;; Create an entity in the world and return it's ID
(define (create-named-entity id . components)

View file

@ -22,6 +22,8 @@
(check (hash-table-exists? world 'ball) => #t)
(check (hash-table-exists? component-sets '<point>) => #t)
(check (point? (car (get-entity 'ball))) => #t) ;; Get entity retrieves the entity components
(clear-world)
(check (hash-table-size world) => 1) ;; World state does not immediately clear