From 995342fb74fdd1ba5aeaa172a428538e7dd0dcdc Mon Sep 17 00:00:00 2001 From: Gene Pasquet Date: Wed, 8 Apr 2026 01:05:50 +0100 Subject: Code cleanup --- world.scm | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'world.scm') diff --git a/world.scm b/world.scm index 1f1b457..e637e90 100644 --- a/world.scm +++ b/world.scm @@ -95,24 +95,23 @@ (loop (cdr es) (cons (cons gid e) acc)))) (loop (cdr es) acc)))))) + (define (sync-member-to-origin e origins) + (let* ((gid (entity-ref e #:group-id #f)) + (o (and gid (not (entity-ref e #:group-origin? #f)) + (assq gid origins)))) + (if o + (let ((origin (cdr o))) + (entity-set (entity-set e #:x (+ (entity-ref origin #:x 0) + (entity-ref e #:group-local-x 0))) + #:y (+ (entity-ref origin #:y 0) + (entity-ref e #:group-local-y 0)))) + e))) + ;; Snap member #:x/#:y to origin + #:group-local-x/y. Call after moving origins (tweens, etc.). (define (scene-sync-groups! scene) - (let* ((ents (scene-entities scene)) - (origins (group-origin-alist ents))) + (let ((origins (group-origin-alist (scene-entities scene)))) (scene-entities-set! scene - (map (lambda (e) - (if (and (entity-ref e #:group-id #f) - (not (entity-ref e #:group-origin? #f))) - (let* ((gid (entity-ref e #:group-id)) - (o (assq gid origins))) - (if o - (let ((origin (cdr o))) - (entity-set (entity-set e #:x (+ (entity-ref origin #:x 0) - (entity-ref e #:group-local-x 0))) - #:y (+ (entity-ref origin #:y 0) - (entity-ref e #:group-local-y 0)))) - e)) - e)) - ents)) + (map (lambda (e) (sync-member-to-origin e origins)) + (scene-entities scene))) scene)) ) -- cgit v1.2.3