Moving resources from a Module, like Mojo SetFont

Monkey Forums/Monkey Programming/Moving resources from a Module, like Mojo SetFont

Tibit(Posted 2012) [#1]
If I use mojo's DrawText I automagically get a font in my data folder.

The Mojo Module has a data folder with a file called "mojo_font.png"

In SetFont we find this:
context.defaultFont=LoadImage( "mojo_font.png",96,Image.XPadding )

but how or where is the file copied to my data directory?

If I want to do something similar in my Module, then what is the recommended approach to doing this? Or can I just use the resource from the Module's/data folder?


therevills(Posted 2012) [#2]
I'm not 100% sure as I'm not on the PC right now, but I believe the mojo font is copied from the targets folders. You won't be able to do it via a module.

Yep I was totally wrong :P


dawlane(Posted 2012) [#3]
Just had a quick checked on the computer. And it looks like it's added as an Import in graphics.monkey in modules mojo. Also in there is a BMax file to create a font.


dawlane(Posted 2012) [#4]
Been playing around and did a bit of testing.
I commented out the Import at the top of graphics.monkey. Gave it a test and no file was transferred.
Then placed a font with the same name and size as mojo_font.png in another directory then just added a Import to that file into the test file.
Looks like it works.


Skn3(Posted 2012) [#5]
Yeah that is how you import. It would be handy if you could force monkey to manually import any file. That way we could copy along libs into the build folder.


Skn3(Posted 2012) [#6]
<double post>


Tibit(Posted 2012) [#7]
So to import a resource I simply do:

Import "data/mojo_font.png"

LoadImage( "mojo_font.png",96,Image.XPadding )

If I want to make use of a font, sound or other temporary graphics in a module I can import the files like that and then simply load them as if they exist, and only if the load is called the file is transferred?

It would be handy if you could force monkey to manually import any file.

Does it not do exactly that? What is the limitation?


dawlane(Posted 2012) [#8]
If I want to make use of a font, sound or other temporary graphics in a module I can import the files like that and then simply load them as if they exist, and only if the load is called the file is transferred?
As I understand it, any file that's not a source file will be passed on into your projects build folder ( meaning that your app will require it to work if you use it in your code ). To Import a font you will have to still load it and use SetFont, unless you do what I did and disabled the Import in graphics.monkey, then you can just use a png font as long as it's the same name as mojo_font. If you didn't disable that import then I would guess that trying to Import another file with the same name may stop trans in it's tracks.

I think Skn3 was thinking a long the lines on importing precompiled 3d party libraries.


Skn3(Posted 2012) [#9]
Yeah sorry I wasn't very clear, yeah it would be nice to be able to force any file to import at build time. It couldn't a while ago, so maybe it has changed now? It would be most useful for modules adding external JavaScript libraries and such!


ziggy(Posted 2012) [#10]
It can do it now. My JungleGui module does import a default font and a javascript file on HTML5 without any issues,


Tibit(Posted 2012) [#11]
What exactly does the import "filehere" do?

Can I import a .js file and then simply reference things inside it?

@Ziggy, so what you are saying is that as long as I have import fontmachine and I have a default font I can use for testing? Since that is similar to what I wanted to do, for adding font to quick temp test things.


ziggy(Posted 2012) [#12]
Import "myfile" will copy the file to the data folder AFAIK.


Tibit(Posted 2012) [#13]
ah ok, so it is that simple. Great :)