2014-03-11 16:52:02 +01:00
|
|
|
window.fakeStorage = {
|
|
|
|
_data : {},
|
|
|
|
setItem : function (id, val) {
|
|
|
|
console.log('set');
|
|
|
|
return this._data[id] = String(val);
|
|
|
|
},
|
|
|
|
getItem : function (id) {
|
|
|
|
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
|
|
|
|
},
|
|
|
|
removeItem : function (id) { return delete this._data[id]; },
|
|
|
|
clear : function () { return this._data = {}; }
|
|
|
|
};
|
|
|
|
|
2014-03-10 21:02:16 +01:00
|
|
|
function LocalScoreManager() {
|
2014-03-11 16:52:02 +01:00
|
|
|
var localSupported = !!window.localStorage;
|
2014-03-10 21:02:16 +01:00
|
|
|
this.key = 'bestScore';
|
2014-03-11 16:52:02 +01:00
|
|
|
this.storage = localSupported ? window.localStorage : window.fakeStorage;
|
2014-03-10 21:02:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalScoreManager.prototype.get = function () {
|
2014-03-11 16:52:02 +01:00
|
|
|
var score = this.storage.getItem(this.key);
|
|
|
|
if (typeof score === "undefined" || score === null) {
|
|
|
|
score = 0;
|
2014-03-10 21:02:16 +01:00
|
|
|
}
|
2014-03-11 16:52:02 +01:00
|
|
|
return score;
|
2014-03-10 21:02:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
LocalScoreManager.prototype.set = function (score) {
|
2014-03-11 16:52:02 +01:00
|
|
|
this.storage.setItem(this.key, score);
|
2014-03-10 21:02:16 +01:00
|
|
|
};
|
|
|
|
|