6 ; SuperTux 0.1.3 to SuperTux 0.2.x level conversion helper
7 ; Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
9 ; This program is free software; you can redistribute it and/or
10 ; modify it under the terms of the GNU General Public License
11 ; as published by the Free Software Foundation; either version 2
12 ; of the License, or (at your option) any later version.
14 ; This program is distributed in the hope that it will be useful,
15 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ; GNU General Public License for more details.
19 ; You should have received a copy of the GNU General Public License
20 ; along with this program; if not, write to the Free Software
21 ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ; ---------------------------------------------------------------------------
27 ; The rest of this file may seem like a Long Irritating Series of Parentheses,
28 ; but it's actually a program. Install a Scheme interpreter, e.g. scm, to run
31 ; This program aids in the conversion of SuperTux levels from 0.1.3 level
32 ; format to the one used by SuperTux 0.2.x.
35 ; levelconverter-0.1.3_0.2.0.scm < oldformat.stl > newformat.stl
38 ; ---------------------------------------------------------------------------
40 ; return first sublist in haystack that starts with needle or #f if none is found
41 (define (find-sublist haystack needle)
44 (not (pair? haystack))
48 (and (pair? (car haystack)) (eq? (caar haystack) needle))
53 (find-sublist (cdr haystack) needle)
58 ; return SuperTux 0.1.3 object in SuperTux 0.2.x form
59 (define (convert-object object)
62 (eq? (car object) 'money)
63 (append '(jumpy) (cdr object))
72 ; return SuperTux 0.1.3 level in SuperTux 0.2.x form
73 (define (convert-level level)
77 (version (find-sublist level 'version))
78 (author (find-sublist level 'author))
79 (name (find-sublist level 'name))
80 (width (find-sublist level 'width))
81 (height (find-sublist level 'height))
82 (start_pos_x (find-sublist level 'start_pos_x))
83 (start_pos_y (find-sublist level 'start_pos_y))
84 (interactive-tm (find-sublist level 'interactive-tm))
85 (background-tm (find-sublist level 'background-tm))
86 (foreground-tm (find-sublist level 'foreground-tm))
87 (objects (find-sublist level 'objects))
89 (if (not (string=? (symbol->string type) "supertux-level")) (error "not a supertux-level:" type))
90 (if (not (= (car version) 1)) (error "not a version 1 level"))
91 (if (not author) (set! author '("Anonymous")))
92 (if (not name) (set! name '("Unnamed Level")))
93 (if (not width) (error "No level width given"))
94 (if (not height) (set! height '(15)))
95 (if (not start_pos_x) (set! start_pos_x '(100)))
96 (if (not start_pos_y) (set! start_pos_y '(170)))
97 (if (not interactive-tm) (error "No interactive tilemap given"))
98 (if (not background-tm) (error "No background tilemap given"))
99 (if (not foreground-tm) (error "No foreground tilemap given"))
100 (if (not objects) (error "No objects list given"))
104 (name (_ ,(car name)))
105 (author ,(car author))
112 (bottom_color 0 0 0.6)
119 (height ,(car height))
120 ,(append '(tiles) background-tm)
127 (height ,(car height))
128 ,(append '(tiles) interactive-tm)
135 (height ,(car height))
136 ,(append '(tiles) foreground-tm)
140 (x ,(car start_pos_x))
141 (y ,(car start_pos_y))
145 (map convert-object objects)
152 ; run conversion on stdin, output to stdout
153 (write (convert-level (read)))