remove database warnings
This commit is contained in:
parent
9f9ad35f7e
commit
011e7a34a1
2
Makefile
2
Makefile
@ -14,4 +14,4 @@ test:
|
|||||||
csc test-database.scm
|
csc test-database.scm
|
||||||
csc -s -J parse.scm
|
csc -s -J parse.scm
|
||||||
csc test-parse.scm
|
csc test-parse.scm
|
||||||
./test-util && ./test-database && ./test-parse && echo "All tests passed."
|
./test-util && ./test-database && ./test-parse
|
||||||
|
@ -6,43 +6,43 @@
|
|||||||
(import database)
|
(import database)
|
||||||
|
|
||||||
(test-group "database"
|
(test-group "database"
|
||||||
(test '((test . ((test-key . 3)))) (begin (set! *database* '())
|
(test '((test . ((test-key . 3)))) (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
*database*))
|
*database*))
|
||||||
(test 3 (begin (set! *database* '())
|
(test 3 (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(database-get 'test 'test-key #f)))
|
(database-get 'test 'test-key #f)))
|
||||||
(test '((test . ((test-key . 3)))) (begin (set! *database* '())
|
(test '((test . ((test-key . 3)))) (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(database-save "test.sav")
|
(database-save "test.sav")
|
||||||
(set! *database* '())
|
(database-null)
|
||||||
(database-load "test.sav")))
|
(database-load "test.sav")))
|
||||||
(test '() (begin (set! *database* '())
|
(test '() (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(database-remove 'test)
|
(database-remove 'test)
|
||||||
*database*))
|
*database*))
|
||||||
(test '(test) (begin (set! *database* '())
|
(test '(test) (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(get-all-objects)))
|
(get-all-objects)))
|
||||||
(test-group "object-exists?"
|
(test-group "object-exists?"
|
||||||
(test #t (begin (set! *database* '())
|
(test #t (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(object-exists? 'test)))
|
(object-exists? 'test)))
|
||||||
(test #f (begin (set! *database* '())
|
(test #f (begin (database-null)
|
||||||
(object-exists? 'test))))
|
(object-exists? 'test))))
|
||||||
(test-group "has-property?"
|
(test-group "has-property?"
|
||||||
(test #t (begin (set! *database* '())
|
(test #t (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(has-property? 'test 'test-key)))
|
(has-property? 'test 'test-key)))
|
||||||
(test #f (begin (set! *database* '())
|
(test #f (begin (database-null)
|
||||||
(database-set 'test 'test-key 3)
|
(database-set 'test 'test-key 3)
|
||||||
(has-property? 'test 'nosuch-key))))
|
(has-property? 'test 'nosuch-key))))
|
||||||
(test-group "toggle-flag"
|
(test-group "toggle-flag"
|
||||||
(test #t (begin (set! *database* '())
|
(test #t (begin (database-null)
|
||||||
(database-set 'test 'test-key #f)
|
(database-set 'test 'test-key #f)
|
||||||
(toggle-flag 'test 'test-key)
|
(toggle-flag 'test 'test-key)
|
||||||
(database-get 'test 'test-key #f)))
|
(database-get 'test 'test-key #f)))
|
||||||
(test #f (begin (set! *database* '())
|
(test #f (begin (database-null)
|
||||||
(database-set 'test 'test-key #t)
|
(database-set 'test 'test-key #t)
|
||||||
(toggle-flag 'test 'test-key)
|
(toggle-flag 'test 'test-key)
|
||||||
(database-get 'test 'test-key #t))))))
|
(database-get 'test 'test-key #t))))))
|
||||||
|
41
world.scm
41
world.scm
@ -1,3 +1,9 @@
|
|||||||
|
;;; Functions modeling a standard text adventure world.
|
||||||
|
;;; Location is modeled as containment, movement is modeled via passage nodes
|
||||||
|
;;; that hold properties and descriptions for a given exit.
|
||||||
|
;;; Global properties are held in the player object YOU, which also acts as
|
||||||
|
;;; the default avatar object.
|
||||||
|
|
||||||
(module world (adventure create-object move-object add-alias set-hidden toggle-fixed set-enter-message set-destination get-container print-room-description)
|
(module world (adventure create-object move-object add-alias set-hidden toggle-fixed set-enter-message set-destination get-container print-room-description)
|
||||||
(import scheme)
|
(import scheme)
|
||||||
(import chicken.base)
|
(import chicken.base)
|
||||||
@ -10,6 +16,9 @@
|
|||||||
(import database)
|
(import database)
|
||||||
(import io)
|
(import io)
|
||||||
|
|
||||||
|
|
||||||
|
;; The canonical name of a given cardinal direction
|
||||||
|
;; and it's aliases.
|
||||||
(define +cardinal-sets+
|
(define +cardinal-sets+
|
||||||
'((north n)
|
'((north n)
|
||||||
(northeast ne north-east)
|
(northeast ne north-east)
|
||||||
@ -22,6 +31,7 @@
|
|||||||
(up u)
|
(up u)
|
||||||
(down d)))
|
(down d)))
|
||||||
|
|
||||||
|
;; The mirror direction for a given direction.
|
||||||
(define +cardinal-opposites+
|
(define +cardinal-opposites+
|
||||||
'((north . south)
|
'((north . south)
|
||||||
(northeast . southwest)
|
(northeast . southwest)
|
||||||
@ -34,17 +44,34 @@
|
|||||||
(up . down)
|
(up . down)
|
||||||
(down . up)))
|
(down . up)))
|
||||||
|
|
||||||
|
;; Main game loop exit condition.
|
||||||
(define *exit-adventure* #f)
|
(define *exit-adventure* #f)
|
||||||
|
|
||||||
|
(define-syntax get-set-define
|
||||||
|
(er-macro-transformer
|
||||||
|
(lambda (exp rename compare)
|
||||||
|
(let ((flag (car exp)))
|
||||||
|
(begin
|
||||||
|
`(define (,(string->symbol (string-append (symbol->string flag) "-get")) object value)
|
||||||
|
(database-get object ,flag value))
|
||||||
|
`(define (,(string->symbol (string-append (symbol->string flag) "-set")) object value)
|
||||||
|
(database-set object ,flag value)))))))
|
||||||
|
|
||||||
|
(get-set-define test-value)
|
||||||
|
|
||||||
|
;; Set the name of an object.
|
||||||
(define (set-name object name)
|
(define (set-name object name)
|
||||||
(database-set object 'name name))
|
(database-set object 'name name))
|
||||||
|
|
||||||
|
;; Set the description of an object.
|
||||||
(define (set-description object description)
|
(define (set-description object description)
|
||||||
(database-set object 'description description))
|
(database-set object 'description description))
|
||||||
|
|
||||||
|
;; Get the name of an object.
|
||||||
(define (get-name object)
|
(define (get-name object)
|
||||||
(database-get object 'name (symbol->string object)))
|
(database-get object 'name (symbol->string object)))
|
||||||
|
|
||||||
|
;; Get the description of an object.
|
||||||
(define (get-description object)
|
(define (get-description object)
|
||||||
(database-get object 'description "You see the swirling void of creation."))
|
(database-get object 'description "You see the swirling void of creation."))
|
||||||
|
|
||||||
@ -92,7 +119,7 @@
|
|||||||
(database-set object 'fixed value))
|
(database-set object 'fixed value))
|
||||||
|
|
||||||
(define (get-fixed object value)
|
(define (get-fixed object value)
|
||||||
(database-get object 'hidden #f))
|
(database-get object 'fixed #f))
|
||||||
|
|
||||||
(define (get-put-message object)
|
(define (get-put-message object)
|
||||||
(database-get object 'put-message "You put the ~a into the ~a."))
|
(database-get object 'put-message "You put the ~a into the ~a."))
|
||||||
@ -100,7 +127,7 @@
|
|||||||
;; Is development mode enabled?
|
;; Is development mode enabled?
|
||||||
|
|
||||||
(define (devmode-enabled?)
|
(define (devmode-enabled?)
|
||||||
(has-property? 'you 'devmode))
|
(database-get 'you 'devmode #f))
|
||||||
|
|
||||||
(define (toggle-devmode)
|
(define (toggle-devmode)
|
||||||
(toggle-flag 'you 'devmode))
|
(toggle-flag 'you 'devmode))
|
||||||
@ -108,7 +135,7 @@
|
|||||||
;; Is an object fixed in place (e.g. cannot be picked up?)
|
;; Is an object fixed in place (e.g. cannot be picked up?)
|
||||||
|
|
||||||
(define (fixed? object)
|
(define (fixed? object)
|
||||||
(has-property? object 'fixed))
|
(database-get object 'fixed #f))
|
||||||
|
|
||||||
(define (toggle-fixed object)
|
(define (toggle-fixed object)
|
||||||
(toggle-flag object 'fixed))
|
(toggle-flag object 'fixed))
|
||||||
@ -153,7 +180,13 @@
|
|||||||
(fmt #t (dsp (wrap-lines (get-description room))))
|
(fmt #t (dsp (wrap-lines (get-description room))))
|
||||||
(newline)
|
(newline)
|
||||||
(display "You see: ")
|
(display "You see: ")
|
||||||
(map (lambda (n) (if (not (get-hidden n)) (begin (display (get-name n)) (display " ") (if (devmode-enabled?) (begin (display (set-text '(bold fg-green) (string-append "[" (symbol->string n) "] ")))))))) (remove (curry eq? 'you) (get-contents room)))
|
(map (lambda (n)
|
||||||
|
(if (not (get-hidden n))
|
||||||
|
(begin
|
||||||
|
(display (get-name n))
|
||||||
|
(display " ")
|
||||||
|
(if (devmode-enabled?)
|
||||||
|
(display (set-text '(bold fg-green) (string-append "[" (symbol->string n) "] "))))))) (remove (curry eq? 'you) (get-contents room)))
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
(define (do-command-enter tag)
|
(define (do-command-enter tag)
|
||||||
|
Loading…
Reference in New Issue
Block a user