dragome/dragome-sdk

[Suggestion] Getting Resources

Opened this issue · 7 comments

Binary resources (images etc) can be converted to base64 and put into a global object. The "getResourceAsStream" method of "Class" can simply find the resource from the defined global object and convert it from base64 to binary and channel it to the caller. However, ByteArrayInputStream must be implemented for that to work which is also missing. Or a ResourceHelper class may return the base64 data directly. Resources that are text(not binary) can be urlencoded and then urldecoded instead of using base64 from this helper class. A Dragome ResourceHelper may be a better option if performance is the target.

Having a ResourceHelper class and making getResourceAsStream to make a call to it is a win win. Developer may choose to use either one of them.

There is no way to get our resources (images etc). This is a real blocker.

@xpenatan is using this version of ByteArrayInputStream: https://github.com/xpenatan/dragome-backend/blob/master/backends/gdx-backend-dragome/emu/java/io/ByteArrayInputStream.java
I'll be merging several classes from this project to dragome base soon.

Great to hear this. We really need the getResourceAsStream working.

We really need this to compile our operating system and applications. Here is a proposal;
Scan all resources and create an entry to a object hash using the found resource paths. Binary data is converted to base64. This can be done in assembly phase and the resources can be added right before the ready method at the very end.

dragome.resources={ binary:{}, text:{} };

such as;
dragome.resources.binary['com/test/resources/pixel.gif'] = 'R0lGODlhAQABAIAAAMbGxgAAACH5BAEAAAAALAAAAAABAAEAQAICRAEAOw==';

dragome.resources.text['com/test/resources/readme.txt'] = 'Hello World';

in Class.java the method getResourcesAsStream will just look for the resource searching binary data first then text data. Binary base64 data is converted to byte array, as well as text data is converted to byte array. The resulting byte array can be streamed using ByteArrayInputStream. The initial resource searching method used in getResourcesAsStream can be made available in a Dragome helper class, so that conversion and streaming phase can be omitted for better performance.

Very large files (larger than 50K for example) can be written to the directory where dragome.js located with randomized names. They can be reached using getResource(String name) method as a URL.

Any update on this bug?