summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/endpoints.lisp45
-rw-r--r--src/pages/adventure-page.lisp10
-rw-r--r--src/pages/hero-page.lisp12
-rw-r--r--src/pages/quest-page.lisp11
-rw-r--r--src/pages/tavern.lisp4
-rw-r--r--src/utilities.lisp4
-rw-r--r--src/views/hero.lisp16
-rw-r--r--src/views/quest.lisp6
8 files changed, 92 insertions, 16 deletions
diff --git a/src/endpoints.lisp b/src/endpoints.lisp
index f1151cf..e78c9fe 100644
--- a/src/endpoints.lisp
+++ b/src/endpoints.lisp
@@ -66,6 +66,25 @@ functions in url parameters in endpoint definitions."
;;; VALIDATOR TRANSFORMS
+(defmacro define-id-plucker (class)
+ (let ((function-name
+ (intern (format nil "~a-~a-WITH-ID"
+ (if (starts-with-vowel-p (symbol-name class))
+ "AN" "A")
+ class)
+ :dnd)))
+ `(defun ,function-name (id)
+ (let ((object (object-with-uid (string-upcase id))))
+ (unless (typep object ',class)
+ (lzb:http-err 404))
+ object))))
+
+(define-id-plucker adventure)
+
+(define-id-plucker hero)
+
+(define-id-plucker quest)
+
(defun a-valid-nick (name)
"Errors with 400 if the name is not a valid hero name."
(unless (valid-nick-p name)
@@ -149,14 +168,26 @@ functions in url parameters in endpoint definitions."
:description description
:seers possible-seers)))))))
-(defun an-adventure-with-id (id)
- (let ((object (object-with-uid (string-upcase id))))
- (unless (typep object 'adventure)
- (lzb:http-err 404))
- object))
-
(defendpoint* :get "/adventure/:adventure an-adventure-with-id:/:title:" () ()
(with-session (player)
(render (page-render-mode)
- adventure))) ;; for now, render raw adventure.
+ (make-instance 'adventure-page
+ :player player
+ :adventure adventure)))) ;; for now, render raw adventure.
+
+(defendpoint* :get "/hero/:hero a-hero-with-id:/:name:" () ()
+ (with-session (player)
+ (render (page-render-mode)
+ (make-instance 'hero-page
+ :player player
+ :hero hero))))
+
+(defendpoint* :get "/quest/:quest a-quest-with-id:/:name:" () ()
+ (with-session (player)
+ (render (page-render-mode)
+ (make-instance 'quest-page
+ :player player
+ :hero quest))))
+
+
diff --git a/src/pages/adventure-page.lisp b/src/pages/adventure-page.lisp
index fd9cb09..80361a0 100644
--- a/src/pages/adventure-page.lisp
+++ b/src/pages/adventure-page.lisp
@@ -2,7 +2,11 @@
(in-package :dnd)
-(defrender :page ((adventure adventure))
- (with-page (:title (title adventure))
- (:h1 (title adventure))
+(defclass adventure-page ()
+ ((adventure :reader adventure :initarg :adventure)
+ (player :reader player :initarg :player)))
+
+(defrender t ((page adventure-page))
+ (with-page (:title (title (adventure page)))
+ (:h1 (title (adventure page)))
(:p "uhh......")))
diff --git a/src/pages/hero-page.lisp b/src/pages/hero-page.lisp
new file mode 100644
index 0000000..f413d9f
--- /dev/null
+++ b/src/pages/hero-page.lisp
@@ -0,0 +1,12 @@
+;;;; hero-apge.lisp -- shows a particular hero
+
+(in-package :dnd)
+
+(defclass hero-page ()
+ ((hero :reader hero :initarg :hero)
+ (player :reader player :initarg :player)))
+
+(defrender t ((page hero-page))
+ (with-page (:title (unique-name (hero page)))
+ (:h1 (unique-name (hero page)))
+ (:p "uhhh.....")))
diff --git a/src/pages/quest-page.lisp b/src/pages/quest-page.lisp
new file mode 100644
index 0000000..9c02d51
--- /dev/null
+++ b/src/pages/quest-page.lisp
@@ -0,0 +1,11 @@
+;;;; quest-page.lisp
+
+(in-package :dnd)
+
+(defclass quest-page ()
+ ((quest :reader quest :initarg :quest)
+ (player :reader player :initarg :player)))
+
+(defrender t ((page quest))
+ (with-page (:title (unique-name (quest page )))
+ (:h1 (unique-name (quest page)))))
diff --git a/src/pages/tavern.lisp b/src/pages/tavern.lisp
index 1f6c441..0ec3cd5 100644
--- a/src/pages/tavern.lisp
+++ b/src/pages/tavern.lisp
@@ -9,7 +9,9 @@
(with-page (:title "A Bustling Tavern")
(let ((player (player tavern)))
(render :details player)
- (render :list (player-heroes player))
+ (when (player-heroes player)
+ (:h2 "Your Heroes'")
+ (render :list (player-heroes player)))
(:br)
(:a :href "/goddess-shrine" "Pray a new hero rises.")
(:br)
diff --git a/src/utilities.lisp b/src/utilities.lisp
index 1e16931..539ad28 100644
--- a/src/utilities.lisp
+++ b/src/utilities.lisp
@@ -66,3 +66,7 @@
#\space
(a:conjoin #'asciip #'alphanumericp)
(string-downcase string)))))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun starts-with-vowel-p (string)
+ (find (elt string 0) "aeiou" :test #'char-equal)))
diff --git a/src/views/hero.lisp b/src/views/hero.lisp
index 31fa169..90c2803 100644
--- a/src/views/hero.lisp
+++ b/src/views/hero.lisp
@@ -4,8 +4,14 @@
(defrender :list-item ((hero hero))
(with-html
- (with-slots (name quest) hero
- (:p name "the" (hero-class hero) (hero-title hero)
- (when quest
- (:span "who is off in on a quest: ")
- (:span (render :inline quest)))))))
+ (:p
+ (render :link-to hero)
+ (a:when-let (quest (quest hero))
+ (:span "who's quest is to")
+ (:span (render :link-to quest))))))
+
+
+(defrender :link-to ((hero hero))
+ (with-html
+ (:a :href (urlpath hero)
+ (unique-name hero) "the" (hero-class hero) (hero-title hero))))
diff --git a/src/views/quest.lisp b/src/views/quest.lisp
index 0312dba..b289d76 100644
--- a/src/views/quest.lisp
+++ b/src/views/quest.lisp
@@ -2,3 +2,9 @@
(in-package :dnd)
+
+
+(defrender :link-to ((quest quest))
+ (with-html
+ (:a :href (urlpath quest)
+ (name quest))))