switch room "tell" to not use string-apend
[mudsync.git] / mudsync / run-game.scm
index 89f96f1df8540711f8555917b59a5bf518c14bb4..0fed48d0c51f3a43182aff45d953a368d0ad09a7 100644 (file)
 
 (define-module (mudsync run-game)
   #:use-module (mudsync game-master)
-  #:use-module (8sync systems actors)
-  #:use-module (8sync systems actors debug)
+  #:use-module (8sync)
+  #:use-module (8sync repl)
+  #:use-module (8sync debug)
+  #:use-module (srfi srfi-1)
+  #:use-module (ice-9 receive)
+  #:use-module (ice-9 q)
+  #:use-module (ice-9 match)
   #:export (run-demo
-            ;; Just temporarily
-            %test-gm))
+            do-inject-special!
+            make-special-injector
 
+            ;; Debug stuff, might go away
+            %live-gm %live-hive
+            inject-gameobj!))
 
+\f
 ;;; Debugging stuff
 ;;; ===============
 
-(define %test-gm #f)
+;; @@: Could these be parameterized and this still work?
+(define %live-gm #f)
+(define %live-hive #f)
 
-(define (run-demo db-path game-spec default-room)
+;; Evil!  This uses a global variable... but it's hard to give any more
+;; convenient way of providing something for live hacking (which is
+;; "quasi-evil for productivity's sake" anyway).  You can set up your own
+;; solution which doesn't use a global though.
+
+(define %inject-queue #f)
+
+(define (inject-gameobj! game-spec special-symbol)
+  (if %inject-queue
+      (let ((gameobj-spec
+             (or (find
+                  (lambda (entry) (eq? (car entry) special-symbol))
+                  game-spec)
+                 (throw 'no-such-symbol "Can't find such a symbol in the game-spec"
+                        #:symbol special-symbol))))
+        (enq! %inject-queue (cons gameobj-spec special-symbol)))
+      (display "Game hasn't been started...\n"))
+  'done)
+
+(define-actor <gameobj-injector> (<actor>)
+  ((repl-update gameobj-injector-inject-queued))
+  (gm #:init-keyword #:gm
+      #:getter .gm))
+
+(define (gameobj-injector-inject-queued injector message)
+  (while (not (q-empty? %inject-queue))
+    (match (deq! %inject-queue)
+      ((gameobj-spec . special-symbol)
+       (<- (.gm injector) 'inject-special!
+           #:special-symbol special-symbol
+           #:gameobj-spec gameobj-spec)))))
+
+\f
+;;; Game running stuff
+;;; ==================
+
+(define* (run-demo game-spec default-room #:key repl-server)
   (define hive (make-hive))
   (define new-conn-handler
     (make-default-room-conn-handler default-room))
   (define gm
-    (hive-create-actor-gimmie* hive <game-master> "gm"
-                               #:new-conn-handler new-conn-handler))
-  (set! %test-gm gm)
-  ;; @@: Boy, wouldn't it be nice if the agenda could do things
-  ;;   on interrupt :P
-  (ez-run-hive hive
-               (list (bootstrap-message hive (actor-id gm) 'init-world
-                                        #:game-spec game-spec))))
+    (bootstrap-actor-gimmie* hive <game-master> "gm"
+                             #:new-conn-handler new-conn-handler))
+  (define injector
+    (bootstrap-actor hive <gameobj-injector>
+                     #:gm (actor-id gm)))
+
+  (define repl-manager
+    (bootstrap-actor* hive <repl-manager> "repl"
+                      #:subscribers (list injector)))
+
+  (set! %live-gm gm)
+  (set! %live-hive hive)
+
+  (set! %inject-queue (make-q))
+
+  (run-hive hive
+            (list (bootstrap-message hive (actor-id gm) 'init-world
+                                     #:game-spec game-spec))))