5 ; SuperTux 0.1.3 to SuperTux 0.2.x level conversion helper
6 ; Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
8 ; This program is free software; you can redistribute it and/or
9 ; modify it under the terms of the GNU General Public License
10 ; as published by the Free Software Foundation; either version 2
11 ; of the License, or (at your option) any later version.
13 ; This program is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ; GNU General Public License for more details.
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ; ---------------------------------------------------------------------------
26 ; The rest of this file may seem like a Long Irritating Series of Parentheses,
27 ; but it's actually a program. Install a Scheme interpreter, e.g. scm, to run
30 ; This program aids in the conversion of SuperTux levels from 0.1.3 level
31 ; format to the one used by SuperTux 0.2.x.
34 ; levelconverter-0.1.3_0.2.0.scm < oldformat.stl > newformat.stl
37 ; Some things (like what background image to use) are not converted:
38 ; they will need manual adjustment afterwards.
40 ; ---------------------------------------------------------------------------
42 ; return first sublist in haystack that starts with needle or #f if none is found
43 (define (find-sublist haystack needle)
46 (not (pair? haystack))
50 (and (pair? (car haystack)) (eq? (caar haystack) needle))
55 (find-sublist (cdr haystack) needle)
60 ; return SuperTux 0.1.3 object in SuperTux 0.2.x form
61 (define (convert-object object)
64 (eq? (car object) 'money)
65 (append '(jumpy) (cdr object))
74 ; return SuperTux 0.1.3 level in SuperTux 0.2.x form
75 (define (convert-level level)
79 (version (find-sublist level 'version))
80 (author (find-sublist level 'author))
81 (name (find-sublist level 'name))
82 (width (find-sublist level 'width))
83 (height (find-sublist level 'height))
84 (start_pos_x (find-sublist level 'start_pos_x))
85 (start_pos_y (find-sublist level 'start_pos_y))
86 (interactive-tm (find-sublist level 'interactive-tm))
87 (background-tm (find-sublist level 'background-tm))
88 (foreground-tm (find-sublist level 'foreground-tm))
89 (objects (find-sublist level 'objects))
91 (if (not (string=? (symbol->string type) "supertux-level")) (error "not a supertux-level:" type))
92 (if (not (= (car version) 1)) (error "not a version 1 level"))
93 (if (not author) (set! author '("Anonymous")))
94 (if (not name) (set! name '("Unnamed Level")))
95 (if (not width) (error "No level width given"))
96 (if (not height) (set! height '(15)))
97 (if (not start_pos_x) (set! start_pos_x '(100)))
98 (if (not start_pos_y) (set! start_pos_y '(170)))
99 (if (not interactive-tm) (error "No interactive tilemap given"))
100 (if (not background-tm) (error "No background tilemap given"))
101 (if (not foreground-tm) (error "No foreground tilemap given"))
102 (if (not objects) (error "No objects list given"))
106 (name (_ ,(car name)))
107 (author ,(car author))
114 (bottom_color 0 0 0.6)
121 (height ,(car height))
122 ,(append '(tiles) background-tm)
129 (height ,(car height))
130 ,(append '(tiles) interactive-tm)
137 (height ,(car height))
138 ,(append '(tiles) foreground-tm)
142 (x ,(car start_pos_x))
143 (y ,(car start_pos_y))
147 (map convert-object objects)
154 ; run conversion on stdin, output to stdout
155 (write (convert-level (read)))