A project I'm starting to work on will be an entirely browser based game. I had an idea to somehow use images as the save files.
The script/function set I came up with will take any javascript variable (array, scalar, object), and convert it into a PNG file. This is done by first JSON.stringify()ing it, then converting ascii to hex, then hex to RGB, then using <canvas> to set individual pixels to those RGB values. I also wrote functionality to then read a PNG file & convert it back to ASCII.
Rather than post it all here, I've made a working example here: http://jsfiddle.net/SzPMj/7/
In the future I'll probably work this all into one big class - this is just a proof of concept more than anything.
JSON => PNG (Javascript)
Moderator: General Moderators
JSON => PNG (Javascript)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: JSON => PNG (Javascript)
That's the most interesting part. How would you use them, and what's the advantage over, say, LocalStorage?I had an idea to somehow use images as the save files.
Re: JSON => PNG (Javascript)
what is the practical application of this procedure?
Re: JSON => PNG (Javascript)
The main reason for doing this was to see if I could. I'm thinking I'll store all the game data in one central object, then write that object to file when saving. To load a save game, just upload a save file image, it'll be read in, and the game initialized.
LocalStorage is limited to 5 MB. While I doubt the PNG files I need to generate will be anywhere close to that, it's nice to not have a limit.
Image files can also be downloaded and moved around, say from computer to computer. So, when my game becomes wildly popular, the throngs of fans will be able to swap saved games.
LocalStorage is limited to 5 MB. While I doubt the PNG files I need to generate will be anywhere close to that, it's nice to not have a limit.
Image files can also be downloaded and moved around, say from computer to computer. So, when my game becomes wildly popular, the throngs of fans will be able to swap saved games.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: JSON => PNG (Javascript)
This is good as long as people don't take screenshots from their monitor or take a snap on their mobiles in hopes of getting the save data to transfer to another instance of a game(like QR code). Or will it work so?
Re: JSON => PNG (Javascript)
I doubt it, the images in the example are zoomed in 2000% - the actual generated image is much smaller. Reading the image back in requires pixel perfect accuracy, so screenshots will almost certainly fail.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: JSON => PNG (Javascript)
The idea (and application) is pretty good; reminds me of steganography.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: JSON => PNG (Javascript)
A while back this technique was used in the 10K apart contest. Here are details: http://www.iamcal.com/png-store/