Creating new assets is difficult
cwillisf opened this issue · 4 comments
Expected Behavior
There should be a straightforward way to create a new empty Asset
object, or to create a new Asset
with externally-defined contents, without relying on an environment-specific data type.
Actual Behavior
Doing so currently requires creating a Buffer
, which is a Node.js-only type. This means there's no good way to create or fill an Asset
in environment-neutral code.
Steps to Reproduce
Once this is fixed we should review all paths in the VM which duplicate sprites, costumes, and sounds. Those duplication paths should be duplicating assets rather than "loading" fresh assets.
I am also interested in following up on this as we want to create our own library of sprites and currently there is no easy way to do that :(
@cwillisf
@stefania11 I believe this issue isn't related to that (this issue is about dynamically creating asset objects). To add items to libraries of sprites/etc, you'll want to look into modifying the files in src/lib/libraries
of scratch-gui (all that's required is that the assets (i.e. their "md5" files) be uploaded onto assets.scratch.mit.edu, which you can do by importing them into any online Scratch project).
Check out an npm package called buffer. The APIs are the same as the Node.js ones, and it supports browsers. Currently our project attaches the storage to the vm and we run it on browsers using
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
})