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 (defparameter *screen-width* 1000)
20 (defparameter *screen-height* 750)
23 ;; here there are the functions that would parse the files.
24 ;; this is useful so it is possible to have all the informations
27 (defun test-correctness-required (file extension)
28 (unless (probe-file file)
29 (error "File \"~A\" not found, exits~%" file)) ; test existance
30 (unless (equal (pathname-type file) extension)
31 (error "File \"~A\" is not \"~A\", exits~%" file extension)) ; map file is json
34 (defun test-correctness-optional (file extension)
36 (unless (probe-file file)
37 (error "File \"~A\" not found, exits~%" file)) ; test existance
38 (unless (equal (pathname-type file) extension)
39 (error "File \"~A\" is not \"~A\", exits~%" file extension)) ; map file is json
44 ;; This is the main command "rulp", it includes the
45 ;; global options and the subcommands
46 (defun rulp/handler (cmd)
48 (let ((mapfile (clingon:getopt cmd :rulp/map))
49 (initfile (clingon:getopt cmd :rulp/initfile))
50 (softwarep (clingon:getopt cmd :rulp/softwarep))
51 (name (format nil "Ru*** roLeplay Playground v~A" rulp.parameters:+rulp-version+)))
52 (test-correctness-required mapfile "json")
53 (test-correctness-optional initfile "lisp")
54 (format t "rulp-~A on ~A-~A~%"
55 rulp.parameters:+rulp-version+
56 rulp.parameters:+rulp-system+
57 rulp.parameters:+rulp-type+)
58 (if initfile (load initfile) (load "init.lisp" :if-does-not-exist nil))
59 (multiple-value-bind (json path) (decode-from-json mapfile)
60 (setf rulp.graphics:*map-info* json)
61 (setf rulp.graphics:*map-path* path))
62 (rulp.graphics:playground name)))
64 (defun rulp/command ()
68 :description "Roleplay playground"
69 :authors '("Giulio 'Zull' De Stasio <giuliodestasio98@gmail.com>")
70 :usage "[-i INITFILE] -m map [COMMAND]"
72 :handler #'rulp/handler
73 :options (rulp/options)
74 :examples '(("rulp -m map.json") ("rulp -m map.json editor"))
75 :sub-commands (rulp/sub-commands)))
77 (defun rulp/options ()
79 (clingon:make-option :counter
80 :description "get a verbose output on STDOUT"
84 (clingon:make-option :string
85 :description "manually select init file, by default it uses init.lisp"
89 (clingon:make-option :string
90 :description "Select the map to load (in JSON format)"
95 (clingon:make-option :counter
96 :description "select software rendering (not working)"
101 (defun rulp/sub-commands ()
102 "list of the subcommands of rulp"
108 ;; this section modify the view to create a functional
109 ;; map editor. It create a map, collisions and interactive objects
110 ;; to be used later on view mode
111 (defun editor/options ()
113 (clingon:make-option :string
114 :description "select map to edit"
119 (defun editor/command ()
120 (clingon:make-command
123 :description "start the editor with the selected map"
124 :options (editor/options)
125 :handler #'editor/handler
126 :examples '("rulp editor -m base.png")))
128 (defun editor/handler (cmd)
129 (let ((mapfile (clingon:getopt cmd :editor/map))
130 (initfile (clingon:getopt cmd :rulp/initfile))
131 (softwarep (clingon:getopt cmd :rulp/softwarep)))
132 (format t "test ~A and ~A~%" mapfile initfile)))
135 (let ((rulp-sys (rulp/command)))
136 (clingon:run rulp-sys)
140 ;; "Ru■■■ Lisp Playground"
142 (defun repl-pipe (mapfile &optional initfile)
143 (test-correctness-required mapfile "json")
144 (test-correctness-optional initfile "lisp")
145 (format t "rulp-~A on ~A-~A~%"
146 rulp.parameters:+rulp-version+
147 rulp.parameters:+rulp-system+
148 rulp.parameters:+rulp-type+)
149 (if initfile (load initfile) (load "init.lisp" :if-does-not-exist nil))
150 (multiple-value-bind (json path) (decode-from-json mapfile)
151 (setf rulp.graphics:*map-info* json)
152 (setf rulp.graphics:*map-path* path))
153 ;; (setf graphics:*plane* (create-plane-from-json mapfile))
154 (sb-thread:make-thread (lambda () (rulp.graphics:playground (format nil "RULP over repl"))))
157 (defun start () (repl-pipe "lab/test2.json"))