supertux.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/usr/bin/ruby
  2. ## $Id$
  3. ##
  4. ## Flexlay - A Generic 2D Game Editor
  5. ## Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
  6. ##
  7. ## This program is free software: you can redistribute it and/or modify
  8. ## it under the terms of the GNU General Public License as published by
  9. ## the Free Software Foundation, either version 3 of the License, or
  10. ## (at your option) any later version.
  11. ##
  12. ## This program is distributed in the hope that it will be useful,
  13. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ## GNU General Public License for more details.
  16. ##
  17. ## You should have received a copy of the GNU General Public License
  18. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. $config_file = File.expand_path("~/.flexlay/supertux.rb")
  20. def find_supertux_datadir()
  21. # try to automatically detect the supertux datadir
  22. possible_locations = [
  23. "~/cvs/supertux/supertux/data/",
  24. "~/cvs/supertux/data/",
  25. "/usr/share/games/supertux/",
  26. "/usr/local/share/games/supertux/",
  27. "/opt/supertux/data/",
  28. "~/projects/supertux/data/",
  29. "~/projects/supertux/svn/trunk/supertux/data/",
  30. ]
  31. # `which supertux`
  32. end
  33. # Config file loading hack
  34. if File.exist?($config_file) then
  35. require $config_file
  36. end
  37. BACKGROUND_LAYER = 1
  38. INTERACTIVE_LAYER = 2
  39. FOREGROUND_LAYER = 3
  40. require "flexlay_wrap"
  41. include Flexlay_wrap
  42. require "flexlay.rb"
  43. require "sexpr.rb"
  44. require_relative "gameobj.rb"
  45. flexlay = Flexlay.new()
  46. width = 1024
  47. height = 768
  48. fullscreen = false
  49. resizeable = true
  50. flexlay.init("SuperTux Editor", width, height, fullscreen, resizeable)
  51. # Tools
  52. $tilemap_paint_tool = TileMapPaintTool.new()
  53. $tilemap_select_tool = TileMapSelectTool.new()
  54. $zoom_tool = ZoomTool.new()
  55. $zoom2_tool = Zoom2Tool.new()
  56. $workspace_move_tool = WorkspaceMoveTool.new()
  57. $objmap_select_tool = ObjMapSelectTool.new()
  58. # $sketch_stroke_tool = SketchStrokeTool.new()
  59. $mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
  60. # $console = Console.new(CL_Rect.new(CL_Point.new(50, 100), CL_Size.new(400, 200)),
  61. # $gui.get_component())
  62. # $console.write("Hello World\n");
  63. # $console.write("blabl\n");
  64. # $console.write("blabl\naoeuau\naeouau");
  65. require_relative "gui.rb"
  66. class SuperTuxConfig
  67. attr_accessor :datadir, :recent_files
  68. def initialize()
  69. @recent_files = []
  70. end
  71. def save(filename)
  72. dir = File.expand_path("~/.flexlay/")
  73. if not File.exists?(dir) then
  74. Dir.mkdir(dir)
  75. end
  76. f = File.new(filename, "w")
  77. f.write("# Autogenerated Script, don't edit by hand!\n\n")
  78. f.write("$datadir = " + $datadir.inspect() + "\n")
  79. f.write("$recent_files = " + $recent_files.inspect() + "\n")
  80. f.write("\n# EOF #\n")
  81. end
  82. end
  83. $config = SuperTuxConfig.new()
  84. if !$datadir then
  85. $datadir = File.expand_path("~/projects/supertux/trunk/supertux/data/")+"/"
  86. end
  87. require_relative "data.rb"
  88. require_relative "WorldMap.rb"
  89. require_relative "WorldMapObject.rb"
  90. require_relative "TileMap.rb"
  91. require_relative "LispWriter.rb"
  92. require_relative "tileset.rb"
  93. require_relative "level.rb"
  94. require_relative "sector.rb"
  95. require_relative "sprite.rb"
  96. require_relative "util.rb"
  97. $tileset = Tileset.new(32)
  98. $tileset.load($datadir + "images/tiles.strf")
  99. $tileset.create_ungrouped_tiles_group()
  100. $gui = SuperTuxGUI.new(width, height)
  101. if !$recent_files then
  102. $recent_files = []
  103. end
  104. $recent_files.each do |filename|
  105. $gui.recent_files_menu.add_item($mysprite, filename, proc{ supertux_load_level(filename) })
  106. end
  107. if ARGV == []
  108. Level.new(100, 50).activate($gui.workspace)
  109. else
  110. supertux_load_level(ARGV[0])
  111. end
  112. # Init the GUI, so that button state is in sync with internal state
  113. $gui.gui_toggle_minimap()
  114. $gui.gui_toggle_minimap()
  115. $gui.gui_show_interactive()
  116. $gui.gui_show_current()
  117. $gui.set_tilemap_paint_tool()
  118. if not File.exist?($datadir) then
  119. dialog = GenericDialog.new("Specify the SuperTux data directory and restart", $gui.gui.get_component())
  120. dialog.add_label("You need to specify the datadir where SuperTux is located")
  121. dialog.add_string("Datadir:", $datadir)
  122. dialog.set_block { |datadir|
  123. $datadir = datadir
  124. }
  125. end
  126. $gui.run()
  127. $config.save($config_file)
  128. # Try to cleanup
  129. puts "Cleanup"
  130. $gui = nil
  131. $config = nil
  132. $tilemap_paint_tool = nil
  133. $tilemap_select_tool = nil
  134. $zoom_tool = nil
  135. $zoom2_tool = nil
  136. $workspace_move_tool = nil
  137. $objmap_select_tool = nil
  138. $game_objects = nil
  139. GC.start
  140. GC.start
  141. GC.start
  142. GC.start
  143. puts "Cleanup done"
  144. # FIXME: Can't deinit flexlay, since we would crash then
  145. at_exit{flexlay.deinit()}
  146. # puts "And now we crash"
  147. # EOF #