LibLoad from string?

Does anyone know if it’s possible to libload data from a version of a blend file sent over the internet? Perhaps saved as a JSON string…
I’m thinking about the idea of having downloadable content and how that might be delivered in to a game.

I’m not really talking about DLC, i.e. paid extras (which I would probably just include in the main file anyway and then transmit some code to unlock them), but more kind of community created content that can be uploaded and then downloaded by other users.

The idea would be that you already have the game, so there’s no need to go to a site, download something and put it in a folder, that sometimes takes longer than downloading the file these days. Just click in game, and it’s downloaded to you and available as soon as the download is finished.

I notice that the API says:

  • blend (string) – The path to the blend file (or the name to use for the library if data is supplied)
  • data (bytes) – Binary data from a blend file (optional)

I guess it could be just a case of downloading the string, encoding it and feeding it to Libload…?

Anyone else already gone down this route before I spend a day researching it?

My route of transmission would be the game jolt saved data API, which can accept data as strings (so sending a JSON dict as a string is possible).

There’s no need to use this. Just download a temporary file. Otherwise, you must store the file in-memory, and at one point you’ll have at least twice the data in memory.

The bytes option may have its uses, if you don’t want to create a file on the OS. Even then, that’s really a poor decision for making such a tradeoff.

A basic usage of the data argument would be:

with open('lib.blend', 'r') as f:
    bge.logic.LibLoad('lib', 'Scene',

Although, this isn’t too useful since you could just pass lib.blend into LibLoad. If you read the contents of the file, base64 encode it, send the data via JSON, base64 decode it, then pass it into LibLoad, I believe it should work.

I wouldn’t even bother using JSON, and just send the bytes directly to a socket.