From 12205afa02a401f3c33e9108ce7c14cc3e6f00c1 Mon Sep 17 00:00:00 2001 From: TakeV Date: Wed, 22 May 2024 01:36:57 -0400 Subject: [PATCH] Make the 'get-components' proceedure a little more intuitive --- modules/ces/entity.scm | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) 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.