levelconverter-0.1.3_0.2.0.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/usr/bin/perl
  2. #
  3. # $Id$
  4. #
  5. # SuperTux - 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. # This conversion helper aids in the conversion of SuperTux level from
  24. # 0.1.3 level format to the one used by SuperTux 0.2.0.
  25. #
  26. # Usage:
  27. # levelconverter-0.1.3_0.2.0.pl < oldformat.stl > newformat.stl
  28. #
  29. # Note that the script makes some unreasonable assumptions about where
  30. # newlines occur in level files. It does work for most levels created
  31. # in SuperTux 0.1.3 and Flexlay, though.
  32. #
  33. ## Helper function: Extracts contents of ($token ...) leaf list (must not contain any other lists)
  34. sub lispContents
  35. {
  36. $token = shift();
  37. $haystack = shift();
  38. if ($haystack =~ m{\($token\s+(.*?)\s*\)}s) {
  39. return $1;
  40. }
  41. return;
  42. }
  43. # extract (supertux-level ...) list from stdin
  44. $all = join("", <STDIN>);
  45. if ($all !~ m{\(supertux-level\s+(.*)\s*\)}s) { die("Not a supertux level"); }
  46. $level = $1;
  47. # make sure we deal with a (version 1) level
  48. $version = lispContents("version", $level) or die("no version tag found");
  49. if ($version != "1") { die("not a version 1 level"); }
  50. # extract various properties
  51. $author = lispContents("author", $level) or $author = "Anonymous";
  52. $name = lispContents("name", $level) or $name = "Unnamed";
  53. $width = lispContents("width", $level) or die("no level width definition found");
  54. $height = lispContents("height", $level) or $height = "15";
  55. $start_pos_x = lispContents("start_pos_x", $level) or $start_pos_x = "100";
  56. $start_pos_y = lispContents("start_pos_y", $level) or $start_pos_y = "170";
  57. $interactive_tm = lispContents("interactive-tm", $level) or die("no interactive tilemap found");
  58. $background_tm = lispContents("background-tm", $level) or die("no background tilemap found");
  59. $foreground_tm = lispContents("foreground-tm", $level) or die("no foreground tilemap found");
  60. # extract objects list
  61. # kind of a hack: object list is assumed to terminate at the first closing parenthesis that is alone on a line
  62. if ($level !~ m{\(objects\s+(.*?)\s*\n\s*\)}s) { die("Objects list not found"); }
  63. $objects = $1;
  64. $objects =~ s{money}{jumpy}sg;
  65. $objects =~ s{\(stay-on-platform\s+#[tf]\s*\)}{}sg;
  66. # write out version-2 level on stdout
  67. print qq{(supertux-level\n};
  68. print qq{ (version 2)\n};
  69. print qq{ (name (_ $name))\n} if ($name);
  70. print qq{ (author $author)\n} if ($author);
  71. print qq{ (sector\n};
  72. print qq{ (name "main")\n};
  73. print qq{ (tilemap\n};
  74. print qq{ (z-pos -100)\n};
  75. print qq{ (solid #f)\n};
  76. print qq{ (speed 1)\n};
  77. print qq{ (width $width)\n};
  78. print qq{ (height $height)\n};
  79. print qq{ (tiles $background_tm)\n};
  80. print qq{ )\n};
  81. print qq{ (tilemap\n};
  82. print qq{ (z-pos 0)\n};
  83. print qq{ (solid #t)\n};
  84. print qq{ (speed 1)\n};
  85. print qq{ (width $width)\n};
  86. print qq{ (height $height)\n};
  87. print qq{ (tiles $interactive_tm)\n};
  88. print qq{ )\n};
  89. print qq{ (tilemap\n};
  90. print qq{ (z-pos 100)\n};
  91. print qq{ (solid #f)\n};
  92. print qq{ (speed 1)\n};
  93. print qq{ (width $width)\n};
  94. print qq{ (height $height)\n};
  95. print qq{ (tiles $foreground_tm)\n};
  96. print qq{ )\n};
  97. print qq{ (spawnpoint\n};
  98. print qq{ (name "main")\n};
  99. print qq{ (x $start_pos_x)\n};
  100. print qq{ (y $start_pos_y)\n};
  101. print qq{ )\n};
  102. print qq{ $objects\n};
  103. print qq{ )\n};
  104. print qq{)\n};
  105. # EOF