diff options
author | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-29 10:23:52 +0300 |
---|---|---|
committer | Henrique Alves <henrique.alves@itsjungle.xyz> | 2024-04-29 10:23:52 +0300 |
commit | aeddacb8d88f41ba7bdf37d39de17d8cf3b6a258 (patch) | |
tree | 2daee509556bb1e7a9b74dc610b2ef4831392fdb /scripts/prompt.scm | |
parent | 94e1881676e39bd8b8e6a8ee98e541102b380549 (diff) | |
download | gamejam-slgj-2024-aeddacb8d88f41ba7bdf37d39de17d8cf3b6a258.tar.gz gamejam-slgj-2024-aeddacb8d88f41ba7bdf37d39de17d8cf3b6a258.tar.bz2 gamejam-slgj-2024-aeddacb8d88f41ba7bdf37d39de17d8cf3b6a258.zip |
Creating small evaluation prompt
Diffstat (limited to 'scripts/prompt.scm')
-rw-r--r-- | scripts/prompt.scm | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/prompt.scm b/scripts/prompt.scm new file mode 100644 index 0000000..738cd42 --- /dev/null +++ b/scripts/prompt.scm @@ -0,0 +1,48 @@ +(define prompt-active #f) +(define prompt-box (make-rect 0 0 800 20)) +(define prompt-text "") + +(define (prompt-update) + (let ((key-pressed (rl-get-key-pressed))) + + + (if (eq? key-pressed 161) + (set! prompt-active (not prompt-active)) + ) + + (if prompt-active + (begin + (let ((key (rl-get-char-pressed))) + (cond ((and (>= key 32) (<= key 125)) + (set! prompt-text + (string-append prompt-text (string (integer->char key))))) + )) + + (if (rl-is-key-down KEY_ENTER) + (begin + (eval-string prompt-text) + (set! prompt-text "") + )) + + (if (eq? key-pressed KEY_BACKSPACE) + (let ((n (string-length prompt-text))) + (cond ((>= n 1) + (set! prompt-text (substring prompt-text 0 (- n 1)))) + ))) + + )) + ) + ) + +(define (prompt-draw) + (if prompt-active + (begin + (rl-draw-rectangle + (rect-x prompt-box) + (rect-y prompt-box) + (rect-width prompt-box) + (rect-height prompt-box) + (make-color 190 100 255)) + (rl-draw-text prompt-text 0 0 20 (make-color 0 0 0)) + )) + ) |