mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 17:27:22 +02:00
have locals torage woring
This commit is contained in:
parent
0735eb3d64
commit
465b25368e
7 changed files with 113 additions and 39 deletions
|
@ -11,8 +11,15 @@ var Main = require('../app');
|
|||
function LevelArbiter() {
|
||||
this.levelMap = {};
|
||||
this.init();
|
||||
// TODO -- local storage sync
|
||||
this.solvedMap = {};
|
||||
|
||||
var solvedMap = {};
|
||||
try {
|
||||
solvedMap = JSON.parse(localStorage.getItem('solvedMap'));
|
||||
} catch (e) {
|
||||
console.warn('local storage failed', e);
|
||||
throw e;
|
||||
}
|
||||
this.solvedMap = solvedMap;
|
||||
|
||||
Main.getEvents().on('levelSolved', this.levelSolved, this);
|
||||
}
|
||||
|
@ -38,10 +45,6 @@ LevelArbiter.prototype.init = function() {
|
|||
}, this);
|
||||
};
|
||||
|
||||
LevelArbiter.prototype.getSolvedMap = function() {
|
||||
return this.solvedMap;
|
||||
};
|
||||
|
||||
LevelArbiter.prototype.isLevelSolved = function(id) {
|
||||
if (!this.levelMap[id]) {
|
||||
throw new Error('that level doesnt exist!');
|
||||
|
@ -51,6 +54,15 @@ LevelArbiter.prototype.isLevelSolved = function(id) {
|
|||
|
||||
LevelArbiter.prototype.levelSolved = function(id) {
|
||||
this.solvedMap[id] = true;
|
||||
this.syncToStorage();
|
||||
};
|
||||
|
||||
LevelArbiter.prototype.syncToStorage = function() {
|
||||
try {
|
||||
localStorage.setItem('solvedMap', JSON.stringify(this.solvedMap));
|
||||
} catch (e) {
|
||||
console.warn('local storage fialed on set', e);
|
||||
}
|
||||
};
|
||||
|
||||
LevelArbiter.prototype.validateLevel = function(level) {
|
||||
|
|
|
@ -119,8 +119,10 @@ var Sandbox = Backbone.View.extend({
|
|||
// handle the case where that level is not found...
|
||||
if (!levelJSON) {
|
||||
command.addWarning(
|
||||
'A level for that id "' + desiredID + '" was not found!!'
|
||||
'A level for that id "' + desiredID + '" was not found!! Opening up level selection view...'
|
||||
);
|
||||
Main.getEventBaton().trigger('commandSubmitted', 'levels');
|
||||
|
||||
command.set('status', 'error');
|
||||
deferred.resolve();
|
||||
return;
|
||||
|
|
|
@ -163,9 +163,7 @@ var Command = Backbone.Model.extend({
|
|||
var CommandEntry = Backbone.Model.extend({
|
||||
defaults: {
|
||||
text: ''
|
||||
},
|
||||
// stub out if no plugin available
|
||||
localStorage: (Backbone.LocalStorage) ? new Backbone.LocalStorage('CommandEntries') : null
|
||||
}
|
||||
});
|
||||
|
||||
exports.CommandEntry = CommandEntry;
|
||||
|
|
|
@ -165,7 +165,6 @@ var CommandPromptView = Backbone.View.extend({
|
|||
this.commands.each(function(c) {
|
||||
Backbone.sync('delete', c, function() { });
|
||||
}, this);
|
||||
localStorage.setItem('CommandEntries', '');
|
||||
},
|
||||
|
||||
setTextField: function(value) {
|
||||
|
|
|
@ -28,6 +28,14 @@ var LevelDropdownView = ContainedBase.extend({
|
|||
300,
|
||||
true
|
||||
));
|
||||
this.navEvents.on('negative', this.negative, this);
|
||||
this.keyboardListener = new KeyboardListener({
|
||||
events: this.navEvents,
|
||||
aliasMap: {
|
||||
esc: 'negative'
|
||||
},
|
||||
wait: true
|
||||
});
|
||||
|
||||
this.sequences = Main.getLevelArbiter().getSequences();
|
||||
this.container = new ModalTerminal({
|
||||
|
@ -41,8 +49,13 @@ var LevelDropdownView = ContainedBase.extend({
|
|||
}
|
||||
},
|
||||
|
||||
negative: function() {
|
||||
this.hide();
|
||||
},
|
||||
|
||||
show: function(deferred) {
|
||||
this.showDeferred = deferred;
|
||||
this.keyboardListener.listen();
|
||||
LevelDropdownView.__super__.show.apply(this);
|
||||
},
|
||||
|
||||
|
@ -51,6 +64,7 @@ var LevelDropdownView = ContainedBase.extend({
|
|||
this.showDeferred.resolve();
|
||||
}
|
||||
this.showDeferred = undefined;
|
||||
this.keyboardListener.mute();
|
||||
|
||||
LevelDropdownView.__super__.hide.apply(this);
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue