From 738239f50a686345a6b134b61b59872a0f22c334 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 26 Jun 2023 09:33:51 -0500 Subject: [PATCH] Persistent data between maps! How exciting! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I spent a good chunk of time trying to get rid of the maps’ global variables, instead packing each map into a :map variable in a “game” hash-table… but, wow, that took a while. And also made things a bit more complicated. And also… we could just do this. From this commit. So much easier! @-@ --- flora-search-aurora.lisp | 4 ++-- overworld.lisp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/flora-search-aurora.lisp b/flora-search-aurora.lisp index 70cd576..8dc87ea 100644 --- a/flora-search-aurora.lisp +++ b/flora-search-aurora.lisp @@ -141,11 +141,11 @@ (defun casino-entrance-trigger (&optional map) - (list :map *casino-map*)) + (list :map (🌍:merge-maps map *casino-map*))) (defun casino-exit-trigger (&optional map) - (list :map *outdoors-map*)) + (list :map (🌍:merge-maps map *outdoors-map*))) diff --git a/overworld.lisp b/overworld.lisp index 7eb6db4..c5cc190 100644 --- a/overworld.lisp +++ b/overworld.lisp @@ -22,6 +22,7 @@ (:use :cl :flora-search-aurora.overworld.tiled :flora-search-aurora.overworld.util) (:export #:overworld-state #:make-overworld-state #:overworld-state-draw + #:merge-maps #:world-coords->screen-coords #:getf-entity #:getf-entity-data #:move-entity-to #:move-entity @@ -301,3 +302,15 @@ A state-function for use with STATE-LOOP." (apply #'🌍:overworld-state (append (list matrix :map-path map-path) args)))) + + +(defun merge-maps (map-a map-b) + "Copy data that should be persistent between maps from map-a to map-b." + (setf (gethash :acts map-b) (gethash :acts map-a)) + (setf (gethash :knows map-b) (gethash :knows map-a)) + (mapcar + (lambda (player-key) + (setf (getf-entity-data map-b 'player player-key) + (getf-entity-data map-a 'player player-key))) + '(:face :normal-face :talking-face)) + map-b)