Add generic trigger function for entrances/exits

This commit is contained in:
Jaidyn Ann 2023-07-10 21:59:01 -05:00
parent 1013977e31
commit efaaba9cad
7 changed files with 43 additions and 1305 deletions

5
.gitignore vendored
View File

@ -1,3 +1,2 @@
res/maps/flashback-school.tmx.lisp *.flf.lisp
res/maps/casino.tmx.lisp *.tmx.lisp
res/maps/outdoors.tmx.lisp

View File

@ -107,14 +107,28 @@ dialogue, among which one will be selected randomly."
map (start-dialogue (say interactee-id :en en-line :eo eo-line))))) map (start-dialogue (say interactee-id :en en-line :eo eo-line)))))
(defun string->symbol (string)
"Given a STRING with an optionally defined package (e.g., package:symbol),
return it as an appopriate symbol."
(let* ((split (str:split ":" (string-upcase string)))
(package (when (eq (length split) 2)
(car split)))
(symbol (or (cadr split) (car split))))
(if package
(intern symbol package)
(intern symbol))))
(defun entrance-trigger (map trigger-plist)
"A trigger that can be used to move the user from one MAP to another, via the
:MAP property in a triggers Tiled entity."
(list :map (🌍:merge-maps map (symbol-value (read-from-string (getf trigger-plist :map))))))
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
;;; The Outside World™ ;;; The Outside World™
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
(defun casino-entrance-trigger (&optional map)
(list :map (🌍:merge-maps map *casino-map*)))
(defun factory-window-interact (&optional map interactee-id) (defun factory-window-interact (&optional map interactee-id)
(make-dialogue-state (make-dialogue-state
map map
@ -351,10 +365,6 @@ avoid triggering this."
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
;;; Casino! ;;; Casino!
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
(defun casino-exit-trigger (&optional map)
(list :map (🌍:merge-maps map *outdoors-map*)))
;;; ——————————————————————————————————— ;;; ———————————————————————————————————
;;; Destitute Gambler arc ;;; Destitute Gambler arc
@ -607,13 +617,13 @@ avoid triggering this."
(flashback-casino-outro map))) (flashback-casino-outro map)))
(defun flashback-casino-trigger (map) (defun flashback-casino-trigger (map &optional trigger-plist)
(make-dialogue-state (make-dialogue-state
map map
(flashback-casino-dialogue map))) (flashback-casino-dialogue map)))
(defun flashback-casino-exit-top-trigger (map) (defun flashback-casino-exit-top-trigger (map &optional trigger-plist)
(make-dialogue-state (make-dialogue-state
map map
(start-dialogue (start-dialogue
@ -624,7 +634,7 @@ avoid triggering this."
(move 'player '(:x 35 :y 2))))) (move 'player '(:x 35 :y 2)))))
(defun flashback-casino-exit-bottom-trigger (map) (defun flashback-casino-exit-bottom-trigger (map &optional trigger-plist)
(make-dialogue-state (make-dialogue-state
map map
(start-dialogue (start-dialogue

View File

@ -243,7 +243,7 @@ Very kindly removes a list of parameters to be returned by the overworld state-f
(trigger (trigger-at-coords map (list :x (getf coords :x) :y (getf coords :y))))) (trigger (trigger-at-coords map (list :x (getf coords :x) :y (getf coords :y)))))
(if (and trigger (getf trigger :function)) (if (and trigger (getf trigger :function))
(apply (string->symbol (getf trigger :function)) (apply (string->symbol (getf trigger :function))
(list map)) (list map trigger))
(list :map map)))) (list :map map))))

View File

@ -81,16 +81,22 @@ character-scale world coordinates in plist form."
"Convert a Tiled object into a trigger plist. That is, a rectangle with "Convert a Tiled object into a trigger plist. That is, a rectangle with
a :FUNCTION to be triggered when its stepped upon." a :FUNCTION to be triggered when its stepped upon."
(when (tiled-rectangle-p tiled-obj) (when (tiled-rectangle-p tiled-obj)
(let ((obj-x (cl-tiled:object-x tiled-obj)) (let ((properties (cl-tiled:properties tiled-obj))
(obj-x (cl-tiled:object-x tiled-obj))
(obj-y (cl-tiled:object-y tiled-obj)) (obj-y (cl-tiled:object-y tiled-obj))
(obj-width (cl-tiled:rect-width tiled-obj)) (obj-width (cl-tiled:rect-width tiled-obj))
(obj-height (cl-tiled:rect-height tiled-obj))) (obj-height (cl-tiled:rect-height tiled-obj)))
(list (append
:coords (tiled-coords->world-coords obj-x obj-y tiled-map) (loop for key being the hash-keys in properties
:width obj-width for val being the hash-values in properties
:height obj-height collect (intern (string-upcase key) "KEYWORD")
:bottom-coords (tiled-coords->world-coords (+ obj-x obj-width) (+ obj-y obj-height) tiled-map) collect val)
:function (gethash "function" (cl-tiled:properties tiled-obj)))))) (list
:coords (tiled-coords->world-coords obj-x obj-y tiled-map)
:width obj-width
:height obj-height
:bottom-coords (tiled-coords->world-coords (+ obj-x obj-width) (+ obj-y obj-height)
tiled-map))))))
(defun object-layer-entities (layer &optional (entity-chunks '())) (defun object-layer-entities (layer &optional (entity-chunks '()))

View File

@ -145,7 +145,8 @@
<objectgroup id="13" name="Triggers"> <objectgroup id="13" name="Triggers">
<object id="37" name="Exit" type="Trigger" x="378.56" y="668.417" width="40.8802" height="12.1666"> <object id="37" name="Exit" type="Trigger" x="378.56" y="668.417" width="40.8802" height="12.1666">
<properties> <properties>
<property name="function" value="✿:casino-exit-trigger"/> <property name="function" value="✿:entrance-trigger"/>
<property name="map" value="✿::*outdoors-map*"/>
</properties> </properties>
</object> </object>
</objectgroup> </objectgroup>

File diff suppressed because it is too large Load Diff

View File

@ -1776,7 +1776,7 @@ DANĜERA LOKO - VENENA MATERIO
<property name="desc-eo">(La laborejo de paĉjo.) <property name="desc-eo">(La laborejo de paĉjo.)
(Mi memoras ke, dum infanaĝo, li ofte petis min helpi lin tie.) (Mi memoras ke, dum infanaĝo, li ofte petis min helpi lin tie.)
(Fek', tiom enuigis!!)</property> (Fek', tiom enuigis!!)</property>
<property name="id" value="✿:grocery-window"/> <property name="id" value="✿:machinist-window"/>
<property name="interact" value="✿:description-interact"/> <property name="interact" value="✿:description-interact"/>
</properties> </properties>
<point/> <point/>
@ -1836,7 +1836,7 @@ DANĜERA LOKO - VENENA MATERIO
</object> </object>
</objectgroup> </objectgroup>
<objectgroup id="7" name="People"> <objectgroup id="7" name="People">
<object id="2" name="Player" type="Person" x="983.334" y="1637.34"> <object id="2" name="Player" type="Person" x="261.334" y="1604.34">
<properties> <properties>
<property name="facing-right" type="bool" value="true"/> <property name="facing-right" type="bool" value="true"/>
<property name="id" value="✿:player"/> <property name="id" value="✿:player"/>
@ -1869,7 +1869,8 @@ DANĜERA LOKO - VENENA MATERIO
<objectgroup id="14" name="Triggers"> <objectgroup id="14" name="Triggers">
<object id="11" name="Casino entrance" type="Trigger" x="204.551" y="1547.73" width="93.7125" height="15.3923"> <object id="11" name="Casino entrance" type="Trigger" x="204.551" y="1547.73" width="93.7125" height="15.3923">
<properties> <properties>
<property name="function" value="✿:casino-entrance-trigger"/> <property name="function" value="✿:entrance-trigger"/>
<property name="map" value="✿::*casino-map*"/>
</properties> </properties>
</object> </object>
</objectgroup> </objectgroup>