Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

API for selecting an asset ?

@Simeon, You have implemented an asset picker in the editor but i would like to be able to use a simplified version in the code to select a file from the project/dropbox/.. assets. Ideally we could specify the file extension so that only the file types wanted would show up. I know assetList() exists but it would be nice to have a native API for a graphical user selectable asset list.

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @piinthesky this is a good suggestion

    The best thing might be to present the new document picker UI filtered to whatever file types you specify in the API. The problem is, how do you "get" the resulting document to use? We could copy it into the Project folder and then return the corresponding key, but what if it's a file type we don't support? Just treat it as plain text?

    file.pick(".txt", function(key)
        -- When the picking operation finishes this callback is called
        -- the file is stored at `key` (which is something like "Project:File")
    end)
    
    file.pick(".txt", function(data)
        -- When the picking operation finishes this callback is called
        -- the file comes in as text or binary data, may be harder to use?
    end)
    
  • @Simeon i was originally thinking of it as a way to just get the name of the file so that it could be fed into readText(). You go an extra step which is to copy the asset from some location to the project folder (if it is not already there)-that could be useful.

    For the unsupported filetypes, yes treat it as plain text.

    By the way, i currently use readText() to load in a json file to feed to decodeJson(). The extension of my files is .js. The readText will not read them if i have selected via the asset picker-as the extension is not propagated to the name of the selected file. If I add the extension to the filename then the readText() works.

    In general, i would prefer to be able to see the file extensions in an asset picker. Sometimes i have the same 3d model with the same name but in different file formats so i never know which one i should pick without the file extension being visible!

Sign In or Register to comment.