From dafccb17a19f5925308c4929c43eea0d919a9320 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:41:47 -0500 Subject: [PATCH] Language-specific map layers --- overworld.lisp | 4 +++- overworld.tiled.lisp | 43 +++++++++++++++++++++++++++---------------- ui.lisp | 10 ++++++++-- util.lisp | 22 ++++++++++++++++------ 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/overworld.lisp b/overworld.lisp index 3895d2a..794bde7 100644 --- a/overworld.lisp +++ b/overworld.lisp @@ -176,7 +176,9 @@ A core part of OVERWORLD-STATE." &key (chunk-width 72) (chunk-height 20)) "Draw a map’s specific chunk (by its ID) to the matrix." (mapcar (lambda (cell) - (matrix-write-cell matrix cell)) + (if (or (not (getf cell :lang)) + (eq (getf cell :lang) (…:system-language))) + (matrix-write-cell matrix cell))) (cdr (assoc chunk (gethash :tiles map))))) diff --git a/overworld.tiled.lisp b/overworld.tiled.lisp index ed08281..078e23c 100644 --- a/overworld.tiled.lisp +++ b/overworld.tiled.lisp @@ -19,7 +19,7 @@ (defpackage :flora-search-aurora.overworld.tiled (:nicknames :fsa.o.t :overworld.tiled) - (:use :cl + (:use :cl :anaphora-basic :flora-search-aurora.overworld.util) (:export #:load-map)) @@ -66,16 +66,16 @@ alist of Tiled cell “chunks”." (defun tiled-object->entity (tiled-obj tiled-map) "Convert a Tiled object into an entity plist." (let ((properties (cl-tiled:properties tiled-obj))) - (list (intern (string-upcase (gethash "id" properties #'string-equal))) + (list (intern (string-upcase (gethash "id" properties))) :coords (list :x (floor (/ (cl-tiled:object-x tiled-obj) (cl-tiled:map-tile-width tiled-map))) :y (floor (/ (cl-tiled:object-y tiled-obj) (cl-tiled:map-tile-height tiled-map)))) - :face (gethash "normal_face" properties #'string-equal) - :normal-face (gethash "normal_face" properties #'string-equal) - :talking-face (gethash "talking_face" properties #'string-equal) - :interact (gethash "interact" properties #'string-equal) - :direction (if (gethash "facing_right" properties #'string-equal) + :face (gethash "normal_face" properties) + :normal-face (gethash "normal_face" properties) + :talking-face (gethash "talking_face" properties) + :interact (gethash "interact" properties) + :direction (if (gethash "facing_right" properties) 'right 'left)))) @@ -95,22 +95,32 @@ alist of Tiled cell “chunks”." ;;; ——————————————————————————————————— ;;; Tile-layer parsing (graphics) ;;; ——————————————————————————————————— -(defun tiled-cell->cell (tiled-cell) +(defun tiled-cell->cell (tiled-cell &key (language nil)) "Convert a Tiled cell into a cell plist." (list :coords (list :x (cl-tiled:cell-column tiled-cell) :y (cl-tiled:cell-row tiled-cell)) - :char (tile-character (cl-tiled:cell-tile tiled-cell)))) + :char (tile-character (cl-tiled:cell-tile tiled-cell)) + :lang language)) + + +(defun tiled-layer-cells (layer) + "Given a Tiled layer, return all of its cells in our custom cell plist-format." + (let ((layer-lang + (…:langcode->keysym + (gethash "language" (cl-tiled:properties layer))))) + (mapcar (lambda (tiled-cell) + (tiled-cell->cell tiled-cell :language layer-lang)) + (cl-tiled:layer-cells layer)))) (defun tile-layer-chunks (layer &optional (chunks '())) "Given a Tiled tile-layer (that is, graphics of the map), parse it into an alist of Tiled cell “chunks”." - (let ((cells (mapcar #'tiled-cell->cell (cl-tiled:layer-cells layer)))) - (collect-items-into-groups - cells - (lambda (cell) - (world-coords-chunk (getf cell :coords))) - :groups chunks))) + (collect-items-into-groups + (tiled-layer-cells layer) + (lambda (cell) + (world-coords-chunk (getf cell :coords))) + :groups chunks)) (defun layer-objects (layer) @@ -144,7 +154,8 @@ with 15 characters-per-line." (mapcar (lambda (layer) (typecase layer (cl-tiled.data-types:tile-layer - (when (gethash "colliding" (cl-tiled:properties layer) #'string-equal) + ;; Add to the bump-map if the layer is colliding + (when (gethash "colliding" (cl-tiled:properties layer)) (setf bump-map (tile-layer-chunks layer bump-map))) (setf tile-chunks (tile-layer-chunks layer tile-chunks))) (cl-tiled.data-types:object-layer diff --git a/ui.lisp b/ui.lisp index 211027d..208fc23 100644 --- a/ui.lisp +++ b/ui.lisp @@ -20,7 +20,7 @@ (defpackage :flora-search-aurora.ui (:nicknames :fsa.u :ui :📋) (:use :cl :assoc-utils) - (:export #:menu-state + (:export #:menu-state #:make-menu-state #:render-line #:render-string #:render-string-partially :label :selection :selected)) @@ -29,7 +29,13 @@ ;;; ——————————————————————————————————— ;;; Menu loops -;;; ——————————————————————————————————— +;;; —————————————————————————————————— +(defun make-menu-state (menu-list) + "Return a state-function for the game’s main menu, for use with STATE-LOOP." + (lambda (matrix) + (📋:menu-state matrix menu-list))) + + (defun menu-state (matrix menu-alist) "Render a menu in menu-alist format to the given matrix, and process user-input. A state-function for use with the #'state-loop." diff --git a/util.lisp b/util.lisp index d99d20c..fb8f88a 100644 --- a/util.lisp +++ b/util.lisp @@ -20,7 +20,10 @@ (defpackage :flora-search-aurora.util (:nicknames :fsa.ut :util :…) (:use :cl :assoc-utils) - (:export #:split-string-by-length #:plist= #:at-least #:at-most #:system-language)) + (:export #:split-string-by-length + #:plist= + #:at-least #:at-most + #:system-language #:langcode->keysym)) (in-package :flora-search-aurora.util) @@ -71,10 +74,17 @@ minimum returns your more pitiful of moments." num)) +(defun langcode->keysym (str) + "Given a language’s code (es/cz/it/etc.), return a corresponding key symbol, +if the language is among the supported. Otherwise, nil." + (when (stringp str) + (let ((lang (string-downcase (subseq str 0 2)))) + (cond + ((string-equal lang "eo") :eo) + ((string-equal lang "en") :en))))) + + (defun system-language () "Return the system language, if among the supported; otherwise, EN-glish." - (let ((lang (subseq (uiop:getenv "LANG") 0 2))) - (cond - ((string-equal lang "eo") :eo) - ((string-equal lang "en") :en) - ('t :en)))) + (or (langcode->keysym (uiop:getenv "LANG")) + :en))