diff --git a/modules/ces/entity.scm b/modules/ces/entity.scm index a5802c5..c3f66f1 100644 --- a/modules/ces/entity.scm +++ b/modules/ces/entity.scm @@ -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.