forked from SuperTux/supertux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
levelconverter-0.1.3_0.2.0.scm
executable file
·163 lines (150 loc) · 5.64 KB
/
levelconverter-0.1.3_0.2.0.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/guile -s
!#
;; SuperTux 0.1.3 to SuperTux 0.2.x level conversion helper
;; Copyright (C) 2006 Christoph Sommer <[email protected]>
;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.
;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;
;; The rest of this file may seem like a Long Irritating Series of Parentheses,
;; but it's actually a program. Install a Scheme interpreter, e.g. scm, to run
;; it.
;
;; This program aids in the conversion of SuperTux levels from 0.1.3 level
;; format to the one used by SuperTux 0.2.x.
;
;; Usage:
;; levelconverter-0.1.3_0.2.0.scm < oldformat.stl > newformat.stl
;
;; Bugs:
;; background and music might need manual tweaking
;; gradients aren't properly converted
(use-modules (ice-9 pretty-print))
;; return first sublist in haystack that starts with needle or #f if none is found
(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))))
;; return SuperTux 0.1.3 object in SuperTux 0.2.x form
(define (convert-object object)
(cond
((eq? (car object) 'money)
(append '(jumpy) (cdr object)))
(else
object)))
(define (convert-music filename)
(if (string-suffix? ".mod" filename)
(string-append "music/" (substring filename 0 (- (string-length filename) 4)) ".ogg")
(string-append "music/" filename)))
(define (convert-background filename)
(if (equal? filename "arctis.png")
(string-append "images/background/arctis.jpg")
(string-append "images/background/" filename)))
;; return SuperTux 0.1.3 level in SuperTux 0.2.x form
(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))
(background (find-sublist level 'background))
(music (find-sublist level 'music))
(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) (warn "No background tilemap given"))
(if (not foreground-tm) (warn "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")
,@(if music
`((music ,(convert-music (car music))))
'())
,@(if (and background (not (equal? background '(""))))
`((background (image ,(convert-background (car background)))))
'((gradient
(top_color 0 0 0.2)
(bottom_color 0 0 0.6)
)))
,@(if foreground-tm
`((tilemap
(z-pos -100)
(solid #f)
(speed 1)
(width ,(car width))
(height ,(car height))
(tiles ,@background-tm)
))
'())
(tilemap
(z-pos 0)
(solid #t)
(speed 1)
(width ,(car width))
(height ,(car height))
(tiles ,@interactive-tm)
)
,@(if foreground-tm
`((tilemap
(z-pos 100)
(solid #f)
(speed 1)
(width ,(car width))
(height ,(car height))
(tiles ,@foreground-tm)
)) '())
(spawnpoint
(name "main")
(x ,(car start_pos_x))
(y ,(car start_pos_y))
)
)
)
(map convert-object objects)
)
)
)
)
)
;; run conversion on stdin, output to stdout
(pretty-print (convert-level (read)))
(newline)
(quit)
;; EOF ;;