I'm creating an HTML5 2D game and I want to request each asset only once and then store them in the user's filesystem, I'm using localStorage for this task, however AFAIK it has a limit of 5mb per origin, (my whole game will have more than that), and I want to know how to store my game assets in the user's machine without that limitation, this is what I've done until now:
items.js:
/**
* Copyright 2014 - Edgar Alexander Franco.
*
* @author Edgar Alexander Franco
* @version 1.0.0
*/
var items = [
{
name : 'characters_scott',
url : './img/game/characters/scott',
type : 'png'
},
{
name : 'map_1',
url : './img/game/map/1',
type : 'jpg'
},
{
name : 'map_2',
url : './img/game/map/2',
type : 'jpg'
}
];
Resource.js
/**
* Copyright 2014 - Edgar Alexander Franco.
*
* @author Edgar Alexander Franco
* @version 1.0.0
*/
var Resource = (function () {
var self = {};
self.get = {};
self.load = function (items) {
var xhr = (typeof XMLHttpRequest != 'undefined') ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP') ;
var item, content, mime;
for (var i in items) {
item = items[ i ];
content = localStorage.getItem(item.url);
if (content == null) {
xhr.open('GET', item.url, false);
xhr.send();
content = xhr.responseText;
localStorage.setItem(item.url, content);
}
if (item.type != 'audio') {
mime = (item.type == 'jpg') ? 'image/jpeg' : 'image/png' ;
self.get[ item.name ] = new Image();
self.get[ item.name ].src = 'data:' + mime + ';base64,' + content;
} else {
// Not yet...
}
}
}
return self;
})();
The code from above works great, but doesn't cover my needs, as you can see I'm using localStore and it has it's limitations, I want to adapt the same code but for an unlimited storage, any ideas?