fluxify it

This commit is contained in:
Peter Cottle 2015-08-29 08:45:53 -07:00
parent 78b87b3c47
commit de8d8221f5
4 changed files with 34 additions and 8 deletions

View file

@ -14,6 +14,12 @@ var GlobalStateActions = {
});
},
levelSolved: function() {
AppDispatcher.handleViewAction({
type: ActionTypes.LEVEL_SOLVED,
});
},
changeFlipTreeY: function(flipTreeY) {
AppDispatcher.handleViewAction({
type: ActionTypes.CHANGE_FLIP_TREE_Y,

View file

@ -25,7 +25,13 @@ module.exports = {
CHANGE_FLIP_TREE_Y: null,
SUBMIT_COMMAND: null,
CHANGE_LOCALE: null,
CHANGE_LOCALE_FROM_HEADER: null
CHANGE_LOCALE_FROM_HEADER: null,
/**
* only dispatched when you actually
* solve the level, not ask for solution
* or solve it again.
*/
SOLVE_LEVEL: null
}),
PayloadSources: keyMirror({

View file

@ -34,8 +34,6 @@ var regexMap = {
'objective': /^(objective|assignment)$/
};
var MAX_TIMES_SHOW_ANIMATION = 5;
var parse = util.genParseCommand(regexMap, 'processLevelCommand');
var Level = Sandbox.extend({
@ -439,8 +437,6 @@ var Level = Sandbox.extend({
}
this.hideGoal();
window.numLevelsSolved = window.numLevelsSolved || 0;
window.numLevelsSolved++;
var nextLevel = LevelStore.getNextLevel(this.level.id);
var numCommands = this.gitCommandsIssued.length;
@ -448,11 +444,17 @@ var Level = Sandbox.extend({
var skipFinishDialog = this.testOption('noFinishDialog') ||
this.wasResetAfterSolved;
var skipFinishAnimation = this.wasResetAfterSolved ||
window.numLevelsSolved > MAX_TIMES_SHOW_ANIMATION;
var skipFinishAnimation = this.wasResetAfterSolved;
if (!skipFinishAnimation) {
GlobalStateActions.levelSolved();
}
/**
* Speed up the animation each time we see it.
*/
var speed = 1.0;
switch (window.numLevelsSolved) {
switch (GlobalStateStore.getNumLevelsSolved()) {
case 2:
speed = 1.5;
break;
@ -466,6 +468,9 @@ var Level = Sandbox.extend({
speed = 2.4;
break;
}
if (GlobalStateStore.getNumLevelsSolved() > 5) {
speed = 2.5;
}
var finishAnimationChain = null;
if (skipFinishAnimation) {

View file

@ -10,6 +10,7 @@ var ActionTypes = AppConstants.ActionTypes;
var _isAnimating = false;
var _flipTreeY = false;
var _numLevelsSolved = 0;
var GlobalStateStore = assign(
{},
@ -24,6 +25,10 @@ AppConstants.StoreSubscribePrototype,
return _flipTreeY;
},
getNumLevelsSolved: function() {
return _numLevelsSolved;
},
dispatchToken: AppDispatcher.register(function(payload) {
var action = payload.action;
var shouldInform = false;
@ -37,6 +42,10 @@ AppConstants.StoreSubscribePrototype,
_flipTreeY = action.flipTreeY;
shouldInform = true;
break;
case ActionTypes.LEVEL_SOLVED:
_numLevelsSolved++;
shouldInform = true;
break;
}
if (shouldInform) {