From 92a5dd6117d0653b20dfa2165c1d7eef7837652a Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 26 Jul 2018 11:39:30 +0200 Subject: Fix bug in resuming conversations. --- scenes/game.scm | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'scenes') diff --git a/scenes/game.scm b/scenes/game.scm index aeb699c..1e753cd 100644 --- a/scenes/game.scm +++ b/scenes/game.scm @@ -148,7 +148,7 @@ map's object layer." ;; Render the player messages in the selected order. (unless (speaking? who) (let ((bubble (child-ref (parent (parent player)) 'text-bubble)) - (messages (accepted-messages who))) + (messages (available-messages player))) (clear-messages bubble) (fold (lambda (message n lines) (match message @@ -235,19 +235,26 @@ be executed; if so, perform the action." (child-ref game 'reaper))) (_ #t)))))) +(define (available-messages player) + "Return the messages that PLAYER can choose from in the current +conversation." + (let ((who (talking? player))) + (cond + ((or (not who) + (wants-to-stop-talking? player)) '()) + ((assoc-ref (resume-messages player) (name who)) => list) + (else (accepted-messages who))))) + (define (handle-talking player key) (define who (talking? player)) ;; Use arrow keys to select a message, hit action key to ;; confirm the selection. - (match (cond - ((wants-to-stop-talking? player) '()) - ((assoc-ref (resume-messages player) (name who)) => list) - (else (accepted-messages who))) + (match (available-messages player) ;; Nothing more to say, so just wait for the action key to ;; be hit to dismiss the dialogue. (() (when (eq? 'space key) - (set! (speaking? who) #f) ; TODO? + (set! (speaking? who) #f) (stop-talking player))) ((and ((and (message text . flags) selected) . rest) messages) (cond @@ -286,7 +293,8 @@ be executed; if so, perform the action." ;; Dismiss character's text. ((and (eq? 'space key) (speaking? who)) - (set! (speaking? who) #f)))) + (set! (speaking? who) #f) + (change-animation (child-ref who 'sprite) 'pause)))) (_ (pk 'this-should-never-happen #t)))) (define-method (talk (player ) (who ) message) @@ -296,6 +304,7 @@ be executed; if so, perform the action." ((text next) (set! (speaking? who) #t) (set! (talking? player) who) + (change-animation (child-ref who 'sprite) 'talk) ;; Clear any shown messages. (clear-messages bubble) @@ -311,16 +320,25 @@ be executed; if so, perform the action." (define-method (start-talking (player ) (who )) (unless (equal? (talking? player) who) - (let ((bubble (child-ref (parent (parent player)) 'text-bubble))) - (clear-messages bubble) - (set! (visible? bubble) #t)) - (set! (talking? player) who))) + (set! (talking? player) who) + (if (null? (available-messages player)) + ;; nothing to say! Play error sound. + (begin + (pk 'nothing-to-say) + (stop-talking player)) + ;; Prepare empty text bubble + (let ((bubble (child-ref (parent (parent player)) 'text-bubble))) + (clear-messages bubble) + (set! (visible? bubble) #t))))) (define-method (stop-talking (player )) - (when (talking? player) - (set! (visible? (child-ref (parent (parent player)) 'text-bubble)) #f) - (set! (talking? player) #f) - (set! (wants-to-stop-talking? player) #f))) + (and=> (talking? player) + (lambda (who) + (let ((sprite (child-ref who 'sprite))) + (change-animation sprite 'idle)) + (set! (visible? (child-ref (parent (parent player)) 'text-bubble)) #f) + (set! (talking? player) #f) + (set! (wants-to-stop-talking? player) #f)))) (define* (render-text bubble text #:key (y-offset 0) (suffix '-text)) "Fill the bubble with lines of text. Return the number of lines." -- cgit v1.2.3