Commit df0c1790 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Add ppm output of parsed maps.

parent 96774c09
......@@ -25,6 +25,12 @@
((srfi srfi-9) #:select (define-record-type))
((srfi srfi-9 gnu) #:select (set-record-type-printer!))
)
(define rgb:black #vu8(0 0 0))
(define rgb:brown #vu8(0 #xFF #xFF))
(define rgb:blue #vu8(0 #x99 #xFF))
(define rgb:red #vu8(#xCC 0 0))
......@@ -230,11 +236,38 @@ else insert the value as given"
(get-planestart map-metadata)
(get-planelength map-metadata)))
;; binary-port x 2d-array<T> x (T → RGB bytevector) → *unspecified#*
;; writes image to file
(define (array->ppm port array mapper)
(let ((dim (array-dimensions array)))
(format port "P6~%~a ~a~%255~%"
(list-ref dim 1)
(list-ref dim 0)))
(array-for-each
(lambda (el) (put-bytevector port (mapper el)))
array))
(define (dump-tilemap map-head tilemap)
(let ((fname (format #f "~a.ppm" (get-name map-head))))
(call-with-output-file fname
(lambda (port) (array->ppm port tilemap
(lambda (tile) ; WL_GAME.C, 624
(cond ((= tile 0) rgb:black) ; floor
((<= 90 tile 101) rgb:brown) ; door
((< tile AREATILE) rgb:blue) ; wall
(else rgb:red))
)))
#:binary #t)
(format #t "Wrote map to ~a~%" fname)))
(define (main args)
(define og-dir (getcwd))
(chdir "/home/hugo/wolf/full/")
(let* ((maphead (call-with-input-file "MAPHEAD.WL6"
......@@ -254,4 +287,8 @@ else insert the value as given"
(data (call-with-input-file "GAMEMAPS.WL6"
(lambda (port) (parse-map-data maph port))
#:binary #t)))
(-> data car tile-list->tilemap display-tilemap))))
(chdir og-dir)
(let ((tilemap (-> data car tile-list->tilemap)))
(display-tilemap tilemap)
(dump-tilemap maph tilemap)))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment