From: Christopher Allan Webber Date: Wed, 4 May 2016 18:57:42 +0000 (-0500) Subject: more dynamic dispatch of commands X-Git-Tag: fosdem-2017~184 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=4736bfc66c4067b0cf9daf8eb69b1fe733d54e00;p=mudsync.git more dynamic dispatch of commands --- diff --git a/mudsync/gameobj.scm b/mudsync/gameobj.scm index 37f8bfe..921850e 100644 --- a/mudsync/gameobj.scm +++ b/mudsync/gameobj.scm @@ -24,6 +24,7 @@ #:use-module (8sync systems actors) #:use-module (8sync agenda) #:use-module (srfi srfi-1) + #:use-module (ice-9 match) #:use-module (oop goops) #:export ( gameobj-simple-name-f @@ -103,6 +104,12 @@ (reply-message actor message #:val (slot-ref actor slot)))) +(define (val-or-run val-or-proc) + "Evaluate if a procedure, or just return otherwise" + (if (procedure? val-or-proc) + (val-or-proc) + val-or-proc)) + (define (filter-commands commands verb) (filter (lambda (cmd) @@ -112,13 +119,13 @@ (define-mhandler (gameobj-get-commands actor message verb) (define filtered-commands - (filter-commands (slot-ref actor 'commands) + (filter-commands (val-or-run (slot-ref actor 'commands)) verb)) (<-reply actor message #:commands filtered-commands)) (define-mhandler (gameobj-get-container-commands actor message verb) (define filtered-commands - (filter-commands (slot-ref actor 'container-commands) + (filter-commands (val-or-run (slot-ref actor 'container-commands)) verb)) (<-reply actor message #:commands filtered-commands)) diff --git a/mudsync/room.scm b/mudsync/room.scm index ddf7430..b2d23e6 100644 --- a/mudsync/room.scm +++ b/mudsync/room.scm @@ -69,8 +69,23 @@ (list (loose-direct-command "look" 'cmd-look-at) (empty-command "look" 'cmd-look-room) + (empty-command "go" 'cmd-go-where) (loose-direct-command "go" 'cmd-go))) +(define room-actions + (build-actions + ;; desc == description + (wire-exits! (wrap-apply room-wire-exits!)) + (cmd-go (wrap-apply room-cmd-go)) + (cmd-go-where (wrap-apply room-cmd-go-where)) + (cmd-look-room (wrap-apply room-cmd-look-room)))) + +(define room-actions* + (append room-actions gameobj-actions)) + +(define room-action-dispatch + (simple-dispatcher room-actions*)) + ;; TODO: Subclass from container? (define-class () ;; A list of @@ -79,7 +94,7 @@ #:getter room-exits) (container-commands - #:init-value %room-contain-commands) + #:init-value (wrap %room-contain-commands)) (message-handler #:allocation #:each-subclass @@ -87,20 +102,6 @@ #:init-value (wrap-apply room-action-dispatch))) -(define room-actions - (build-actions - ;; desc == description - (wire-exits! (wrap-apply room-wire-exits!)) - (cmd-go (wrap-apply room-cmd-go)) - (cmd-look-room (wrap-apply room-cmd-look-room)))) - -(define room-actions* - (append room-actions gameobj-actions)) - -(define room-action-dispatch - (simple-dispatcher room-actions*)) - - (define (room-wire-exits! room message) "Actually hook up the rooms' exit addresses to the rooms they claim to point to." @@ -131,5 +132,9 @@ claim to point to." (<- room (message-from message) 'tell #:text "I don't know where that is?\n")))) +(define-mhandler (room-cmd-go-where room message) + (<- room (message-from message) 'tell + #:text "Go where?\n")) + (define-mhandler (room-cmd-look-room room message) (<- room (message-from message) 'look-room))