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
res/maps/casino.tmx.lisp
res/maps/outdoors.tmx.lisp
*.flf.lisp
*.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)))))
(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™
;;; ———————————————————————————————————
(defun casino-entrance-trigger (&optional map)
(list :map (🌍:merge-maps map *casino-map*)))
(defun factory-window-interact (&optional map interactee-id)
(make-dialogue-state
map
@ -351,10 +365,6 @@ avoid triggering this."
;;; ———————————————————————————————————
;;; Casino!
;;; ———————————————————————————————————
(defun casino-exit-trigger (&optional map)
(list :map (🌍:merge-maps map *outdoors-map*)))
;;; ———————————————————————————————————
;;; Destitute Gambler arc
@ -607,13 +617,13 @@ avoid triggering this."
(flashback-casino-outro map)))
(defun flashback-casino-trigger (map)
(defun flashback-casino-trigger (map &optional trigger-plist)
(make-dialogue-state
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
map
(start-dialogue
@ -624,7 +634,7 @@ avoid triggering this."
(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
map
(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)))))
(if (and trigger (getf trigger :function))
(apply (string->symbol (getf trigger :function))
(list map))
(list map trigger))
(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
a :FUNCTION to be triggered when its stepped upon."
(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-width (cl-tiled:rect-width tiled-obj))
(obj-height (cl-tiled:rect-height 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)
:function (gethash "function" (cl-tiled:properties tiled-obj))))))
(append
(loop for key being the hash-keys in properties
for val being the hash-values in properties
collect (intern (string-upcase key) "KEYWORD")
collect val)
(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 '()))

View File

@ -145,7 +145,8 @@
<objectgroup id="13" name="Triggers">
<object id="37" name="Exit" type="Trigger" x="378.56" y="668.417" width="40.8802" height="12.1666">
<properties>
<property name="function" value="✿:casino-exit-trigger"/>
<property name="function" value="✿:entrance-trigger"/>
<property name="map" value="✿::*outdoors-map*"/>
</properties>
</object>
</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.)
(Mi memoras ke, dum infanaĝo, li ofte petis min helpi lin tie.)
(Fek', tiom enuigis!!)</property>
<property name="id" value="✿:grocery-window"/>
<property name="id" value="✿:machinist-window"/>
<property name="interact" value="✿:description-interact"/>
</properties>
<point/>
@ -1836,7 +1836,7 @@ DANĜERA LOKO - VENENA MATERIO
</object>
</objectgroup>
<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>
<property name="facing-right" type="bool" value="true"/>
<property name="id" value="✿:player"/>
@ -1869,7 +1869,8 @@ DANĜERA LOKO - VENENA MATERIO
<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">
<properties>
<property name="function" value="✿:casino-entrance-trigger"/>
<property name="function" value="✿:entrance-trigger"/>
<property name="map" value="✿::*casino-map*"/>
</properties>
</object>
</objectgroup>