levelconverter-0.1.3_0.2.0.scm 5.6 KB

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