diff options
author | colin <colin@cicadas.surf> | 2023-04-01 15:53:13 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-04-01 15:53:13 -0700 |
commit | a73b31c1ca88d0cba7365e648e3da70c4124f27e (patch) | |
tree | c66e46b115a2f3881922a5109d242f913dc23d99 /src/game | |
parent | cc10599f1531e18998fd8a6d80f8b17846699d63 (diff) |
Reorganizing the adventure page
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/adventure.lisp | 100 | ||||
-rw-r--r-- | src/game/hero.lisp | 10 | ||||
-rw-r--r-- | src/game/quest.lisp | 22 | ||||
-rw-r--r-- | src/game/tavern.lisp | 26 | ||||
-rw-r--r-- | src/game/views.lisp | 5 |
5 files changed, 87 insertions, 76 deletions
diff --git a/src/game/adventure.lisp b/src/game/adventure.lisp index 6bbd2d3..9c3fafd 100644 --- a/src/game/adventure.lisp +++ b/src/game/adventure.lisp @@ -53,6 +53,12 @@ ;;; HELPERS +(defun adventure-rumors-path (adventure) + (format nil "/rumors-about/~a" (uid adventure))) + +(defmethod unique-name ((adventure adventure)) + (title adventure)) + ;;; QUERIES (defun player-adventures (player) @@ -109,6 +115,41 @@ only the active quest(s) are considered, otherwise all quests are considered." (defrender :list-item ((adventure adventure)) (render :inline adventure)) +(defrender :list-item ((rumor rumor)) + (with-slots (reporter reported) rumor + (with-html + (:p (subseq reported 0 (min 20 (length reported))) " ..." " -- " (render :inline reporter))))) + +(defun rumors-section (page) + (let ((adventure (adventure page))) + (with-html + (:div + (when (rumors adventure) + (:h3 "Rumors") + (render :list (rumors adventure))) + (:h4 "Report a rumor") + (:form :method "POST" :action (adventure-rumors-path adventure) + (:label :for "REPORTED" "What did ye have to report?") + (:br) + (:textarea :name "REPORTED" :rows "5" :cols "40") + (:br) + (:button :type "submit" "Report!")))))) + +(defun seers-section (page) + (let ((adventure (adventure page))) + (with-html + (:div + (when (seers adventure) + (:h4 "Seers: ") + (render :list (seers adventure))) + (when (possible-seers page) + (:form :method "POST" :action (urlpath adventure) + (:label :for "SEER" "Add a seer to this adventure:") (:br) + (:select :name "SEER" + (loop :for p :in (all-other-players (player page)) + :collect (:option :value (nickname p) (nickname p)))) + (:button :type "submit" "Add Seer"))))))) + ;;; PAGES & PAGE CLASSES @@ -118,7 +159,6 @@ only the active quest(s) are considered, otherwise all quests are considered." :initarg :possible-seers :initform nil))) - (defrender t ((page adventure-awaits)) (with-page (:title "What sparkles in yer eye?") (:h2 "Enscribe your new adventure in the book of the bards.") @@ -147,45 +187,21 @@ only the active quest(s) are considered, otherwise all quests are considered." (:button :type "submit" "Embark!"))))) -(defclass adventure-page () - ((adventure :reader adventure :initarg :adventure) - (player :reader player :initarg :player))) +(defclass/std adventure-page () + ((adventure player possible-seers))) + +(defmethod possible-seers ((page adventure-page)) + (when (eq (player page) (creator (adventure page))) + (remove (player page) (all-players)))) (defrender t ((page adventure-page)) (let ((adventure (adventure page))) (with-page (:title (title adventure)) (:h1 (title adventure)) (:p (description adventure)) - (:h2 "Rumors: ") - ; (render :list (rumors adventure)) - (:h2 "Architect of this Adventure: " (nickname (creator adventure))) - (:h2 "Seers: ") - (render :list (seers adventure)) - (:form :method "POST" :action (urlpath adventure) - (:label :for "SEER" "Add a seer to this adventure:") (:br) - (:select :name "SEER" - (loop :for p :in (all-other-players (player page)) - :collect (:option :value (nickname p) (nickname p)))) - (:button :type "submit" "Add Seer"))))) - -(defclass spymaster () - ((player :reader player :initarg :player) - (adventures :reader adventures :initarg :adventures))) - - -(defrender t ((page spymaster)) - (with-page (:title "spymaster - report a rumor") - (:h1 "Of what hazards have ye heard rumor?") - (:form :method "POST" :action "/spymaster" - (:label :for "ADVENTURE" "What adventure did ye hear a rumor about?") - (:br) - (render :select (adventures page) :name "ADVENTURE") - (:br) - (:label :for "REPORTED" "And what did ye have to report?") - (:br) - (:textarea :name "REPORTED" :rows "5" :cols "60") - (:br) - (:button :type "submit" "Report!")))) + (:p "Created by: " (render :link-to (player page))) + (rumors-section page) + (seers-section page)))) (defclass/std tavern-adventures () ((your-adventures))) @@ -229,20 +245,12 @@ only the active quest(s) are considered, otherwise all quests are considered." :seers possible-seers))))))) -(defendpoint* :get "/spymaster" () () - (with-session (player) - (render (page-render-mode) - (make-instance 'spymaster - :player player - :adventures (adventures-visible-by player))))) - -(defendpoint* :post "/spymaster" () () +(defendpoint* :post "/rumors-about/:adventure an-adventure-with-id:" () () (with-session (player) - (with-plist ((adventure :adventure) (reported :reported)) (lzb:request-body) - (let ((adventure (an-adventure-with-id adventure))) - (report-a-rumor player adventure reported)) - (redirect-to "/tavern")))) + (with-plist ((reported :reported)) (lzb:request-body) + (report-a-rumor player adventure reported) + (redirect-to (urlpath adventure))))) ;; NB for current hackers (Tue Mar 7 06:44:02 PM PST 2023) ;; Even though these next three all look the same I'm not going to diff --git a/src/game/hero.lisp b/src/game/hero.lisp index 68606b2..56c5786 100644 --- a/src/game/hero.lisp +++ b/src/game/hero.lisp @@ -51,6 +51,9 @@ ;;; HELPERS +(defmethod unique-name ((hero hero)) + (name hero)) + ;;; QUERIES (defun all-heroes () (db:store-objects-with-class 'hero)) @@ -71,7 +74,6 @@ (:span "who's quest is to") (:span (render :link-to quest)))))) - (defrender :link-to ((hero hero)) (with-html (:a :href (urlpath hero) @@ -86,7 +88,11 @@ (defrender t ((page hero-page)) (with-page (:title (unique-name (hero page))) (:h1 (unique-name (hero page))) - (:p "uhhh....."))) + (:div + (if (quest (hero page)) + (:p "This hero is questing on " + (render :link-to (quest (hero page)))) + (:p "this hero is free to join a quest"))))) (defrender t ((page (eql :goddess-shrine))) (with-page (:title "A Sacred Shrine") diff --git a/src/game/quest.lisp b/src/game/quest.lisp index d36b9f9..ab1b9a7 100644 --- a/src/game/quest.lisp +++ b/src/game/quest.lisp @@ -26,22 +26,28 @@ :type (or nil integer) :documentation "Time at which the quest began.")) (:metaclass db:persistent-class) - (:documentation "A collection of hazards with a deadline and start date which heroes will attack.")) + (:documentation + "A collection of hazards with a deadline and start date which heroes will attack.")) +;;; HELPERS +;;; QUERIES (defun player-quests (player) "Return all quests in which one of player's heroes is engaged." (remove nil (mapcar #'quest (player-heroes player)))) -(define-id-plucker quest) +;;; TRANSACTIONS +;;; MODEL VIEWS (defrender :link-to ((quest quest)) (with-html (:a :href (urlpath quest) (name quest)))) +;;; PAGES & PAGE CLASSES + (defclass quest-page () ((quest :reader quest :initarg :quest) (player :reader player :initarg :player))) @@ -50,18 +56,10 @@ (with-page (:title (unique-name (quest page ))) (:h1 (unique-name (quest page))))) -;;; HELPERS - -;;; QUERIES - -;;; TRANSACTIONS - -;;; MODEL VIEWS - -;;; PAGES & PAGE CLASSES - ;;; ENDPOINT HELPERS +(define-id-plucker quest) + ;;; ENDPOINT DEFINITIONS (defendpoint* :get "/quest/:quest a-quest-with-id:/:name:" () () diff --git a/src/game/tavern.lisp b/src/game/tavern.lisp index 5997218..5ddb8b9 100644 --- a/src/game/tavern.lisp +++ b/src/game/tavern.lisp @@ -6,22 +6,18 @@ ;;; PAGES & PAGE CLASSES (defclass/std tavern () - ((player))) + ((player adventures))) (defrender t ((tavern tavern)) (with-page (:title "A Bustling Tavern") - (let ((player (player tavern))) - (render :details player) - (when (player-heroes player) - (:h2 "Your Heroes:") - (render :list (player-heroes player))) - (:a :href "tavern/adventures" "Adventures for which you are seer.") - (:br) - (:a :href "/goddess-shrine" "Pray a new hero rises.") - (:br) - (:a :href "/spymaster" "Report a Roguish Rumour...") - (:br) - (:a :href "/adventure-awaits" "Embark on a new Adventure!")))) + (let ((player (player tavern))) + (render :details player) + (when (player-heroes player) + (:h4 "Your Heroes:") + (render :list (player-heroes player))) + (when (adventures tavern) + (:h4 "All Adventures:") + (render :list (adventures tavern)))))) ;;; ENDPONT HELPERS @@ -31,7 +27,9 @@ (defendpoint* :get "/tavern" () () (with-session (me) (render (page-render-mode) - (make-instance 'tavern :player me)))) + (make-instance 'tavern + :player me + :adventures (all-adventures))))) diff --git a/src/game/views.lisp b/src/game/views.lisp index 1b2f05d..e674598 100644 --- a/src/game/views.lisp +++ b/src/game/views.lisp @@ -5,5 +5,6 @@ (defun page-nav () (with-html (:nav :class "navbar" - (:ul - (:li (:a :href "/tavern" "🍺 Tavern")))))) + (:div (:a :href "/tavern" "🍺 Tavern")) + (:div (:a :href "/goddess-shrine" "🦸 Roll Up A Hero")) + (:div (:a :href "/adventure-awaits" "🔭 Embark on an Adventure"))))) |