Make the 'get-components' proceedure a little more intuitive
This commit is contained in:
parent
45c4dcecd5
commit
12205afa02
1 changed files with 11 additions and 18 deletions
|
@ -38,24 +38,17 @@
|
|||
false otherwise."
|
||||
(hashtable-ref (game-entity-components entity) component-name #f))
|
||||
|
||||
;; Returns a vector of components matching the provided critera
|
||||
;; If only the entity is provided, return all the entities.
|
||||
;; If a list or vector is provided, returns a vector with
|
||||
;; the component which matches that component-name
|
||||
;; (get-components renderable-entity ['position 'sprite])
|
||||
;; would return [POSITION-COMPONENT SPRITE-COMPONENT]
|
||||
(define get-components
|
||||
(case-lambda
|
||||
((entity) (hashtable-entries entity))
|
||||
((entity names)
|
||||
(let ((component-search
|
||||
(lambda (component-name)
|
||||
(get-component entity component-name))))
|
||||
(match names
|
||||
((? list?)
|
||||
(list->vector (map component-search names)))
|
||||
((? vector?)
|
||||
(list->vector (vector-map component-search names))))))))
|
||||
(define (get-components entity name . names)
|
||||
"Returns a list of components matching the provided critera
|
||||
(get-components renderable-entity 'position 'sprite)
|
||||
would return '(POSITION-COMPONENT SPRITE-COMPONENT)
|
||||
The order is preserved. If a component with that name
|
||||
does not exist, false is returned in place of the component. "
|
||||
(append
|
||||
(map (lambda (n)
|
||||
(get-component entity n))
|
||||
names)
|
||||
`(,name)))
|
||||
|
||||
(define (set-component! entity component-name component)
|
||||
"Replaces the component in entity with component-name.
|
||||
|
|
Loading…
Reference in a new issue