(defparameter *map-path* nil
"this is the path where the json file lived")
-(defparameter *execute-before* '())
-(defparameter *execute-in-viewpoint* '())
-(defparameter *execute-in-window* '())
-(defparameter *execute-after* '())
-
-
-;; FIXME: define push-once to avoid loading many times the same function from
-;; slime/sly
-(defmacro defchain (chain-name where &body body)
- (cond
- ((eq where :before) (push chain-name *execute-before*))
- ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*))
- ((eq where :window) (push chain-name *execute-in-window*))
- ((eq where :after) (push chain-name *execute-after*))
- )
- `(defun ,chain-name ()
- ,@body))
-
-
-(defchain render-plane-and-entities :viewpoint
-;; "using *plane* and *entities-list* the macro display on the current rendering texture
-;; the plane 'as is' and the entities with the grid-layout function"
- (when *plane*
- ;; NOTE: add error for non-screen planes
- (display *plane* t)
- (loop :for entity :in (entities-list *plane*)
- :do
- (when (displayp entity)
- (display entity (plane-grid *plane*))
- ))) ; FIXME: create a grid-layout function
+;; this defines the parameters and the defchain macro used to create inversion of
+;; control. The parameters cannot be defined outside this function because asdf
+;; would initialize them after the functions and break the functionality
+(defun kick-start-chain ()
+ (defparameter *execute-before* nil)
+ (defparameter *execute-in-viewpoint* nil)
+ (defparameter *execute-in-window* nil)
+ (defparameter *execute-after* nil)
+ (defmacro defchain (chain-name where &body body)
+ (cond
+ ((eq where :before) (push chain-name *execute-before*))
+ ((eq where :viewpoint) (push chain-name *execute-in-viewpoint*))
+ ((eq where :window) (push chain-name *execute-in-window*))
+ ((eq where :after) (push chain-name *execute-after*))
+ )
+ `(defun ,chain-name ()
+ ,@body))
)
+
+(kick-start-chain)
;; BUG: when the system loads it doesn't fill the variable
;; *execute-in-viewpoint* therefore this function is never executed
+(defchain render-plane-and-entities :viewpoint
+;; "using *plane* and *entities-list* the macro display on the current rendering texture
+;; the plane 'as is' and the entities with the grid-layout function"
+ (when *plane*
+ ;; NOTE: add error for non-screen planes
+ (display *plane* t)
+ (loop :for entity :in (entities-list *plane*)
+ :do
+ (when (displayp entity)
+ (display entity (plane-grid *plane*))
+ ))) ; FIXME: create a grid-layout function
+ )
;; :image (merge-pathnames map-path (cdr (assoc :image-path entity-info)))
:background (merge-pathnames map-path (cdr (assoc :image-path entity-info)))
:size (if (assoc :size entity-info) (cdr (assoc :size entity-info)) 1)
- :name (assoc :name entity-info)
+ :name (cdr (assoc :name entity-info))
))))
+;; FIXME: this design can be improved with the use of cl-json options
+(defun create-entity (alist map-path)
+ (make-instance 'entity
+ :background (merge-pathnames map-path (cdr (assoc :image-path alist)))
+ :size (if (assoc :size alist) (cdr (assoc :size alist)) 1)
+ :name (assoc :name alist)
+ ))
+
(defun create-plane (map-info map-path &key (number 0))
"convert the map informations into a functioning plane, without number it convert the
first element"
(let ((plane-info (nth number (cdr (assoc :planes map-info)))))
(make-instance 'rulp.layers:plane
:background (merge-pathnames map-path (cdr (assoc :image-path plane-info)))
- :entities-list (create-entities map-info map-path)
+ :entities-list (map 'list #'(lambda (x) (create-entity x map-path)) (cdr (assoc :entities plane-info)))
:grid (make-instance 'squaregrid
:span (cdr (assoc :grid-dimension plane-info)))
)
(setf *plane-grid* (span (rulp.layers:plane-grid *plane*)))
;; FIXME: to remove
- (setf *entities-list* (entities-list *plane*))
+ ;; (setf *entities-list* (entities-list *plane*))
(loop :for i :in *execute-before*
:do (eval `(,i)))
;; FIXME: to remove