forked from santanche/mlca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlca_Ruleset.js
38 lines (33 loc) · 857 Bytes
/
mlca_Ruleset.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
/*
Ruleset: a set of rules for a determined layer
-ruleList: rule[]
specs: {ruleList}
+run(coordinate): Return a boolean telling if a rule succeeded.
Try to apply one of the rules in rule List then exit.
*/
mlca.Ruleset = function(specs){
'use strict';
this.ruleList = specs.ruleList;
this.layerID = specs.layerID;
this.layerRef = mlca.layerList.getLayerByID(this.layerID);
};
mlca.Ruleset.prototype = {
ruleList: [],
run: function(coords){
'use strict';
var i, ret = false;
for(i = 0; i< this.ruleList.length; i+=1){
if (this.ruleList[i].apply(coords)){
ret = true;
break;
}
}
if (ret === false){
if (this.layerRef === undefined){
this.layerRef = mlca.layerList.getLayerByID(this.layerID);
}
this.layerRef.write(coords,this.layerRef.read(coords));
}
return ret;
}
};