How do I properly read the data from these modules? I think require "assets.levels" is probably wrong since they are not included in the binary (but it still works for some reason.)
It looks like I need to get sys.get_application_path() with bundled resources, then append relative path to the assets/levels directory. However when I build the project, I do not know where the assets are located relative to the application. It doesn’t look like they’re being placed next to the executable.
If you want your final bundle folder with the game executable to include a “levels” folder, in your project you need to put the contents in “res/common/levels” (if you put “res” in your “Bundle Resources” game.project field).
It is working when I build with Project -> Bundle -> xxx Application. However, when I use ctrl + b to build in the editor, the folder does not seem to be copied into the /build folder subdirectories, which are default and x86_64-win32.
Having a similar problem to this. Bundling or starting a debugging session does not seem to copy over files. It is possible to rebundle the game, and it is quite fast, but it’s not as nice of a workflow as just kickstarting the debugger. Here is a minimal project to test it with. (That project might be useful as an example as well) def_mr_bundleresources.zip (7.1 MB)
This is true, we only copy the files when you bundle the final application.
Will this work on macOS? A macOS .app has this structure:
Foo.app
|
+-- Contents/
|
+-- Resources/ (contains the Defold game archive files etc)
+-- MacOS/ (contains the Defold engine)
+-- Info.plist
Putting bundle resources in /common would copy the files to the root of the .app, ie next to Contents/ above.
What I’m trying to say is that your app needs to deal with some platform specifics when you load files and adjust the path accordingly. The only way to not have to do this is to use Custom Resources and load with sys.load_resource() or if you really want to use Bundle Resources you need to use platform specific folders. For macOS use osx/Contents/MacOS/assets/levels/ to put the files next to the engine.
And if your app needs to deal with some platform specifics when you load files you can probably also add a check if the game is running from the editor or from an application bundle and adjust the paths.
This is a bit messy but it is something you need to solve once and then reuse in a Lua module. Perhaps someone already has something like this to share?
I started to write a script for this and started to create bundles for the different platforms. I did find some issues (without testing to run them on any of the platforms, just peeking around the files):
Android doesn’t seem to export a 64-bit version, with only 64-bit selected it still exports a folder called armv7
I cannot find the bundle resources in the android version
Can’t find in macOS version either
I don’t have access to the other versions as they are proprietary (and I’m not sure I’m allowed to put these in a public script, so I’m not doing that for now)