Removed some boilerplate.
[uxul-world.git] / files.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 ;; This file declares the constants for loading different files and
4 ;; file-formats.
5
6 (in-package :uxul-world)
7
8 (defun si (var val)
9   (setf (symbol-value (intern var)) val))
10
11 (defun stretch-image (x y img)
12   "Resize that file to x times y."
13   (uxul-world::resize-bmp-blob img x y))
14
15 (defun ash-sized-image (img a)
16   "Calculate an image of half/eighth/quarter of the size."
17   (let ((w (bmp-width img))
18         (h (bmp-height img)))
19   (uxul-world::resize-bmp-blob img (max 1 (floor (/ w a))) (max 1 (floor (/ h a))))))
20
21 (defun init-bmp-file (file)
22   "Load an image file into a Variable. Set |filename| (without .png
23 and path) to a list with all sizes of that image."
24   (si (pathname-name file)
25        (with-open-file (in file :element-type '(unsigned-byte 8)) 
26          (let* ((length (file-length in))
27                 (content (make-array (list length)
28                                      :element-type '(unsigned-byte 8)
29                                      :adjustable nil)))
30            (read-sequence content in)
31            content))))
32
33 (defun bmp-p (file)
34   "Is the file relevant for initialization? So far only .png-files are
35 relevant."
36   (string= (pathname-type file) "bmp"))
37
38 (defun init-bmp-files ()
39   (cl-fad:walk-directory
40    (asdf:component-pathname (asdf:find-system :uxul-world))
41    #'init-bmp-file :test #'bmp-p))
42
43 (defun init-files ()
44   "Load the relevant files into variables"
45   (init-bmp-files))
46
47 (init-files)