-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathActionQueue.js
127 lines (103 loc) · 3 KB
/
ActionQueue.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
var Sburb = (function(Sburb){
///////////////////////////////////////
//ActionQueue Class
///////////////////////////////////////
//constructor
Sburb.ActionQueue = function(action, id, groups, noWait, paused, trigger) {
this.curAction = action;
this.id = (id && (id.length>0)) ? id : Sburb.nextQueueId++;
this.groups = groups ? groups : [];
this.noWait = noWait ? noWait : false;
this.paused = paused ? true : false;
this.trigger = trigger;
}
Sburb.ActionQueue.prototype.hasGroup = function(group) {
for(var i=0;i<this.groups.length;i++) {
if(this.groups[i]==group) {
return true;
}
}
return false;
}
Sburb.ActionQueue.prototype.serialize = function(output) {
if(!this.curAction) {
return "";
}
var groupString="";
for(var i=0;i<this.groups.length;i++) {
groupString+=((i>0)?":":"")+this.groups[i];
}
output = output.concat("\n<actionQueue "+Sburb.serializeAttributes(this,"id","noWait","paused")
+(groupString.length==0?"":" groups='"+groupString+"'")+">");
output = this.curAction.serialize(output);
if(this.trigger) {
output = this.trigger.serialize(output);
}
output = output.concat("</actionQueue>");
return output;
}
//////////////////////////////////////////////////
//Related utility functions
//////////////////////////////////////////////////
Sburb.getActionQueueById = function(id) {
for(var i=0;i<this.actionQueues.length;i++) {
var queue=this.actionQueues[i];
if(queue.id==id) {
return queue;
}
}
}
Sburb.removeActionQueueById = function(id) {
for(var i=0;i<this.actionQueues.length;i++) {
var queue=this.actionQueues[i];
if(queue.id==id) {
this.actionQueues.remove(i);
return;
}
}
}
Sburb.forEachActionQueueInGroup = function(group, callback) {
for(var i=0;i<this.actionQueues.length;i++) {
var queue=this.actionQueues[i];
if(queue.hasGroup(group)) {
callback(queue);
}
}
}
Sburb.removeActionQueuesByGroup = function(group) {
for(var i=0;i<this.actionQueues.length;i++) {
var queue=this.actionQueues[i];
if(queue.hasGroup(group)) {
this.actionQueues.remove(i);
i--;
}
}
}
Sburb.parseActionQueue = function(node) {
var attributes = node.attributes;
var newAction = null;
var newId = 0;
var newGroups = null;
var newNoWait = false;
var newPaused = false;
var newTrigger = null;
var childNodes = node.childNodes;
for(var i=0;i<childNodes.length;i++) {
if(childNodes[i].nodeName == "#text") {
continue;
}
if(childNodes[i].nodeName == "action") {
newAction = Sburb.parseAction(childNodes[i]);
} else {
newTrigger = Sburb.parseTrigger(childNodes[i]);
}
}
var temp;
newId = (temp=attributes.getNamedItem("id"))?temp.value:(Sburb.nextQueueId++);
newGroups = (temp=attributes.getNamedItem("groups"))?temp.value.split(":"):newGroups;
newNoWait = (temp=attributes.getNamedItem("noWait"))?temp.value=="true":newNoWait;
newPaused = (temp=attributes.getNamedItem("paused"))?temp.value=="true":newPaused;
return new Sburb.ActionQueue(newAction,newId,newGroups,newNoWait,newPaused,newTrigger);
}
return Sburb;
})(Sburb || {});