61 lines
1.3 KiB
Scheme
61 lines
1.3 KiB
Scheme
(module (engine input) ()
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken module)
|
|
(engine core)
|
|
raylib
|
|
(srfi 99))
|
|
|
|
(register-event-bus 'input)
|
|
|
|
;; Input actions alist
|
|
(define input-actions '())
|
|
|
|
;; Key-press type action
|
|
(define-record-type <key-press>
|
|
(make-key-press key)
|
|
key-press?
|
|
(key key-press-key))
|
|
|
|
;; Mouse click type action
|
|
(define-record-type <mouse-press>
|
|
(make-mouse-press button)
|
|
mouse-press?
|
|
(button mouse-press-button))
|
|
|
|
;; Add a new action to the input actions alist
|
|
(export register-action push-actions)
|
|
(define (register-action name type . data)
|
|
(assert (symbol? name))
|
|
(assert (member type '(key-press mouse-press)))
|
|
(set! input-actions
|
|
(cons (cons name
|
|
(apply (cond
|
|
((eqv? type 'key-press) make-key-press)
|
|
((eqv? type 'mouse-press) make-mouse-press))
|
|
data))
|
|
input-actions)))
|
|
|
|
;; Default global system for simple input management
|
|
(define push-actions
|
|
(make-system
|
|
'push-actions
|
|
0
|
|
'global
|
|
'()
|
|
(lambda ()
|
|
(for-each
|
|
(lambda (action)
|
|
(cond
|
|
((key-press? (cdr action))
|
|
(when (key-pressed? (key-press-key (cdr action)))
|
|
(push-event 'input
|
|
(car action)
|
|
(cdr action))))
|
|
((mouse-press? (cdr action))
|
|
(when (mouse-button-pressed? (mouse-press-button (cdr action)))
|
|
(push-event 'input
|
|
(car action)
|
|
(cdr action))))))
|
|
input-actions))))
|
|
)
|