1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022 Zull
4 ;;;; This program is free software: you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation, either version 3 of the License, or
7 ;;;; (at your option) any later version.
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;;; GNU General Public License for more details.
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17 (in-package :rulp.core)
19 (defun decode-from-json (json-file)
20 "take a json file path and decode it"
21 (with-open-file (json-stream json-file)
22 (values (json:decode-json json-stream)
23 (make-pathname :directory (pathname-directory json-file)))))
25 ;; this definition is hard coded, when planes will change this
26 ;; function needs to be edited alike. Look for a better and
27 ;; auto modifiable solution.
28 (defun create-plane-from-json (json-file)
29 "take a parsed alist and create a plane on those specs"
30 (let* ((json-position (make-pathname :directory (pathname-directory json-file)))
31 (alist (decode-from-json json-file))
32 (img-path (merge-pathnames json-position (cdr (assoc ':image-path alist))))
33 (ret (make-instance 'rulp.layers:screen :image img-path)))
34 ;; (when (assoc ':size alist) (setf (layers:size ret) (cdr (assoc ':size alist))))
35 ;; (when (assoc ':grid-dimension alist) (setf (graphics:-dimension ret) (cdr (assoc ':grid-dimension alist))))
39 ;; posso usare le hash piuttosto che interpretarlo sul momento. Infatti creerò un metodo che
40 ;; analizza json e lo traduce in una tabella hash e una funzione che prende la hash e crea
41 ;; l'oggetto tramite i metodi standard.
43 ;; (defparameter a (make-hash-table)) ; crea una hash con make-hash-table
44 ;; (gethash 'key a) ; recupera la hash con chiave key, questa è settable
45 (defun parse-list (linput)
46 (if (listp (car linput))
47 (loop :for l :in linput
50 (FORMAT t "TEXT IS ~A, ~A AND ~A~%" (CAR LINPUT) (CADR LINPUT) (CADDR LINPUT)) ; devi ricordanti che i campi non sono (a b c) ma sono ((a1 . a2) (b1 . b2) (c1 . c2))
53 (defun decompose-alist (alist search-list)
54 (apply 'concatenate 'list
55 (loop :for search-term :in search-list
57 (when (assoc search-term alist)
59 (cdr (assoc search-term alist))))