OSDN Git Service

support for an init.lisp file for initial setup
authorGiulio De Stasio <giuliodestasio98@gmail.com>
Wed, 16 Nov 2022 19:24:42 +0000 (20:24 +0100)
committerGiulio De Stasio <giuliodestasio98@gmail.com>
Wed, 16 Nov 2022 19:24:42 +0000 (20:24 +0100)
Signed-off-by: Giulio De Stasio <giuliodestasio98@gmail.com>
core.lisp
data.lisp
graphics/inputs.lisp
graphics/package.lisp
graphics/view.lisp
layers/models.lisp
layers/screens.lisp
script.lisp [new file with mode: 0644]
system.asd

index 9a0e1c8..f739442 100644 (file)
--- a/core.lisp
+++ b/core.lisp
@@ -11,7 +11,8 @@
             parameters:*rulp-version*
             parameters:*rulp-system*
             parameters:*rulp-arch*)
-;    (graphics:playground *screen-width* *screen-height* name)
+    (load "init.lisp" :if-does-not-exist nil)
+    ;; (graphics:playground *screen-width* *screen-height* name)
     (bt:make-thread (lambda () (graphics:playground *screen-width* *screen-height* name)))
 ;    (gui:lobby)
     )
index b2d7c23..10f7e8a 100644 (file)
--- a/data.lisp
+++ b/data.lisp
@@ -1,5 +1,22 @@
+;;;; Ru*** roLeplay Playground virtual tabletop
+;;;; Copyright (C) 2022  Zull
+;;;;
+;;;; 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 <https://www.gnu.org/licenses/>.
 (in-package :core)
 
+
+
 ;; posso usare le hash piuttosto che interpretarlo sul momento. Infatti creerò un metodo che
 ;; analizza json e lo traduce in una tabella hash e una funzione che prende la hash e crea
 ;; l'oggetto tramite i metodi standard.
 ;; (gethash 'key a) ; recupera la hash con chiave key, questa è settable
 (defun parse-list (linput)
   (if (listp (car linput))
-          (loop :for l :in linput
-                :do
-                (parse-list l))
-          (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))
-          ))
+      (loop :for l :in linput
+            :do
+               (parse-list l))
+      (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))
+      ))
 
 (defun decompose-alist (alist search-list)
   (apply 'concatenate 'list
index 2ccf0a6..6212224 100644 (file)
@@ -22,7 +22,7 @@
   (:documentation "given x y and the button pressed it do actions"))
 
 (defmethod activate (x y pressed (p plane))
-  (loop :for key :in *keybinds*
+  (loop :for key :in *mouse-keybinds*
         :do
            (when (sdl2:mouse-state-p (eval (car key)))
              (apply (cadr key) `(,x ,y ,p))
index 90cf5e8..e0ae234 100644 (file)
@@ -17,7 +17,7 @@
 (defpackage :graphics
   (:use :cl :layers)
   (:export
-   playground
+   playground +plane+
            ))
 
 (in-package :graphics)
@@ -56,10 +56,10 @@ with render-copy")
 (defparameter +mouse-button-right+ 3)
 (defparameter +mouse-button-middle+ 2)
 
-(defparameter *keybinds* (list
-                          '(+mouse-button-left+ select-pointer)
-                          '(+mouse-button-right+ move-entity)
-                          )
+(defparameter *mouse-keybinds* (list
+                                '(+mouse-button-left+ select-pointer)
+                                '(+mouse-button-right+ move-entity)
+                                )
   "this is a list of actions connected to mouse presses, this can be edited
 here if needed"
   )
index 4224470..07b8944 100644 (file)
                                                                                 font-surface)))
                            (sdl2:free-surface font-surface)
                            font-texture))
-      (setf +plane+ (make-instance 'plane :image (truename "media/board.tga")))
-      (setf (entities-list +plane+) (list (make-instance 'entity)))
       (sdl2:with-event-loop (:method :poll)
         (:quit () t)
+        (:keyup (:keysym keysym)
+                (when (sdl2:scancode= (sdl2:scancode-value keysym) :scancode-q)
+                  (format t "pressed q~%")))
         (:mousebuttondown (:x x :y y :state state)
                           (activate x y state +plane+))
         (:idle ()
index f1229be..3eabd76 100644 (file)
    ))
 
 (defmethod create-entity ((m model))
+  "create an entity from the standard model"
   (let* ((return-entity m))
-    (change-class return-entity 'entity)
-    return-entity))
+    (make-instance 'entity
+                   :name (name m)
+                   :movement (movement m)
+                   :size (size m)
+                   :interactions (interactions m))))
index 7f57e34..6260a1b 100644 (file)
@@ -126,3 +126,8 @@ where the screen should be displayed"))
 (defmethod screen-destination ((s screen) (p t))
   (sdl2:make-rect (x s) (y s) (width s) (height s))
   )
+
+(defmethod screen-purge ((s screen))
+  "purge screens video data. This data is automatically generated during rendering"
+  (sdl2:destroy-texture (texture s))
+  (sdl2:free-surface (surface s)))
diff --git a/script.lisp b/script.lisp
new file mode 100644 (file)
index 0000000..68d9821
--- /dev/null
@@ -0,0 +1,62 @@
+;;;; Ru*** roLeplay Playground virtual tabletop
+;;;; Copyright (C) 2022  Zull
+;;;;
+;;;; 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 <https://www.gnu.org/licenses/>.
+
+(defpackage :script
+  (:use :cl :graphics :layers))
+
+(in-package :script)
+
+(defun active-plane ()
+  graphics:+plane+)
+
+(defun (setf active-plane) (value)
+  (setf graphics:+plane+ value))
+
+(defun entities ()
+  (entities-list graphics:+plane+))
+
+(defun (setf entities) (value)
+  (if (listp value)
+      (setf (entities-list graphics:+plane+) value)
+      (error "(setf entities) error: given symbol is not a list")))
+
+(defun add-entity (entity)
+  "add an entity into the active plane"
+  (push entity graphics:+plane+))
+
+(defun remove-entity (number)
+  "remove the nth entity from the active plane"
+  (screen-purge (nth number (entities-list graphics:+plane+)))
+  (setf (nth number (entities-list graphics:+plane+)) nil)
+  (remove nil (entities-list graphics:+plane+)))
+
+(defparameter *plane-list* nil)
+
+(defun new-plane (image)
+  "create a new plane and add it to the plane list"
+  (let ((gen-plane (make-instance 'plane :image image)))
+        (push gen-plane *plane-list*)
+        gen-plane))
+
+(defun remove-plane (number)
+  "remove the nth plane from the plane list"
+  (screen-purge (nth number *plane-list*))
+  (setf (nth number *plane-list*) nil)
+  (setf *plane-list* (remove nil *plane-list*)))
+
+(defun list-planes ()
+  "list the content in the plane list"
+  *plane-list*)
index 101146a..608d8db 100644 (file)
@@ -12,7 +12,7 @@
 ;;;; 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 <https://www.gnu.org/licenses/>.
+;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
 
 (asdf:defsystem "rulp"
   :description "Ru*** roLeplay Playground: a digital table for roleplay games"
@@ -47,5 +47,6 @@
 ;                :components ((:file "package")
 ;                             (:file "skeleton")))
                (:file "package" :depends-on ("graphics"))
+               (:file "script" :depends-on ("graphics"))
                (:file "data" :depends-on ("package" "parameters"))
                (:file "core" :depends-on ("package" "parameters"))))