Corrected the dependencies. Level Editor works again using Skippy.
[uxul-world.git] / files.lisp
index e8e50db..9c6d44e 100755 (executable)
@@ -8,27 +8,47 @@
 (defun si (var val)
   (setf (symbol-value (intern var)) val))
 
-(defun init-file (file)
-  "Load a file into a Variable. Access with |filename| (without .png
-and path)."
-  (si (pathname-name file)
-      (with-open-file (in file :element-type '(unsigned-byte 8)) 
-       (let* ((length (file-length in))
-              (content (make-array (list length)
-                                   :element-type '(unsigned-byte 8)
-                                   :adjustable nil)))
-         (read-sequence content in)
-         content))))
-
-(defun file-relevant-p (file)
+(defun stretch-image (x y img)
+  "Resize that file to x times y."
+  (uxul-world::resize-bmp-blob img x y))
+
+(defun ash-sized-image (img a)
+  "Calculate an image of half/eighth/quarter of the size."
+  (let ((w (bmp-width img))
+       (h (bmp-height img)))
+  (uxul-world::resize-bmp-blob img (max 1 (floor (/ w a))) (max 1 (floor (/ h a))))))
+
+(defun all-sizes (img)
+  (list img
+       (ash-sized-image img 2)
+       (ash-sized-image img 4)
+       (ash-sized-image img 8)))
+
+(defun init-bmp-file (file)
+  "Load an image file into a Variable. Set |filename| (without .png
+and path) to a list with all sizes of that image."
+  (si (pathname-name file) 
+      (all-sizes
+       (with-open-file (in file :element-type '(unsigned-byte 8)) 
+        (let* ((length (file-length in))
+               (content (make-array (list length)
+                                    :element-type '(unsigned-byte 8)
+                                    :adjustable nil)))
+          (read-sequence content in)
+          content)))))
+
+(defun bmp-p (file)
   "Is the file relevant for initialization? So far only .png-files are
 relevant."
-  (string= (pathname-type file) "png"))
+  (string= (pathname-type file) "bmp"))
 
-(defun init-files ()
-  "Load the relevant files into variables"
+(defun init-bmp-files ()
   (cl-fad:walk-directory
    (asdf:component-pathname (asdf:find-system :uxul-world))
-   #'init-file :test #'file-relevant-p))
+   #'init-bmp-file :test #'bmp-p))
+
+(defun init-files ()
+  "Load the relevant files into variables"
+  (init-bmp-files))
 
 (init-files)
\ No newline at end of file