From 51be2e0e1470562d6ae4f0d176baf05792b509cf Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Thu, 25 Sep 2014 17:07:39 -0700 Subject: [PATCH] a way of doing dialogue trees, but meh. --- desktop/src-common/advent/screens/scene.clj | 55 ++++++++++++--------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 6abacfd1..1a4611d1 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -145,17 +145,16 @@ (merge params {:collision (advent.pathfind/map-from-resource collision) :interactions interactions-as-list}))) -(defn make-dialogue-tree [entities target-id tree] - (let [[e-line t-line options] tree - option-scripts (when options (for [option options] - [(first option) (actions/get-script entities - (make-dialogue-tree entities target-id option))]))] - (actions/talk entities :ego e-line) - (if (string? t-line) - (actions/talk entities target-id t-line) - (t-line)) - (when options - (apply actions/present-choices entities option-scripts)))) +(defn run-dialogue-tree [entities command-pairs & [previous-line]] + (let [commands (partition 2 command-pairs)] + (doseq [[subject arg] commands] + (if (= :choices subject) + (apply actions/present-choices entities (for [choice (partition 2 arg)] + [(first choice) (actions/get-script entities + (run-dialogue-tree entities (second choice) (first choice)))])) + (if (= :line arg) + (actions/talk entities subject previous-line) + (actions/talk entities subject arg)))))) (defn backgrounds [screen] (let [sheep-sheet (texture! (texture "outsidehouse/sheep-anim.png") :split 33 21) @@ -180,18 +179,28 @@ :cursor :down} :wizard {:box [228 80 248 126] :script (actions/get-script entities - (make-dialogue-tree entities :wizard ["Hello there Mr. Fangald!" - "Oh no, not you again!" - [["You're not my friend, Mr. Fangald?" - "No, you are a rascally little boy who is nothing but a cheat!" - [["Oh come on, I'm not that bad." - "Yes you are. Shoo!"] - ["I'm sorry I stole your magic cowboy hat." - #(do (actions/talk entities :wizard "Go.") - (actions/talk entities :wizard "Away.") - (actions/transition-background entities :outside-house [262 88]))]]] - ["What do you mean, 'not you again'?" - "I mean get lost kid."]]]))}} + (run-dialogue-tree entities [:ego "Hello there Mr. Fangald!" + :wizard "Oh no, not you again!" + :choices ["You're not happy to see me?" [:ego :line + :wizard "Of course not!" + :wizard "Not after all the hell you've put me through." + :choices ["You mean the time I set your rabbit loose?" [:ego :line + :wizard "Fluffy was my best rabbit!"] + "You're not still sore about my stealing your magic cowboy hat." [:ego :line + :ego "Are you?" + :wizard "That cowboy hat was one of a kind!" + :wizard "Truly unique." + :wizard "It accented my unique facial physique." + :wizard "And now it's gone forever." + :wizard "Leave me to die in peace."] + "You mean the time I set your house on fire with a fire mint?" [:ego :line + :wizard "That was you? I spent a fortune cleaning up the mess you made!" + :wizard "You ruined my life work!"] + + "An old hoot like you needs a kick the pants every now and again!" [:ego :line + :wizard "Maybe so, but not from a cheating little boy like you!"]]] + "What do you mean, 'not you again'?" [:ego :line + :wizard "I mean get lost kid."]]]))}} :layers [(assoc (texture "inside-house/background.png") :x 0 :y 0 :baseline 0) (assoc (texture "inside-house/desk.png") :x 0 :y 0 :baseline 200) (assoc (texture "inside-house/sillhoute.png") :x 0 :y 0 :baseline 240)]