levelconverter-0.1.3_0.2.0.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ;
  2. ;
  3. ; $Id$
  4. ;
  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>
  7. ;
  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.
  12. ;
  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.
  17. ;
  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.
  21. ;
  22. ; ---------------------------------------------------------------------------
  23. ;
  24. ; The rest of this file may seem like a Long Irritating Series of Parentheses,
  25. ; but it's actually a program. Install a Scheme interpreter, e.g. scm, to run
  26. ; it.
  27. ;
  28. ; This program aids in the conversion of SuperTux levels from 0.1.3 level
  29. ; format to the one used by SuperTux 0.2.x.
  30. ;
  31. ; Usage:
  32. ; levelconverter-0.1.3_0.2.0.scm < oldformat.stl > newformat.stl
  33. ;
  34. ; Bugs:
  35. ; Some things (like what background image to use) are not converted:
  36. ; they will need manual adjustment afterwards.
  37. ; ---------------------------------------------------------------------------
  38. ; return first sublist in haystack that starts with needle or #f if none is found
  39. (define (find-sublist haystack needle)
  40. (cond
  41. (
  42. (not (pair? haystack))
  43. #f
  44. )
  45. (
  46. (and (pair? (car haystack)) (eq? (caar haystack) needle))
  47. (cdar haystack)
  48. )
  49. (
  50. else
  51. (find-sublist (cdr haystack) needle)
  52. )
  53. )
  54. )
  55. ; return SuperTux 0.1.3 object in SuperTux 0.2.x form
  56. (define (convert-object object)
  57. (cond
  58. (
  59. (eq? (car object) 'money)
  60. (append '(jumpy) (cdr object))
  61. )
  62. (
  63. else
  64. object
  65. )
  66. )
  67. )
  68. ; return SuperTux 0.1.3 level in SuperTux 0.2.x form
  69. (define (convert-level level)
  70. (let
  71. (
  72. (type (car level))
  73. (version (find-sublist level 'version))
  74. (author (find-sublist level 'author))
  75. (name (find-sublist level 'name))
  76. (width (find-sublist level 'width))
  77. (height (find-sublist level 'height))
  78. (start_pos_x (find-sublist level 'start_pos_x))
  79. (start_pos_y (find-sublist level 'start_pos_y))
  80. (interactive-tm (find-sublist level 'interactive-tm))
  81. (background-tm (find-sublist level 'background-tm))
  82. (foreground-tm (find-sublist level 'foreground-tm))
  83. (objects (find-sublist level 'objects))
  84. )
  85. (if (not (string=? (symbol->string type) "supertux-level")) (error "not a supertux-level:" type))
  86. (if (not (= (car version) 1)) (error "not a version 1 level"))
  87. (if (not author) (set! author '("Anonymous")))
  88. (if (not name) (set! name '("Unnamed Level")))
  89. (if (not width) (error "No level width given"))
  90. (if (not height) (set! height '(15)))
  91. (if (not start_pos_x) (set! start_pos_x '(100)))
  92. (if (not start_pos_y) (set! start_pos_y '(170)))
  93. (if (not interactive-tm) (error "No interactive tilemap given"))
  94. (if (not background-tm) (error "No background tilemap given"))
  95. (if (not foreground-tm) (error "No foreground tilemap given"))
  96. (if (not objects) (error "No objects list given"))
  97. (quasiquote
  98. (supertux-level
  99. (version 2)
  100. (name (_ ,(car name)))
  101. (author ,(car author))
  102. ,(append
  103. (quasiquote
  104. (sector
  105. (name "main")
  106. (gradient
  107. (top_color 0 0 0.2)
  108. (bottom_color 0 0 0.6)
  109. )
  110. (tilemap
  111. (z-pos -100)
  112. (solid #f)
  113. (speed 1)
  114. (width ,(car width))
  115. (height ,(car height))
  116. ,(append '(tiles) background-tm)
  117. )
  118. (tilemap
  119. (z-pos 0)
  120. (solid #t)
  121. (speed 1)
  122. (width ,(car width))
  123. (height ,(car height))
  124. ,(append '(tiles) interactive-tm)
  125. )
  126. (tilemap
  127. (z-pos 100)
  128. (solid #f)
  129. (speed 1)
  130. (width ,(car width))
  131. (height ,(car height))
  132. ,(append '(tiles) foreground-tm)
  133. )
  134. (spawnpoint
  135. (name "main")
  136. (x ,(car start_pos_x))
  137. (y ,(car start_pos_y))
  138. )
  139. )
  140. )
  141. (map convert-object objects)
  142. )
  143. )
  144. )
  145. )
  146. )
  147. ; run conversion on stdin, output to stdout
  148. (write (convert-level (read)))
  149. (newline)
  150. (quit)