diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2021-04-20 15:42:10 -0400 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2021-04-20 15:42:10 -0400 |
commit | 059319aa1d1f7ead314824ab6a2439f55457dffa (patch) | |
tree | 24e6819b9a3b0b4c4cedc1624cd94df08b9d86d5 | |
parent | 44e96e43a8d98b6f4acc146b25e75a3795c10309 (diff) |
Flesh out terminal state a bit more.
-rw-r--r-- | game.scm | 95 |
1 files changed, 67 insertions, 28 deletions
@@ -15,7 +15,7 @@ #:use-module (starling node-2d) #:use-module (starling ring-buffer) #:use-module (starling scene) - #:duplicates (merge-generics) + #:duplicates (merge-generics replace warn-override-core warn last) #:export (launch-game)) @@ -273,7 +273,10 @@ (let ((old-state (state game)) (lines (terminal-lines game)) (input "") - (max-input-chars 48)) + (max-input-chars 48) + (password-attempts 0)) + (define (log line) + (ring-buffer-put! lines line)) (define (prompt) (if (terminal-locked? game) "password: " @@ -282,7 +285,7 @@ (if (terminal-locked? game) (make-string (string-length str) #\*) str)) - (define (refresh-output) + (define* (refresh-output #:optional (prompt? #t)) (set! (text (& game terminal-group output)) (string-concatenate (let loop ((i 0)) @@ -290,27 +293,47 @@ (cons* (ring-buffer-ref lines i) "\n" (loop (+ i 1))) - (list (prompt) - (passwordify-maybe input))))))) + (if prompt? + (list (prompt) + (passwordify-maybe input)) + '())))))) + (define (help) + (when (zero? (random 2)) + (log "quit wasting time!! open the door!!")) + (log "available commands:") + (log "exit - leave terminal") + (log "diagnostic N - run level N diagnostic") + (log "help - you're looking at it, buddy") + #t) + (define (exit-term) + (log "logout") + #f) + (define (diagnostic level) + (let ((n (string->number level))) + (if (and (integer? n) (positive? n)) + (begin + (log (string-append "running level " level " diagnostic...")) + (refresh-output #f) + (sleep 30) + (log "...") + (refresh-output #f) + (sleep 30) + (log "complete!") + (log "replenish dilithium crystals") + #t) + (begin + (ring-buffer-put! lines "expected an integer") + #t)))) (define (run-command command) (match command + (("help") + (help)) (("exit") - (ring-buffer-put! lines "logout") - #f) + (exit-term)) (("diagnostic" level) - (let ((n (string->number level))) - (if (and (integer? n) (positive? n)) - (begin - (ring-buffer-put! lines (string-append "running level " level " diagnostic...")) - (ring-buffer-put! lines "...") - (ring-buffer-put! lines "complete!") - (ring-buffer-put! lines "replenish dilithium crystals") - #t) - (begin - (ring-buffer-put! lines "expected an integer") - #t)))) + (diagnostic level)) ((name . _) - (ring-buffer-put! lines "error: no such command") + (log "error: no such command") #t))) (set! (state game) 'terminal) (attach-to game @@ -329,7 +352,7 @@ (- 300.0 (font-line-height (asset-ref monogram-font)))))))) (unless (terminal-locked? game) - (ring-buffer-put! lines "login")) + (log "login")) (refresh-output) (let loop () (if (match (channel-get (terminal-channel game)) @@ -337,15 +360,26 @@ (set! input (substring input 0 (max (- (string-length input) 1) 0))) #t) ('return - (ring-buffer-put! lines (string-append (prompt) (passwordify-maybe input))) + (log (string-append (prompt) (passwordify-maybe input))) (if (terminal-locked? game) - (begin - (if (string=? input "password") - (begin - (ring-buffer-put! lines "login successful") - (set! (terminal-locked? game) #f)) - (ring-buffer-put! lines "incorrect password")) - (set! input "")) + (if (string=? input "password") + (begin + (log "login successful") + (set! (terminal-locked? game) #f) + (set! input "") + #t) + (begin + (set! password-attempts (+ password-attempts 1)) + (log "incorrect password") + (if (>= password-attempts 3) + (begin + (dialog game player-display-name + "> Ugh... Random guesses aren't going to work. I should look around for clues.") + + (exit-term)) + (begin + (set! input "") + #t)))) (let ((continue? (run-command (remove string-null? (string-split input #\space))))) (set! input "") continue?))) @@ -472,11 +506,16 @@ (detach-all game) (run-script game (intro game)))) + ((terminal) + #f) (else (next-method)))) (define-method (on-key-press (game <game>) key modifiers repeat?) (case (state game) + ((dialog) + (when (eq? key 'return) + (channel-put! (click-channel game) #t))) ((terminal) (case key ((backspace return) |