supertux-worldmap.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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-worldmap.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. "~/project/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 "gameobj.rb"
  44. require "sexpr.rb"
  45. require "sprite.rb"
  46. require "util.rb"
  47. flexlay = Flexlay.new()
  48. width = 1024
  49. height = 768
  50. flexlay.init("SuperTux Worldmap Editor", width, height)
  51. # Tools
  52. $tilemap_paint_tool = TileMapPaintTool.new()
  53. $tilemap_select_tool = TileMapSelectTool.new()
  54. $zoom_tool = ZoomTool.new()
  55. $objmap_select_tool = ObjMapSelectTool.new()
  56. # $sketch_stroke_tool = SketchStrokeTool.new()
  57. # $console = Console.new(CL_Rect.new(CL_Point.new(50, 100), CL_Size.new(400, 200)),
  58. # $gui.get_component())
  59. # $console.write("Hello World\n");
  60. # $console.write("blabl\n");
  61. # $console.write("blabl\naoeuau\naeouau");
  62. require "gui.rb"
  63. class Config
  64. attr_accessor :datadir, :recent_files
  65. def initialize()
  66. @recent_files = []
  67. end
  68. def save(filename)
  69. dir = File.expand_path("~/.flexlay/")
  70. if not File.exists?(dir) then
  71. Dir.mkdir(dir)
  72. end
  73. f = File.new(filename, "w")
  74. f.write("# Autogenerated Script, don't edit by hand!\n\n")
  75. f.write("$datadir = " + $datadir.inspect() + "\n")
  76. f.write("$recent_files = " + $recent_files.inspect() + "\n")
  77. f.write("\n# EOF #\n")
  78. end
  79. end
  80. $config = Config.new()
  81. if !$datadir then
  82. $datadir = File.expand_path("~/projects/supertux/data/")+"/"
  83. end
  84. require "data.rb"
  85. require "WorldMap.rb"
  86. require "WorldMapObject.rb"
  87. require "TileMap.rb"
  88. require "LispWriter.rb"
  89. require "tileset.rb"
  90. require "level.rb"
  91. require "sector.rb"
  92. $tileset = Tileset.new(32)
  93. $tileset.load($datadir + "images/worldmap.strf")
  94. $tileset.create_ungrouped_tiles_group()
  95. $mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
  96. $gui = SuperTuxGUI.new(width, height)
  97. if !$recent_files then
  98. $recent_files = []
  99. end
  100. $recent_files.each do |filename|
  101. $gui.recent_files_menu.add_item($mysprite, filename, proc{ supertux_load_level(filename) })
  102. end
  103. if ARGV == []
  104. WorldMap.new(70, 50).activate($gui.workspace)
  105. $use_worldmap = true
  106. else
  107. supertux_load_worldmap(ARGV[0])
  108. end
  109. # Init the GUI, so that button state is in sync with internal state
  110. $gui.gui_toggle_minimap()
  111. $gui.gui_toggle_minimap()
  112. #$gui.gui_show_interactive()
  113. $gui.gui_show_current()
  114. $gui.set_tilemap_paint_tool()
  115. if not File.exist?($datadir) then
  116. dialog = GenericDialog.new("Specify the SuperTux data directory and restart", $gui.gui.get_component())
  117. dialog.add_label("You need to specify the datadir where SuperTux is located")
  118. dialog.add_string("Datadir:", $datadir)
  119. dialog.set_block { |datadir|
  120. $datadir = datadir
  121. }
  122. end
  123. $gui.run()
  124. $config.save($config_file)
  125. # FIXME: Can't deinit flexlay, since we would crash then
  126. # flexlay.deinit()
  127. # puts "And now we crash"
  128. # EOF #