OSDN Git Service

graphics/package.lisp: resolved defchain kickstart
[rulp/rulp.git] / graphics / package.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 (defpackage :rulp.graphics
18   (:use :cl :rulp.layers :rulp.geometry)
19   (:export
20    playground +plane+ *plane* *plane-grid* *map-info* *map-path* *entities-list*
21    arrange-rect *window-width* *window-height* tr-write defchain
22            ))
23 ;; NOTE: remove +plane+, there is no other occurrence of the parameter on the code
24
25 (in-package :rulp.graphics)
26
27 ;; these variables contain information for the plane and grid systems. The default
28 ;; grid is a square grid but by changing the grid-layout function it is possible
29 ;; to modify it
30 (defparameter *plane* nil
31   "the plane containing the graphics to be desplayed on the background. This is a
32 basic layout:screen")
33
34 (defparameter *plane-grid* 10
35   "the grid for the plane. By default the grid is square and this value contain the
36 pixels between lines")
37
38 (defparameter *entities-list* nil
39   "the list of the entities to be displayed on the plane. these entities are global and
40 by default not connected to the *plane* choice. To change planes and entities use the proper
41 functions")
42
43 (defparameter *renderer* nil
44   "a variable containing the tool to render textures to screen, this is associated
45 with the screen and created in the view file but used almost everywhere. this is a
46 side variable and cannot be moved in a sdl enviroinment.")
47
48 (defparameter *pointer* nil
49   "this is a numeric value whose refer to the selected entity in the plane, it is
50 used combined with input to apply the actions and with view to display a 1x1 over
51 grid square of the entity")
52
53 ;; tr stands for text-rendering
54 (defparameter *tr-string* "abcdefghijklmnopqrstuvwxyz 0123456789-"
55   "This string is used to generate a texture with the alphabet, the software
56 in the text.lisp file will 'write' on the screen selecting squares and using
57 this string again to parse a string variable into coordinate in the texture")
58
59 (defparameter *alphabet* "abcdefghijklmnopqrstuvwxyz-"
60   "this is used to generate the grid, when the coordinates run out of letters
61 they restart from the beginning")
62
63 (defparameter *tr-texture* nil
64   "this contains the texture of the characters from *tr-string*. This
65 will be used to create text on screen by applying the single letters
66 with render-copy")
67
68 (defconstant +mouse-button-left+ 1 "this binds the left button")
69 (defconstant +mouse-button-right+ 3 "this binds the right button")
70 (defconstant +mouse-button-middle+ 2 "this binds the scroll button")
71
72 ;; FIXME: replace with apply system and fixed arguments *mouse-position*, *mouse-previous-position* *viewpoint-offset*
73 (defparameter *mouse-keybinds* (list
74                                 '(+mouse-button-left+ nil (select-pointer *mouse-position* *entities-list*))
75                                 '(+mouse-button-middle+ (panning *viewpoint-offset* (velocity *mouse-position* *mouse-previous-position*)) nil)
76                                 '(+mouse-button-right+ nil (move-entity *mouse-position*))
77                                 ;; '(+mouse-button-right+ nil (push (summon-entry *mouse-position* '(1)) *active-entries*))
78                                 )
79   "This is the mouse-keybinds association list. The first value is the button, the second
80 is the action executed on hold and the third is the action executed on release (if any)")
81
82
83 (defparameter *is-grid* t
84   "Parameter for displaying the grid, when nil it does not display a grid, when t
85 it display a grid as defined by the *plane-grid*")
86 (defparameter *is-indexes* t
87   "Parameter for displaying the indexes, when nil it does not display them, when t
88 it uses the grid to create a chessboard like indexes")
89
90 (defparameter *window-width* 1001)
91 (defparameter *window-height* 750)
92
93 ;; NOTE: probably they need to be moved below in layers, for now they can stay here
94 (defparameter *map-info* nil
95   "when the json informations are read, the content is dumped into this parameter and then
96 used on uninitialized data to bootstrap the data")
97
98 (defparameter *map-path* nil
99   "this is the path where the json file lived")
100
101 (defun kick-start-chain ()
102   (progn
103     (defvar *execute-before* nil)
104     (defvar *execute-in-viewpoint* nil)
105     (defvar *execute-in-window* nil)
106     (defvar *execute-after* nil)
107     (defmacro defchain (chain-name where &body body)
108       `(progn
109          (defun ,chain-name ()
110            ,@body)
111          (cond
112            ((eq ,where :before) (push ',chain-name *execute-before*))
113            ((eq ,where :viewpoint) (push ',chain-name *execute-in-viewpoint*))
114            ((eq ,where :window) (push ',chain-name *execute-in-window*))
115            ((eq ,where :after) (push ',chain-name *execute-after*))
116            )
117          )
118       )))
119
120 (kick-start-chain)