OSDN Git Service

view: entities-list in plane and fixes
[rulp/rulp.git] / core.lisp
1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022  Zull
3 ;;;;
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.
8 ;;;;
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.
13 ;;;;
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/>.
16
17 (in-package :rulp.core)
18
19 (defparameter *screen-width* 1000)
20 (defparameter *screen-height* 750)
21
22 ;; Parse json maps
23 ;; here there are the functions that would parse the files.
24 ;; this is useful so it is possible to have all the informations
25 ;; saved in one file.
26
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
32   t)
33
34 (defun test-correctness-optional (file extension)
35   (when file
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
40     )
41   t)
42
43 ;; RULP command
44 ;; This is the main command "rulp", it includes the
45 ;; global options and the subcommands
46 (defun rulp/handler (cmd)
47   "handling the view"
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)))
63
64 (defun rulp/command ()
65   (clingon:make-command
66    :name "rulp"
67    :version "0.0.1"
68    :description "Roleplay playground"
69    :authors '("Giulio 'Zull' De Stasio <giuliodestasio98@gmail.com>")
70    :usage "[-i INITFILE] -m map [COMMAND]"
71    :license "GPLv3"
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)))
76
77 (defun rulp/options ()
78   (list
79    (clingon:make-option :counter
80                         :description "get a verbose output on STDOUT"
81                         :short-name #\v
82                         :long-name "verbose"
83                         :key :rulp/verbose)
84    (clingon:make-option :string
85                         :description "manually select init file, by default it uses init.lisp"
86                         :short-name #\i
87                         :long-name "init"
88                         :key :rulp/initfile)
89    (clingon:make-option :string
90                         :description "Select the map to load (in JSON format)"
91                         :short-name #\m
92                         :required t
93                         :long-name "map"
94                         :key :rulp/map)
95    (clingon:make-option :counter
96                         :description "select software rendering (not working)"
97                         :long-name "software"
98                         :key :rulp/softwarep)
99    ))
100
101 (defun rulp/sub-commands ()
102     "list of the subcommands of rulp"
103   (list
104    (editor/command)))
105
106
107 ;; EDITOR command
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 ()
112   (list
113    (clingon:make-option :string
114                         :description "select map to edit"
115                         :short-name #\m
116                         :long-name "map"
117                         :key :editor/map)))
118
119 (defun editor/command ()
120   (clingon:make-command
121    :name "editor"
122    :usage "-m <MAP>"
123    :description "start the editor with the selected map"
124    :options (editor/options)
125    :handler #'editor/handler
126    :examples '("rulp editor -m base.png")))
127
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)))
133
134 (defun main ()
135   (let ((rulp-sys (rulp/command)))
136     (clingon:run rulp-sys)
137     )
138   )
139
140 ;; "Ru■■■ Lisp Playground"
141
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"))))
155   )
156
157 (defun start () (repl-pipe "lab/test2.json"))