Skip to content

Commit

Permalink
Highlight invalid algs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Garron committed Feb 17, 2014
1 parent 04a99bb commit e59418b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions alg.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
<h1><textarea id="title" rows="{{title | num_lines}}" ng-trim="false" ng-model="title" placeholder="alg.cubing.net"></textarea>

<h2 ng-show="type.id != 'algorithm'" ng-bind="type.setup">Setup</h2>
<textarea id="setup" ng-show="type.id != 'algorithm'" rows="{{setup | num_lines}}" ng-trim="false" class="moves" ng-model="setup" placeholder="[Click here to add {{type.setup | lowercase}} moves.]"
<textarea id="setup" ng-show="type.id != 'algorithm'" rows="{{setup | num_lines}}" ng-trim="false" class="moves" ng-model="setup" placeholder="[Click here to add {{type.setup | lowercase}} moves.]" ng-class="{'invalid': !setupValid}"
></textarea>

<h2 ng-bind="type.alg">Algorithm</h2>
<textarea id="algorithm" rows="{{alg | num_lines}}" ng-trim="false" class="moves" ng-model="alg" placeholder="[Click here to add {{type.moves}}.]"
<textarea id="algorithm" rows="{{alg | num_lines}}" ng-trim="false" class="moves" ng-model="alg" placeholder="[Click here to add {{type.moves}}.]" ng-class="{'invalid': !algValid}"
></textarea>

<h2>Settings</h2>
Expand Down
10 changes: 10 additions & 0 deletions inc/alg.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ html, textarea {
cursor: pointer;
}

.moves.invalid {
border: 1px solid red;
background: rgba(255, 0, 0, 0.1);
}

.moves.invalid, .moves.invalid:hover, .moves.invalid:focus {
border: 1px solid red;
background: rgba(255, 0, 0, 0.1);
}

#info h1 {
font-variant: small-caps;
width: 100%;
Expand Down
25 changes: 19 additions & 6 deletions inc/alg.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ algxControllers.controller('algxController', ["$scope", "$location", function($s
$scope.speed = 1;
$scope.current_move = 0;

$scope.setupValid = true;
$scope.algValid = true;

$scope.title_default = "";
$scope.title = $scope.title_default;
if ("title" in search) {
Expand Down Expand Up @@ -206,8 +209,22 @@ algxControllers.controller('algxController', ["$scope", "$location", function($s
"colors": colorList($scope.scheme.scheme)
});

var init = alg.sign_w.stringToAlg($scope.setup);
var algo = alg.sign_w.stringToAlg($scope.alg);
try {
var algo = alg.sign_w.stringToAlg($scope.alg);
$scope.algValid = true;
} catch (e) {
$scope.algValid = false;
throw e;
}

try {
var init = alg.sign_w.stringToAlg($scope.setup);
$scope.setupValid = true;
} catch (e) {
$scope.setupValid = false;
throw e;
}

var type = $scope.type.type;

init = alg.sign_w.algToMoves(init);
Expand Down Expand Up @@ -254,18 +271,14 @@ algxControllers.controller('algxController', ["$scope", "$location", function($s
var idx = twistyScene.debug.getIndex() + 1;
var val = $scope.current_move;
if (idx != val && fire) {
fire = false;
$scope.$apply("current_move = " + idx);
fire = true;
}
});
$scope.$watch('current_move', function() {
var idx = twistyScene.debug.getIndex() + 1;
var val = $scope.current_move;
if (idx != val && fire) {
fire = false;
twistyScene.setIndex($scope.current_move - 1);
fire = true;
}
});
$scope.$watch('speed', function() {
Expand Down

0 comments on commit e59418b

Please sign in to comment.