You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
892 B
JavaScript
49 lines
892 B
JavaScript
7 years ago
|
/*global $, MotorMixRule*/
|
||
7 years ago
|
'use strict';
|
||
|
|
||
7 years ago
|
var MotorMixerRuleCollection = function () {
|
||
7 years ago
|
|
||
|
var self = {};
|
||
|
var data = [];
|
||
|
|
||
|
self.put = function (element) {
|
||
|
data.push(element);
|
||
|
};
|
||
|
|
||
|
self.get = function () {
|
||
|
return data;
|
||
|
};
|
||
|
|
||
|
self.drop = function (index) {
|
||
7 years ago
|
data[index].setThrottle(0);
|
||
7 years ago
|
self.cleanup();
|
||
|
};
|
||
|
|
||
|
self.flush = function () {
|
||
|
data = [];
|
||
|
};
|
||
|
|
||
|
self.cleanup = function () {
|
||
|
var tmpData = [];
|
||
|
|
||
|
data.forEach(function (element) {
|
||
|
if (element.isUsed()) {
|
||
|
tmpData.push(element);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
data = tmpData;
|
||
|
};
|
||
|
|
||
|
self.inflate = function () {
|
||
|
while (self.hasFreeSlots()) {
|
||
7 years ago
|
self.put(new MotorMixRule(0, 0, 0, 0));
|
||
7 years ago
|
}
|
||
7 years ago
|
};
|
||
7 years ago
|
|
||
|
self.hasFreeSlots = function () {
|
||
7 years ago
|
return data.length < 8;
|
||
7 years ago
|
};
|
||
|
|
||
|
return self;
|
||
|
};
|