123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- (define (find-sublist haystack needle)
- (cond
- (
- (not (pair? haystack))
- #f
- )
- (
- (and (pair? (car haystack)) (eq? (caar haystack) needle))
- (cdar haystack)
- )
- (
- else
- (find-sublist (cdr haystack) needle)
- )
- )
- )
- (define (convert-object object)
- (cond
- (
- (eq? (car object) 'money)
- (append '(jumpy) (cdr object))
- )
- (
- else
- object
- )
- )
- )
- (define (convert-level level)
- (let
- (
- (type (car level))
- (version (find-sublist level 'version))
- (author (find-sublist level 'author))
- (name (find-sublist level 'name))
- (width (find-sublist level 'width))
- (height (find-sublist level 'height))
- (start_pos_x (find-sublist level 'start_pos_x))
- (start_pos_y (find-sublist level 'start_pos_y))
- (interactive-tm (find-sublist level 'interactive-tm))
- (background-tm (find-sublist level 'background-tm))
- (foreground-tm (find-sublist level 'foreground-tm))
- (objects (find-sublist level 'objects))
- )
- (if (not (string=? (symbol->string type) "supertux-level")) (error "not a supertux-level:" type))
- (if (not (= (car version) 1)) (error "not a version 1 level"))
- (if (not author) (set! author '("Anonymous")))
- (if (not name) (set! name '("Unnamed Level")))
- (if (not width) (error "No level width given"))
- (if (not height) (set! height '(15)))
- (if (not start_pos_x) (set! start_pos_x '(100)))
- (if (not start_pos_y) (set! start_pos_y '(170)))
- (if (not interactive-tm) (error "No interactive tilemap given"))
- (if (not background-tm) (error "No background tilemap given"))
- (if (not foreground-tm) (error "No foreground tilemap given"))
- (if (not objects) (error "No objects list given"))
- (quasiquote
- (supertux-level
- (version 2)
- (name (_ ,(car name)))
- (author ,(car author))
- ,(append
- (quasiquote
- (sector
- (name "main")
- (gradient
- (top_color 0 0 0.2)
- (bottom_color 0 0 0.6)
- )
- (tilemap
- (z-pos -100)
- (solid #f)
- (speed 1)
- (width ,(car width))
- (height ,(car height))
- ,(append '(tiles) background-tm)
- )
- (tilemap
- (z-pos 0)
- (solid #t)
- (speed 1)
- (width ,(car width))
- (height ,(car height))
- ,(append '(tiles) interactive-tm)
- )
- (tilemap
- (z-pos 100)
- (solid #f)
- (speed 1)
- (width ,(car width))
- (height ,(car height))
- ,(append '(tiles) foreground-tm)
- )
- (spawnpoint
- (name "main")
- (x ,(car start_pos_x))
- (y ,(car start_pos_y))
- )
- )
- )
- (map convert-object objects)
- )
- )
- )
- )
- )
- (write (convert-level (read)))
- (newline)
- (quit)
|