bmx-ng / bmx-ng

The Open Source BlitzMax Compiler Project
101 stars 14 forks source link

Mac: resource location #69

Open GWRon opened 5 years ago

GWRon commented 5 years ago

I just was told that it is better for Mac apps to contain their resources / assets within the "MyProgram.app"-folder. So for MaxIDE/BlitzMaxNG-project this won't change much as it is still "self contained" then.

But for custom NG-Mac-"GUI"-projects it might be useful to think about a function or global to retrieve the "ResourceDir()" (which differs from the ApplicationDir if you are on a Mac then) and a bmk-option to automatically move all the stuff "around" the source file into the newly build "MyProgram.app"-folder.

Or is there a better solution to this problem? Especially with multi-platform-releases one could just reference the assets differently from within Windows/Linux (LoadImage("MyProgram.app/resources/gfx/image.png")) but it might look a bit odd here and there.

Now ... there is already an android target requiring a similar approach.

How to join all this things together so that you can have one "source.bmx" and could compile the very same folger on all these platforms and receive a working binary (so android, iOS, Mac OS, Windows, Linux) ?

woollybah commented 5 years ago

I could provide you with a function... NSPathToResource:String(filename:String, subdir:String = Null) which would return the correct path to the file you specify, including optional subdir.

It will return Null if either the app is not bundled (i.e. not a gui app), or it can't locate the path/file you provide.

Example

Local path:String = NSPathToResource("image.png", "gfx")

In the API the optional subdir is not included as part of the filename path, which is why it is separate here. I'd rather not have to start messing around with splitting files and paths, but I can if having to specify the two parts separately is going to be a problem?

woollybah commented 5 years ago

Also, SDLGetBasePath() returns the path to the resources folder on macOS/iOS. Which may be useful ;-)

GWRon commented 5 years ago

Of course it would be nicer if there is a automatic replacement somehow.

LoadImage( NativeUri("assets/gfx/image.png") )

What I already dislike is that this Mac behaviour does fully ignore other platforms and works against a cross-platform-download package... As you either had to double-provide the assets (outside mac.app plus inside), use symlinks (trouble on windows) or to let the windows and linux builds reference mac.app/resource too.