From e1fe5afb75fe4a199b1486cf28427914d13e8774 Mon Sep 17 00:00:00 2001 From: Giulio De Stasio Date: Wed, 16 Nov 2022 20:24:42 +0100 Subject: [PATCH] support for an init.lisp file for initial setup Signed-off-by: Giulio De Stasio --- core.lisp | 3 ++- data.lisp | 27 +++++++++++++++++----- graphics/inputs.lisp | 2 +- graphics/package.lisp | 10 ++++----- graphics/view.lisp | 5 +++-- layers/models.lisp | 8 +++++-- layers/screens.lisp | 5 +++++ script.lisp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ system.asd | 3 ++- 9 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 script.lisp diff --git a/core.lisp b/core.lisp index 9a0e1c8..f739442 100644 --- 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) ) diff --git a/data.lisp b/data.lisp index b2d7c23..10f7e8a 100644 --- 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 . (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. @@ -8,11 +25,11 @@ ;; (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 diff --git a/graphics/inputs.lisp b/graphics/inputs.lisp index 2ccf0a6..6212224 100644 --- a/graphics/inputs.lisp +++ b/graphics/inputs.lisp @@ -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)) diff --git a/graphics/package.lisp b/graphics/package.lisp index 90cf5e8..e0ae234 100644 --- a/graphics/package.lisp +++ b/graphics/package.lisp @@ -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" ) diff --git a/graphics/view.lisp b/graphics/view.lisp index 4224470..07b8944 100644 --- a/graphics/view.lisp +++ b/graphics/view.lisp @@ -46,10 +46,11 @@ 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 () diff --git a/layers/models.lisp b/layers/models.lisp index f1229be..3eabd76 100644 --- a/layers/models.lisp +++ b/layers/models.lisp @@ -23,6 +23,10 @@ )) (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)))) diff --git a/layers/screens.lisp b/layers/screens.lisp index 7f57e34..6260a1b 100644 --- a/layers/screens.lisp +++ b/layers/screens.lisp @@ -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 index 0000000..68d9821 --- /dev/null +++ b/script.lisp @@ -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 . + +(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*) diff --git a/system.asd b/system.asd index 101146a..608d8db 100644 --- a/system.asd +++ b/system.asd @@ -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 . +;;;; along with this program. If not, see . (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")))) -- 2.11.0