Language-specific map layers
This commit is contained in:
parent
495ed87f09
commit
dafccb17a1
|
@ -176,7 +176,9 @@ A core part of OVERWORLD-STATE."
|
||||||
&key (chunk-width 72) (chunk-height 20))
|
&key (chunk-width 72) (chunk-height 20))
|
||||||
"Draw a map’s specific chunk (by its ID) to the matrix."
|
"Draw a map’s specific chunk (by its ID) to the matrix."
|
||||||
(mapcar (lambda (cell)
|
(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)))))
|
(cdr (assoc chunk (gethash :tiles map)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
(defpackage :flora-search-aurora.overworld.tiled
|
(defpackage :flora-search-aurora.overworld.tiled
|
||||||
(:nicknames :fsa.o.t :overworld.tiled)
|
(:nicknames :fsa.o.t :overworld.tiled)
|
||||||
(:use :cl
|
(:use :cl :anaphora-basic
|
||||||
:flora-search-aurora.overworld.util)
|
:flora-search-aurora.overworld.util)
|
||||||
(:export #:load-map))
|
(:export #:load-map))
|
||||||
|
|
||||||
|
@ -66,16 +66,16 @@ alist of Tiled cell “chunks”."
|
||||||
(defun tiled-object->entity (tiled-obj tiled-map)
|
(defun tiled-object->entity (tiled-obj tiled-map)
|
||||||
"Convert a Tiled object into an entity plist."
|
"Convert a Tiled object into an entity plist."
|
||||||
(let ((properties (cl-tiled:properties tiled-obj)))
|
(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)
|
:coords (list :x (floor (/ (cl-tiled:object-x tiled-obj)
|
||||||
(cl-tiled:map-tile-width tiled-map)))
|
(cl-tiled:map-tile-width tiled-map)))
|
||||||
:y (floor (/ (cl-tiled:object-y tiled-obj)
|
:y (floor (/ (cl-tiled:object-y tiled-obj)
|
||||||
(cl-tiled:map-tile-height tiled-map))))
|
(cl-tiled:map-tile-height tiled-map))))
|
||||||
:face (gethash "normal_face" properties #'string-equal)
|
:face (gethash "normal_face" properties)
|
||||||
:normal-face (gethash "normal_face" properties #'string-equal)
|
:normal-face (gethash "normal_face" properties)
|
||||||
:talking-face (gethash "talking_face" properties #'string-equal)
|
:talking-face (gethash "talking_face" properties)
|
||||||
:interact (gethash "interact" properties #'string-equal)
|
:interact (gethash "interact" properties)
|
||||||
:direction (if (gethash "facing_right" properties #'string-equal)
|
:direction (if (gethash "facing_right" properties)
|
||||||
'right
|
'right
|
||||||
'left))))
|
'left))))
|
||||||
|
|
||||||
|
@ -95,22 +95,32 @@ alist of Tiled cell “chunks”."
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
;;; Tile-layer parsing (graphics)
|
;;; 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."
|
"Convert a Tiled cell into a cell plist."
|
||||||
(list :coords (list :x (cl-tiled:cell-column tiled-cell)
|
(list :coords (list :x (cl-tiled:cell-column tiled-cell)
|
||||||
:y (cl-tiled:cell-row 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 '()))
|
(defun tile-layer-chunks (layer &optional (chunks '()))
|
||||||
"Given a Tiled tile-layer (that is, graphics of the map), parse it into an
|
"Given a Tiled tile-layer (that is, graphics of the map), parse it into an
|
||||||
alist of Tiled cell “chunks”."
|
alist of Tiled cell “chunks”."
|
||||||
(let ((cells (mapcar #'tiled-cell->cell (cl-tiled:layer-cells layer))))
|
|
||||||
(collect-items-into-groups
|
(collect-items-into-groups
|
||||||
cells
|
(tiled-layer-cells layer)
|
||||||
(lambda (cell)
|
(lambda (cell)
|
||||||
(world-coords-chunk (getf cell :coords)))
|
(world-coords-chunk (getf cell :coords)))
|
||||||
:groups chunks)))
|
:groups chunks))
|
||||||
|
|
||||||
|
|
||||||
(defun layer-objects (layer)
|
(defun layer-objects (layer)
|
||||||
|
@ -144,7 +154,8 @@ with 15 characters-per-line."
|
||||||
(mapcar (lambda (layer)
|
(mapcar (lambda (layer)
|
||||||
(typecase layer
|
(typecase layer
|
||||||
(cl-tiled.data-types:tile-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 bump-map (tile-layer-chunks layer bump-map)))
|
||||||
(setf tile-chunks (tile-layer-chunks layer tile-chunks)))
|
(setf tile-chunks (tile-layer-chunks layer tile-chunks)))
|
||||||
(cl-tiled.data-types:object-layer
|
(cl-tiled.data-types:object-layer
|
||||||
|
|
10
ui.lisp
10
ui.lisp
|
@ -20,7 +20,7 @@
|
||||||
(defpackage :flora-search-aurora.ui
|
(defpackage :flora-search-aurora.ui
|
||||||
(:nicknames :fsa.u :ui :📋)
|
(:nicknames :fsa.u :ui :📋)
|
||||||
(:use :cl :assoc-utils)
|
(:use :cl :assoc-utils)
|
||||||
(:export #:menu-state
|
(:export #:menu-state #:make-menu-state
|
||||||
#:render-line #:render-string #:render-string-partially
|
#:render-line #:render-string #:render-string-partially
|
||||||
:label :selection :selected))
|
:label :selection :selected))
|
||||||
|
|
||||||
|
@ -29,7 +29,13 @@
|
||||||
|
|
||||||
;;; ———————————————————————————————————
|
;;; ———————————————————————————————————
|
||||||
;;; Menu loops
|
;;; 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)
|
(defun menu-state (matrix menu-alist)
|
||||||
"Render a menu in menu-alist format to the given matrix, and process user-input.
|
"Render a menu in menu-alist format to the given matrix, and process user-input.
|
||||||
A state-function for use with the #'state-loop."
|
A state-function for use with the #'state-loop."
|
||||||
|
|
22
util.lisp
22
util.lisp
|
@ -20,7 +20,10 @@
|
||||||
(defpackage :flora-search-aurora.util
|
(defpackage :flora-search-aurora.util
|
||||||
(:nicknames :fsa.ut :util :…)
|
(:nicknames :fsa.ut :util :…)
|
||||||
(:use :cl :assoc-utils)
|
(: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)
|
(in-package :flora-search-aurora.util)
|
||||||
|
|
||||||
|
@ -71,10 +74,17 @@ minimum returns your more pitiful of moments."
|
||||||
num))
|
num))
|
||||||
|
|
||||||
|
|
||||||
(defun system-language ()
|
(defun langcode->keysym (str)
|
||||||
"Return the system language, if among the supported; otherwise, EN-glish."
|
"Given a language’s code (es/cz/it/etc.), return a corresponding key symbol,
|
||||||
(let ((lang (subseq (uiop:getenv "LANG") 0 2)))
|
if the language is among the supported. Otherwise, nil."
|
||||||
|
(when (stringp str)
|
||||||
|
(let ((lang (string-downcase (subseq str 0 2))))
|
||||||
(cond
|
(cond
|
||||||
((string-equal lang "eo") :eo)
|
((string-equal lang "eo") :eo)
|
||||||
((string-equal lang "en") :en)
|
((string-equal lang "en") :en)))))
|
||||||
('t :en))))
|
|
||||||
|
|
||||||
|
(defun system-language ()
|
||||||
|
"Return the system language, if among the supported; otherwise, EN-glish."
|
||||||
|
(or (langcode->keysym (uiop:getenv "LANG"))
|
||||||
|
:en))
|
||||||
|
|
Ŝarĝante…
Reference in New Issue