kittykatattack / ga

The world's tiniest, cutest and funnest game engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for base64 encoded files.

peacememories opened this issue · comments

Hi, and thanks for your work on this neat little engine.
I'm currently working on an entry for js13k, and using webpack with a few loaders. One of them is a base64 loader which packs required files (like images) into a data url string at compile time. This is neat because it allows me to embed everything quickly in one single html file.

Unfortunately this does not seem to work with gas asset loading. Trying to preload a data url results in the loader complaining about unsupported types.

It would be lovely to have this feature in ga. If there is already a way (even if a bit more complicated) to do this, I would love to hear it also :)

@peacememories Hello!

Ga does support bas64! :)

#47

Unfortunately, I've never used this feature and don't know how to to integrate it with Ga's asset loader.
I suppose you could create your own custom asset loader that works with base64, and then just initialize Ga when it's ready...?

But, I don't know 🙃

Can anyone help?

Ah I see. One workaround I thought of was to just manually inject the dependencies into the asset dict.

The other variant (which would not be bad anyway, I think) could be to stop testing assets by file extension and instead fetch them and look at the mime type. One drawback I see with this is more ram usage, although I'm not sure that would be the case, and it might be worth it anyway.

Elaboration on more ram usage:

One could use the fetch API to fetch the url in the asset array, then test for mime types and use the createDataURL function to create a data url from the original file. This would of course mean that some assets would store the url, the data url, and the actual data somewhere, potentially doubling or tripling the memory consumption. Right now this would be worth it for me, since in cases where this memory consumption would pose problems the advantages of Ga (namely its tiny footprint) would not matter anymore and people might choose bigger engines with different asset handling.

Also possible:
In addition to plain urls, allow objects of the form

{
  name: 'name to be used as key',
  source: <>
}

to be supplied in the array.

Then allow source to also include plain Image objects, or, crucially, promises that resolve to other objects (this would allow any loader to cleanly hook into the loading progress bar)

@peacememories: Wow, that's interesting! I've never thought of doing that - could be amazing! If you manage to get this working, please PR :)