diff --git a/figlet.lisp b/figlet.lisp new file mode 100644 index 0000000..892bfde --- /dev/null +++ b/figlet.lisp @@ -0,0 +1,67 @@ +;;;; Copyright © 2023, Jaidyn Ann +;;;; +;;;; This program is free software: you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License as +;;;; published by the Free Software Foundation, either version 3 of +;;;; the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program. If not, see . + +;;;; FIGLET +;;;; A package for parsing Figlet fonts into simple associative lists, for +;;;; devious text-rendering purposes. + +(in-package :figlet) + + +(defun string->integer (string) + "Convert a string to a number, potentially in 0x… hexadecimal form. +If no number is parsed out, return NIL." + (let ((radix (if (str:starts-with-p "0x" string) + 16 10)) + (string (if (str:starts-with-p "0x" string) + (subseq string 2) string))) + (ignore-errors (parse-integer string :radix radix)))) + + +(defun parse-lines (lines &optional (font-plist '()) (current-symbol 32)) + "Parse a list of lines from a Figlet font-file (.FLF) into a plist +associating a character with its respective string in the font-file. + (#\A \"TEXT-ART-A\" #\B \"TEXT-ART-B\" …)" + (if lines + (let* ((line (car lines)) + (sans-@ (cl:string-trim "@" line)) + (last-of-symbol-p (str:ends-with-p "@@" line)) + (not-art-line (not (str:ends-with-p "@" line))) + (first-word (car (str:split " " line))) + (first-word-num (string->integer first-word)) + (new-symbol-header-p (and not-art-line first-word-num))) + (cond (new-symbol-header-p + (parse-lines (cdr lines) font-plist first-word-num)) + ((not not-art-line) + (setf (getf font-plist (code-char current-symbol)) + (format nil "~A~A~%" + (or (getf font-plist (code-char current-symbol)) + "") + sans-@)) + (parse-lines (cdr lines) font-plist (if last-of-symbol-p + (+ current-symbol 1) + current-symbol))) + ('t + (parse-lines (cdr lines) font-plist current-symbol)))) + font-plist)) + + +(defun figlet-font-plist (path) + "Parse a Figlet font-file (.FLF) into a plist associating a character +with its respective string in the font-file. + (#\A \"TEXT-ART-A\" #\B \"TEXT-ART-B\" …)" + (parse-lines + (str:lines + (alexandria:read-file-into-string path)))) diff --git a/packages.lisp b/packages.lisp index a0beace..98e4e99 100644 --- a/packages.lisp +++ b/packages.lisp @@ -30,10 +30,10 @@ (:export #:read-char-plist #:read-gamefied-char-plist #:normalize-char-plist #:gameify-char-plist #:plist-char-p - :control :meta :shift - +qwerty-layout+ +dvorak-layout+ - +arrows-game-layout+ +wasd-game-layout+ +ijkl-game-layout+ - :↑ :← :→ :↓ :🆗 :❎)) + :control :meta :shift + +qwerty-layout+ +dvorak-layout+ + +arrows-game-layout+ +wasd-game-layout+ +ijkl-game-layout+ + :↑ :← :→ :↓ :🆗 :❎)) (defpackage :flora-search-aurora.display (:nicknames :fsa.d :display :✎) @@ -46,14 +46,14 @@ (:use :cl :assoc-utils) (:export #:menu-state #:make-menu-state #:render-line #:render-string #:render-string-partially - :label :selection :selected)) + :label :selection :selected)) (defpackage :flora-search-aurora.dialogue (:nicknames :fsa.dia :dialogue :💬) (:use :cl) (:export #:dialogue-state #:make-dialogue-state #:start-dialogue #:face #:say #:mumble #:move - :normal-face :talking-face)) + :normal-face :talking-face)) (defpackage :flora-search-aurora.inventory (:nicknames :fsa.inv :inventory :🎒) @@ -64,11 +64,11 @@ (:nicknames :fsa.o.u :overworld.util :🌍.…) (:use :cl) (:export #:coords->symbol #:symbol->coords - #:world-coords->screen-coords - #:world-coords-chunk - #:map->plist #:plist->map - #:string->symbol - #:save-map-to-file)) + #:world-coords->screen-coords + #:world-coords-chunk + #:map->plist #:plist->map + #:string->symbol + #:save-map-to-file)) (defpackage :flora-search-aurora.overworld (:nicknames :fsa.o :overworld :🌍) @@ -91,9 +91,12 @@ (defpackage :flora-search-aurora (:nicknames :fsa :✿) (:export #:main - :player) + :player) (:use :cl :flora-search-aurora.input :flora-search-aurora.display :flora-search-aurora.overworld :flora-search-aurora.dialogue :flora-search-aurora.ui)) +(defpackage :figlet-font-plist + (:export #:parse-figlet-font-file) + (:use cl))