(define-module (game util assets)
  #:use-module (ice-9 ftw)
  #:use-module (ice-9 textual-ports)
  #:use-module (chickadee graphics texture)
  #:use-module (chickadee graphics color)
  #:export (assets-load assets-file-name tile-texture tile-atlas hero-texture hero-atlas assets-map-levels)
  
  )

(define tile-texture #f)
(define tile-atlas #f)

(define hero-texture #f)
(define hero-atlas #f)

(define prefix (or (getenv "ASSET_DIR") "." ))


(define (assets-file-name name)
  (string-append prefix "/" name)
  )


(define (read-level-map filename)
  (call-with-input-file   get-string-all))

(define (assets-map-levels f)
  (map f 
       (map (lambda (filename)(string-append prefix "/assets/levels/" filename))
            (scandir (assets-file-name "assets/levels") 
                     (lambda (filename) (string-suffix? ".map" filename ))))))

(define (assets-load)
  (set! tile-texture (load-image (assets-file-name "assets/images/simples_pimples.png")))
  (set! tile-atlas (split-texture tile-texture 16 16))
  
  (set! hero-texture (load-image (assets-file-name "assets/images/lr_penguin2.png")))
  (set! hero-atlas (split-texture hero-texture 32 32)))
