-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.controller.js
177 lines (149 loc) · 4.35 KB
/
main.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
'use strict';
var splatoonApp = angular.module('splatoonApp', []);
splatoonApp.controller('MainCtrl', function ($scope) {
//Load in datatables
angular.module('splatoonApp').stats($scope);
angular.module('splatoonApp').abilities($scope);
angular.module('splatoonApp').gear($scope);
//Start main logic
var points = 0;
$scope.mains = [];
$scope.subs = [];
$scope.showModal = false;
$scope.ErrorMessage= 'Testing';
$scope.toggleModal = function(){
$scope.showModal = !$scope.showModal;
};
$scope.activate = function(ability){
/*
for(var i = 0; i < $scope.mains.length; i++){
for(var j=0; j < $scope.gear.length; j++){
if($scope.gear[j].ability === $scope.mains[i].name){
abilitygear[i].push($scope.gear[j].type)
}
}
}
*/
if (points >= 57) {
//alert('Too Many Abilities!!');
$scope.ErrorMessage = 'Too Many Abilities!!';
$scope.toggleModal();
return;
}
var i = $scope.abilities.indexOf(ability);
if( $scope.mains.length<3 ){
if($scope.abilities[i].stackable || $scope.mains.indexOf(ability) == -1){
$scope.mains.push($scope.abilities[i]);
points+=10;
console.log($scope.mains.length);
console.log($scope.mains[$scope.mains.length-1]);
calc();
}
else {
//alert('Cannot Stack This Ability!!');
$scope.ErrorMessage = 'Cannot Stack This Ability!!';
$scope.toggleModal();
return;
}
}
else if ( $scope.abilities[i].stackable ){
$scope.subs.push($scope.abilities[i]);
points+=3;
calc();
}
else {
//alert('Cannot Sub This Ability!!');
$scope.ErrorMessage = 'Cannot Sub This Ability!!';
$scope.toggleModal(); }
};
$scope.demain = function(main) {
$scope.mains.splice($scope.mains.indexOf(main), 1);
points-=10;
calc();
};
$scope.desub = function(sub) {
$scope.subs.splice($scope.subs.indexOf(sub), 1);
points-=3;
calc();
};
// Calc function for finding values
function calc() {
//Hide all gear and show what is selected.
for(var i = 0; i < $scope.gear.length; i++){
console.log('hiding gear');
$scope.gear[i].show = false;
$scope.gear[i].uname = $scope.gear[i].name.replace(/ /g,'_');
}
console.log($scope.gear[0].show);
for(var i = 0; i < $scope.gear.length; i++){
for(var j=0; j < $scope.mains.length; j++){
if($scope.gear[i].ability === $scope.mains[j].name){
console.log('showing ' + $scope.gear[i].name);
$scope.gear[i].show = true;
console.log('showing ' + $scope.gear[i].show);
}
for(var itm in $scope.gear[i]){
if(itm === $scope.mains[j].name && $scope.gear[i][itm] === '1/3.3'){
console.log('showing ' + $scope.gear[i].name);
$scope.gear[i].show = true;
console.log('showing ' + $scope.gear[i].show);
}
}
}
}
for(var i=0; i < $scope.stats.length; i++){
var name = $scope.stats[i].name;
$scope.stats[i].apply(
$scope.mains.count(name),
$scope.subs.count(name)
);
}
}
$scope.clear = function() {
console.log('CLEARED');
$scope.mains.length=0;
$scope.subs.length=0;
points = 0;
calc();
};
});
splatoonApp.directive('modal', function () {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h4 class="modal-title">{{ ErrorMessage }}</h4>' +
'</div>' +
'<div class="modal-body">' +
'<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace:true,
scope:true,
link: function postLink(scope, element, attrs) {
scope.$watch(attrs.visible, function(value){
if(value == true)
$(element).modal('show');
else
$(element).modal('hide');
});
$(element).on('shown.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = true;
});
});
$(element).on('hidden.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = false;
});
});
}
};
});