import player correctly, pass off input correctly
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 2 May 2016 18:45:44 +0000 (13:45 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 2 May 2016 18:45:44 +0000 (13:45 -0500)
mudsync/game-master.scm
mudsync/player.scm

index bb8756a5e2ca96563d0d594760d1051e0691b5bc..f839931002fe663cabe8c62c2458be623407a4f7 100644 (file)
@@ -18,7 +18,6 @@
 
 (define-module (mudsync game-master)
   #:use-module (mudsync room)
-  #:use-module (mudsync player)
   #:use-module (mudsync networking)
   #:use-module (8sync systems actors)
   #:use-module (8sync agenda)
   "Handle input from a client."
   (define client-id (message-ref message 'client))
   (define input (message-ref message 'data))
-  (format #t "From ~s: ~s\n" client-id input)
+  ;; Look up player
+  (define player (hash-ref (gm-client-dir actor) client-id))
+
+  ;; debugging
+  (format #t "DEBUG: From ~s: ~s\n" client-id input)
+
+  (<- actor player 'handle-input
+      #:input input)
+
+  ;; TODO: Remove this shortly
   (<- actor (gm-network-manager actor) 'send-to-client
       #:client client-id
       #:data "Thanks, we got it!\n"))
 with an anonymous persona"
   (let ((count 0))
     (lambda (gm client-id)
-      (define guest-name (string-append "Guest-"
+      (set! count (+ count 1))
+      (let* ((guest-name (string-append "Guest-"
                                         (number->string count)))
-      (define room-id
-        (hash-ref (gm-room-dir gm) default-room))
-      ;; create and register the player
-      (define player
-        (create-actor* gm <player> "player"
-                       #:username guest-name
-                       #:gm (actor-id gm)
-                       #:client client-id))
-
-      ;; Register the player in our database of players -> connections
-      (gm-register-client! gm client-id player)
-      ;; Dump the player into the default room
-      (<-wait gm player 'set-loc! #:id room-id)
-      ;; Initialize the player
-      (<- gm player 'init))))
+             (room-id
+              (hash-ref (gm-room-dir gm) default-room))
+             ;; create and register the player
+             (player
+              (create-actor* gm (@@ (mudsync player) <player>) "player"
+                             #:username guest-name
+                             #:gm (actor-id gm)
+                             #:client client-id)))
+        ;; Register the player in our database of players -> connections
+        (gm-register-client! gm client-id player)
+        ;; Dump the player into the default room
+        (<-wait gm player 'set-loc! #:id room-id)
+        ;; Initialize the player
+        (<- gm player 'init)))))
 
index 42359bd47db3a116391a788ed8bb39964d787ace..340fa3d7c16a0cfec98a630382ff38fcea20b4fb 100644 (file)
@@ -18,6 +18,7 @@
 
 (define-module (mudsync player)
   #:use-module (mudsync gameobj)
+  #:use-module (mudsync game-master)
   #:use-module (8sync systems actors)
   #:use-module (8sync agenda)
   #:use-module (ice-9 format)
 
   (message-handler
    #:init-value
+   ;; @@: We're gonna need action inheritance real awful soon, huh?
    (make-action-dispatch
     (set-loc! (wrap-apply player-set-loc!))
-    (init (wrap-apply player-init!)))))
+    (init (wrap-apply player-init!))
+    (handle-input (wrap-apply player-handle-input)))))
 
 ;;; player message handlers
 
 (define-mhandler (player-init! player message)
   (player-look-around player))
 
+
+(define-mhandler (player-handle-input player message input)
+  (<- player (gameobj-gm player) 'write-home
+      #:text
+      (format #f "<~a>: ~s\n"
+              (player-username player)
+              input)))
+
+
 ;;; player methods
 
 (define (player-look-around player)