#Import "assets/something" why import lines for this ?

About Monkey 2 Forums Monkey 2 Development #Import "assets/something" why import lines for this ?

Tagged: 

This topic contains 7 replies, has 3 voices, and was last updated by  Richard Betson 2 years, 6 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2808

    gcmartijn
    Participant

    Why do we need to import all the assets first.
    > are they loaded at that point in memory (I guess not) ?
    #Import “assets/test.png”
    #Import “assets/test.json”

    But then later we have to write again the ‘path’
    Local obj:=JsonObject.Load(‘asset::test.json’)

    Why is this ?
    Why not just one (path) line like this (not working)
    Local obj:=JsonObject.Load(‘assets/test.json’)

    Or a mix like this
    #Import “assets/*.json”
    or
    #Import “assets/*”

    If some game have more then 100 assets :S :S

    What is the idea behind this ?

    #2809

    Mark Sibly
    Keymaster

    Local obj:=JsonObject.Load(‘assets/test.json’)

    This loads directly from the filesystem, and will work if you’re in the right current directory, eg:

    ChangeDir( ExtractDir( AssetsDir() ) )   ‘changedir to parent dir of assets dir.

    Local obj:=JsonObject.Load( ‘assets/test.json’ )

    But note that if you’re trying to write something that runs everywhere, assets may not even be stored in the filesystem (eg: on android they’re stored in a zip), so it’s safest to use ‘asset::’

    #Import “assets/*”

    This will be in the next release.

    #2826

    gcmartijn
    Participant

    Oke.

    I din’t know about the zipfile construction, I will use the asset:: thing.
    #Import “assets/*” would be cool and easy.
    My json loader will load all the assets (something like atlas)

    I had this situation because
    a.monkey2
    #Import “src/JSONLoader”
    Field json:JSONLoader =  New JSONLoader()
    json.loadScene(“assets/scene1.json”)

    b.monkey2
    Method loadScene(_inpJSONFile:String)
    Local obj:=JsonObject.Load( _inpJSONFile ) ‘ but that don’t not work now

     

    This is working
    a.monkey2
    #Import “src/JSONLoader”
    #Import “assets/scene1.json”
    Field json:JSONLoader =  New JSONLoader()
    json.loadScene(“assets::scene1.json”)

    b.monkey2
    Method loadScene(_inpJSONFile:String)
    Local obj:=JsonObject.Load( _inpJSONFile )

    #4157

    gcmartijn
    Participant

    What does the jsonvalue.save() do ?

    But note that if you’re trying to write something that runs everywhere, assets may not even be stored in the filesystem (eg: on android they’re stored in a zip), so it’s safest to use ‘asset::’

    I need to store save files and other files on all devices (future proof) so first I thought this is the way:

     

    In other words, what is the best path to save files so it works on all clients devices/desktop

    In the example above I’m trying to overwrite the official data-world1.json file with new data.
    What is the path to do that for all devices/desktop

    #4161

    Mark Sibly
    Keymaster

    In other words, what is the best path to save files so it works on all clients devices/desktop

    These need to be added…

    #4162

    Richard Betson
    Participant

    These are some of the issues I encountered and posted about before version 1.0.0.  As of now I am loading all of my assets using Image.Load() or LoadString(). The asset count for my project is well beyond using #import asset and most of the assets must be loaded at runtime. An example of this is assets for a game map or skin images or text based configuration files all of which are dynamic. It really is an issue of scope and scale as larger more enterprising or specialized projects just may not work well with the #Import asset model.

    I did like the way MX1 handle this with use of a path to the data folder ala. monkey://data/.

    #4165

    Mark Sibly
    Keymaster

    I did like the way MX1 handle this with use of a path to the data folder ala. monkey://data/.

    The mx2 system works pretty much the same way. Any asset files you #import are copied into the apps ‘data’ folder (just like mx1’s blah.data dir) and using “asset::blah…” as a file path will load an asset at runtime.

    You can replicate mx1 exactly-ish by using #Import “myapp.data/” or whatever at the top of your code. The trailing ‘/’ means to copy the whole dir. You can then use “asset::” to load these assets at runtime.

    #4168

    Richard Betson
    Participant

    I’ll give that a try. Thanks.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.