gosu / releasy

A rake task generator to help with building/packaging/deploying Ruby applications (⚠️ unmaintained)
https://spooner.github.com/libraries/releasy/
MIT License
378 stars 29 forks source link

Building Mac OSX app doesn't include executable file #41

Closed ashleywysocki closed 10 years ago

ashleywysocki commented 11 years ago

I'm trying to package a game for Mac OSX with Snow Leopard and Ruby 1.9.2. When I make the game, the app doesn't run and I get the error: no such file to load -- galaxy.rb (LoadError). Galaxy.rb is the main file that runs the game. In my Rakefile I have:

executable "galaxy.rb" files "media//." exclude_encoding

add_build :osx_app do wrapper "gosu-mac-wrapper-0.7.44.tar.gz" # Assuming this is where you downloaded this file. url "com.github.my_application" add_package :tar_gz end

Am I doing anything wrong or what could I try to do to fix this?

bil-bas commented 11 years ago

'Galaxy.rb' is not the same file as 'galaxy.rb' (except on Windows). If that is just a typo, then is it in the same directory as the Rakefile because it should include a path if it isn't?

bil-bas commented 11 years ago

Oh and #files should also include ALL files needed to run the game, not just media files (unless your entire game is just galaxy.rb, of course).

ashleywysocki commented 11 years ago

Yeah, that's a typo, I was just capitalizing it for the sentence but the actual file is galaxy.rb. It is in the same directory as the Rakefile. The entire game is in the galaxy file and the pictures are in the media folder. If I do try to put more than one file in #files though, I get the error: "wrong number of arguments (3 for 1)".

bil-bas commented 11 years ago

Oops, that is a bug in the docs (or rather, that the pushed docs are for a version I haven't released). You need to do files [x, y, z] now, not files x, y, z - sorry, I should sort that out (Sorry!). In either case, it just uses a FileList underneath and your current media/**/*.* should catch everything.

Hmm, maybe you need galaxy.rb in the #files list too? While since I've looked at it, so I can't say for certain. If it does need to be in there, that is a bit sloppy and it probably should be fixed so that it is automatically added to the file list. Please tell me if adding that sorts out the problem (I am thinking it is most probably the issue, now I think about it).

ashleywysocki commented 11 years ago

Thanks so much for the quick reply. I added galaxy.rb to the files list and now that error doesn't come up. However now the error that comes up is:

/Contents/Resources/vendor/gems/chingu-0.8.1/lib/chingu/assets.rb:37:in `autoload': Can't load image "space.jpg" (RuntimeError)

Do I have to do something special with the media folder or is it something else?

bil-bas commented 11 years ago

I'm guessing that it is because you are making assumptions about the current working directory in your code. If you can't run your code from anywhere but the root directory (i.e. cd .. then try to run it) then this is the problem.

Well, it is probably Chingu that is being assumptive, so be explicit in telling chingu where to look in your script:

media_dir = File.expand_path("media", File.basename(__FILE__))
Image.autoload_dirs.unshift File.join(media_dir, 'images')
Sample.autoload_dirs.unshift File.join(media_dir, 'sounds')
Song.autoload_dirs.unshift File.join(media_dir, 'music')
Font.autoload_dirs.unshift File.join(media_dir, 'fonts')

EDIT: I made an error here, it should have been File.dirname, not File.basename

ashleywysocki commented 11 years ago

So where do I put this? I put it in my galaxy.rb file and then I get this error: uninitialized constant Object::Image (NameError). Do I have to change something about that code to get it to work or does it go somewhere else?

bil-bas commented 11 years ago

Sorry, I'm so use to include Gosu! Those are in the Gosu namespace (Gosu::Image, etc).

ashleywysocki commented 11 years ago

So I added include Gosu but I'm still getting the error: Can't load image "space.jpg" (RuntimeError). Do I have to add code to the media_dir... code or something else? Do I have to put where exactly the file is and if so, what and where?

bil-bas commented 11 years ago

Well, it depends where your asset files actually are. I have mine in /media/images, media/sounds, etc. and that is where I'm telling Chingu to look for them. If yours are in another folder, then you need to tell Chingu that. Chingu looks in default places, but those are based on the current working directory, so are not a good choice in a setting where you are less sure where that is on startup.

ashleywysocki commented 11 years ago

All of the asset files are in the media folder which is right now located in the application folder inside the game. So would it be:

media_dir = File.expand_path("media", File.basename(FILE)) Image.autoload_dirs.unshift File.join(media_dir) Sample.autoload_dirs.unshift File.join(media_dir) Song.autoload_dirs.unshift File.join(media_dir)

Or would it be somewhere else?

bil-bas commented 11 years ago

Yeah, that would be right. However, I introduced a rather silly error - I wrote File.basename, not File.dirname - sorry!

So in your case it should be:

include Gosu
media_dir = File.expand_path("media", File.dirname(__FILE__))
Image.autoload_dirs.unshift media_dir
Sample.autoload_dirs.unshift media_dir
Song.autoload_dirs.unshift media_dir
ashleywysocki commented 11 years ago

Thanks! That works but now I'm getting the error: galaxy.rb:76:in `rand': can't convert Range into Integer (TypeError). Apparently only Ruby 1.9.3 let's you do rand for a range. Is there any way to upgrade Ruby to 1.9.3 for the package since it looks like in the Frameworks folder it's 1.9.1.

bil-bas commented 11 years ago

The .app only contains Ruby 1.9.2, but Kernel#rand(Range) was added in 1.9.3. I don't build the OSX app myself, since I don't have access to OSX, so I have no control over it; you just have to live with it! All versions of 1.9 use the 1.9.1 folder (for arcane reasons), so the folder name doesn't give anything away.

You could monkey-patch Ruby 1.9.2 to be compatible with 1.9.3 (at least in respect to #rand):

module Kernel
  alias_method :original_rand, :rand

  def rand(value)
    if value.is_a? Range
      original_rand(value.max + 1 - value.min) + value.min
    else
      original_rand value
    end
  end
end
bil-bas commented 11 years ago

Alternatively, use Random#rand, rather than Kernel#rand, since that supported Range in 1.9.2: http://www.ruby-doc.org/core-1.9.2/Random.html

ashleywysocki commented 11 years ago

Okay that helps. Thanks so much for the help! It works now.