Seperating data when building targets

Monkey Forums/Monkey Programming/Seperating data when building targets

Sensei(Posted 2014) [#1]
Hey all.

So I have noticed that when I do a build, the target build folder gets all the monkeyproject.data folder content.
What I was hoping to achieve is, that, using conditional comments like...
#If TARGET="html5"
  snd_shoot = LoadSound (html5AudioPath + "laser_shoot.mp3")
#End
#If TARGET="glfw"
  snd_shoot = LoadSound (glfwAudioPath + "laser_shoot.wav")
#End


...the build will only include the relevant files for the platform in question. So in the above example, when I build HTML5, it only includes the mp3 files in the data build folder.
Other than manually deleting the irrelevant folders for the target builds, is there a way to have the build do it somehow? If not, how have you done it?


impixi(Posted 2014) [#2]
You can import media files in a similar manner, like so:

#If TARGET="html5"
  Import "laser_shoot.mp3"
  Import "html.png"
#End
#If TARGET="glfw"
  Import "laser_shoot.wav"
  Import "glfw.png"
#End


In the above case, my media files are located in the same folder as my code file. When it compiles, Monkey will copy across only the specified files into the specified target's build data folder.


ImmutableOctet(SKNG)(Posted 2014) [#3]
Well, the build folder's version of the data folder is meant to be the final resources used for that build. So, for the sake of testing, you could technically use symbolic links (Which is what I do for the STDCPP / C++ Tool). If you're running Windows, you could use Link Shell Extension.

But then again, it sounds like you want only the files that are used by that build. If that's the case, then that exact feature isn't in Monkey. Monkey does have preprocessor variables for supported file-formats, however.

These variables can be added to, or set manually. They can be configured in a Monkey file/module, or in your build-folder's configuration files ("CONFIG.MONKEY" in each target's folder). Using the target's generated configuration file isn't a bad idea, but you're probably better off making your own configuration module (Or using your primary module; the module with 'Main' in it) for your project (Assuming this is a project you're actively working on).

In fact, if the format isn't even supported by the target by default, it won't even copy it (Without explicitly adding it yourself). So, technically, you don't always need to worry about that.

Anyway, on to the actual variables. These variables are (Hash-tags added to denote they're preprocessor variables):
' Variables you'd normally be changing / adding to:

' Just about any text file you can think of. If you're using something like an XML module, this is where you'd put those formats.
#TEXT_FILES

' Your usual binary files. This is generally used for formats you'll be reading from with your own routines (Usually via 'FileStream' or 'DataStream' and 'DataBuffer.Load').
#BINARY_FILES

' Variables which you likely will never change, as they're already setup with all of the formats the target supports:

' As a rule of thumb, basically all targets support the PNG file format.
#IMAGE_FILES

' Sound formats tend to vary from target to target, but OGG's my personal choice.
#SOUND_FILES

' OGG and MP3 are likely your best bet, but like 'SOUND_FILES', this is rather platform specific.
#MUSIC_FILES


Here's the resource-paths section of the documentation. Also check out the "app config settings" section.

To set a variable, just do something like this:


And to add to it, simply use the '+=' operator instead:


I'm not actually sure if you can use this for exact file names, but it's worth a try. The '*' character is used as a wild-card in this case, so any name can fit in that area.

And technically, you could use 'Import' for each file. That's what 'mojo' does for its default font. (Not the best of methods)

This works something like:


EDIT: Links, formatting, etc.


Sensei(Posted 2014) [#4]
Many thanks guys! That's exactly what I'm looking for.
I set the various target pre-processor Imports at the top of my game and then in the OnCreate() method I just loaded the sounds as per normal for the relevant targets as such:

At the top:
#If TARGET = "html5"
	' Sounds
	Import "sound/mp3/laser_shoot.mp3"
        ' Music
	Import "music/test.mp3"
#End
#If TARGET = "glfw"
	' Sounds
	Import "sound/wav/laser_shoot.wav"
        ' Music
	Import "music/test.wav"
#End


Inside OnCreate:
#If TARGET = "html5"
      ' Sounds
      snd_shoot = LoadSound("laser_shoot.mp3")
      ' Music
      menuSong = "test.mp3"
#End
#If TARGET = "glfw"
      ' Sounds
      snd_shoot = LoadSound("laser_shoot.wav")
      ' Music
      menuSong = "test.wav"
#End


Seems to work correctly and only import the formats for that target platform.

Happy days!


Carlo(Posted 2014) [#5]
you are tested a code for a ipad / iphone i don't work no sound is mute