Added a Graphic for "key".
[uxul-world.git] / files.lisp
1 ;;; Copyright 2009 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 init-file (file)
12   "Load a file into a Variable. Access with |filename| (without .png
13 and path)."
14   (si (pathname-name file)
15       (with-open-file (in file :element-type '(unsigned-byte 8)) 
16         (let* ((length (file-length in))
17                (content (make-array (list length)
18                                     :element-type '(unsigned-byte 8)
19                                     :adjustable nil)))
20           (read-sequence content in)
21           content))))
22
23 (defun file-relevant-p (file)
24   "Is the file relevant for initialization? So far only .png-files are
25 relevant."
26   (string= (pathname-type file) "png"))
27
28 (defun init-files ()
29   "Load the relevant files into variables"
30   (cl-fad:walk-directory
31    (asdf:component-pathname (asdf:find-system :uxul-world))
32    #'init-file :test #'file-relevant-p))
33
34 (init-files)