diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2018-07-26 11:39:30 +0200 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2018-07-27 17:15:48 +0200 |
commit | 92a5dd6117d0653b20dfa2165c1d7eef7837652a (patch) | |
tree | 0957e4ddc09a7f1c48af4e88fa33a9fd8f50aa37 /scenes | |
parent | daec916bb542f282cbcd43c3cf9eb1444e6b1236 (diff) |
Fix bug in resuming conversations.
Diffstat (limited to 'scenes')
-rw-r--r-- | scenes/game.scm | 48 |
1 files changed, 33 insertions, 15 deletions
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 <player>) (who <character>) 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 <player>) (who <character>)) (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 <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." |