diff options
author | colin <colin@cicadas.surf> | 2023-03-07 19:15:12 -0800 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-03-07 19:15:12 -0800 |
commit | efa771e3cc363dae68b57dfcc5c67c511a1d3331 (patch) | |
tree | 99dc6c2b8770a6e0ae87fedf2ba99ac21bf83b7d | |
parent | e2a60e8d2b8e41bcd2c9a39d8e2210f701b92353 (diff) |
Add: reporting rumors
-rw-r--r-- | src/endpoints.lisp | 22 | ||||
-rw-r--r-- | src/model.lisp | 2 | ||||
-rw-r--r-- | src/pages/spymaster.lisp | 22 | ||||
-rw-r--r-- | src/queries.lisp | 8 | ||||
-rw-r--r-- | src/transactions.lisp | 8 | ||||
-rw-r--r-- | src/views/adventure.lisp | 4 | ||||
-rw-r--r-- | src/views/components.lisp | 5 |
7 files changed, 66 insertions, 5 deletions
diff --git a/src/endpoints.lisp b/src/endpoints.lisp index e78c9fe..51d2de3 100644 --- a/src/endpoints.lisp +++ b/src/endpoints.lisp @@ -9,7 +9,6 @@ (defparameter +session-cookie-name+ "dnd-session") - ;;; UTILITIES (defun redirect-to (location) @@ -169,6 +168,26 @@ functions in url parameters in endpoint definitions." :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" () () + (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")))) + +;; 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 +;; make a macro to generate them. there may be future concerns with +;; permissions or query parameters that will make them look different. + (defendpoint* :get "/adventure/:adventure an-adventure-with-id:/:title:" () () (with-session (player) (render (page-render-mode) @@ -191,3 +210,4 @@ functions in url parameters in endpoint definitions." :hero quest)))) + diff --git a/src/model.lisp b/src/model.lisp index 381687e..e44d3b9 100644 --- a/src/model.lisp +++ b/src/model.lisp @@ -157,7 +157,7 @@ (:metaclass db:persistent-class) (:documentation "A adventure is a container of quests. Adventures are expected to be engaged with on a particular schedule, and are run by particular people.")) -(defclass rumor (db:store-object) +(defclass rumor (game-object) ((reporter :reader reporter :initarg :reporter diff --git a/src/pages/spymaster.lisp b/src/pages/spymaster.lisp new file mode 100644 index 0000000..01deef2 --- /dev/null +++ b/src/pages/spymaster.lisp @@ -0,0 +1,22 @@ +;;;; spymaster.lisp + +(in-package :dnd) + +(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!")))) diff --git a/src/queries.lisp b/src/queries.lisp index de3f8c3..07a8d5f 100644 --- a/src/queries.lisp +++ b/src/queries.lisp @@ -31,3 +31,11 @@ ACTIVEP, then only heroes involved in active quests are returned." (remove-duplicates (loop :for adventure :in (player-adventures player) :nconc (adventure-heros adventure :activep activep)))) + +(defun all-adventures () + (db:store-objects-with-class 'adventure)) + +(defun adventures-visible-by (player) + (declare (ignore player)) + (all-adventures)) + diff --git a/src/transactions.lisp b/src/transactions.lisp index dff037d..61f7f9b 100644 --- a/src/transactions.lisp +++ b/src/transactions.lisp @@ -22,3 +22,11 @@ (make-instance 'adventure :title title :creator player :seers seers :description description))) + +(defun report-a-rumor (reporter adventure reported) + (db:with-transaction () + (let ((rumor + (make-instance 'rumor + :reported reported + :reporter reporter))) + (push rumor (rumors adventure))))) diff --git a/src/views/adventure.lisp b/src/views/adventure.lisp index b4980f1..8d4cebc 100644 --- a/src/views/adventure.lisp +++ b/src/views/adventure.lisp @@ -6,3 +6,7 @@ (defrender :inline ((adventure adventure)) (with-html (:a :href (urlpath adventure) (title adventure)))) + +(defrender :option ((adventure adventure)) + (with-html + (:option :value (uid adventure) (title adventure)))) diff --git a/src/views/components.lisp b/src/views/components.lisp index de4cc5c..bb9772d 100644 --- a/src/views/components.lisp +++ b/src/views/components.lisp @@ -19,11 +19,10 @@ the class string for the contained list items." (dolist (item data) (:li :class item-class (render :list-item item)))))) -(defrender :select ((data list) (multiple "false") name class) +(defrender :select ((data list) name class) (with-html (when data - (:select :multiple multiple - :name (or name (format nil "select-~a" (class-of (first data)))) + (:select :name (or name (format nil "select-~a" (class-of (first data)))) :class (or class (format nil "select ~a" (class-of (first data)))) (dolist (item data) (render :option item)))))) |