-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautomat.js
65 lines (46 loc) · 1.4 KB
/
automat.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
debug.log('import automat.js');
function Class() {
}
Class.prototype.construct = function() {};
Class.extend = function(def) {
var classDef = function() {
if (arguments[0] !== Class) {
this.construct.apply(this, arguments);
}
};
var proto = new this(Class);
var superClass = this.prototype;
for (var n in def) {
var item = def[n];
if (item instanceof Function)
item.$ = superClass;
proto[n] = item;
}
classDef.prototype = proto;
classDef.extend = this.extend;
return classDef;
};
var Automat = Class.extend({
state: null,
name: null,
construct: function(begin_state) {
this.state = begin_state;
this.name = "undefined";
debug.log('CREATED AUTOMAT ' + this.name)
this.init();
},
A: function (event, args) {
},
init: function () {
},
state_changed: function (old_state, new_state, event, args) {
},
event: function (evt, args) {
debug.log(this.name + '(' + this.state + ') fired with \'' + evt + '\'');
var old = this.state;
this.A(evt, args);
if (old != this.state)
debug.log(this.name + ' : ' + old + ' -> ' + this.state);
this.state_changed(old, this.state, evt, args);
}
});