Rev 1610 | Rev 1619 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1610 | Rev 1614 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | var modules = new Array(); |
2 | var modules = new Array(); |
| - | 3 | var module_aliases = new Array(); |
|
| - | 4 | ||
| - | 5 | function CreateModuleAlias(alias, module_name, module_id, extra) |
|
| - | 6 | { |
|
| - | 7 | module_aliases[alias] = { "is_group" : false, "module_name" : module_name, "module_id" : module_id, "extra" : extra }; |
|
| - | 8 | } |
|
| - | 9 | ||
| - | 10 | function CreateModuleAliasGroup(alias, aliases) |
|
| - | 11 | { |
|
| - | 12 | module_aliases[alias] = { "is_group" : true, "aliases" : aliases }; |
|
| - | 13 | } |
|
| 3 | 14 | ||
| 4 | function GetModule(name) |
15 | function GetModule(name) |
| 5 | { |
16 | { |
| 6 | if (typeof modules[name] == 'undefined') |
17 | if (typeof modules[name] == 'undefined') |
| 7 | { |
18 | { |
| Line 9... | Line 20... | ||
| 9 | 20 | ||
| 10 | if (eval("typeof " + name + " != 'function'")) |
21 | if (eval("typeof " + name + " != 'function'")) |
| 11 | { |
22 | { |
| 12 | Log("Failed to load " + name + " module."); |
23 | Log("Failed to load " + name + " module."); |
| 13 | return; |
24 | return; |
| 14 | } |
25 | } |
| 15 | 26 | ||
| 16 | modules[name] = eval("(new " + name + "('" + name + "'))"); |
27 | modules[name] = eval("(new " + name + "('" + name + "'))"); |
| 17 | } |
28 | } |
| 18 | 29 | ||
| 19 | return modules[name]; |
30 | return modules[name]; |
| 20 | } |
31 | } |
| 21 | 32 | ||
| 22 | function Module_OnChange(full_id, available) |
33 | function Module_OnChange(full_id, available) |
| 23 | { |
34 | { |
| 24 | var parts = full_id.split(":", 2); |
35 | var parts = full_id.split(":", 2); |
| 25 | 36 | ||
| 26 | if (global_legacy) |
37 | if (global_legacy) |
| Line 32... | Line 43... | ||
| 32 | var module = GetModule(parts[0]); |
43 | var module = GetModule(parts[0]); |
| 33 | 44 | ||
| 34 | if (module) |
45 | if (module) |
| 35 | { |
46 | { |
| 36 | module.SetStatus(parts[1], available); |
47 | module.SetStatus(parts[1], available); |
| 37 | } |
48 | } |
| 38 | } |
49 | } |
| 39 | 50 | ||
| 40 | function Module_OnMessage() |
51 | function Module_OnMessage() |
| 41 | { |
52 | { |
| 42 | var full_id = arguments[0]; |
53 | var full_id = arguments[0]; |
| 43 | var command = arguments[1]; |
54 | var command = arguments[1]; |
| Line 100... | Line 111... | ||
| 100 | { |
111 | { |
| 101 | this.name_ = name; |
112 | this.name_ = name; |
| 102 | this.ids_ = new Array(); |
113 | this.ids_ = new Array(); |
| 103 | 114 | ||
| 104 | this.EventBase(); |
115 | this.EventBase(); |
| 105 | } |
116 | } |
| 106 | 117 | ||
| 107 | Extend(Module, EventBase); |
118 | Extend(Module, EventBase); |
| 108 | 119 | ||
| 109 | Module.prototype.name_; |
120 | Module.prototype.name_; |
| 110 | Module.prototype.ids_; |
121 | Module.prototype.ids_; |
| 111 | 122 | ||
| 112 | Module.prototype.SetStatus = function(id, available) |
123 | Module.prototype.SetStatus = function(id, available) |
| Line 117... | Line 128... | ||
| 117 | this.EventBase.prototype.Trigger.call(this, "onStatusChange", id, available); |
128 | this.EventBase.prototype.Trigger.call(this, "onStatusChange", id, available); |
| 118 | } |
129 | } |
| 119 | else if (this.ids[id] != available) |
130 | else if (this.ids[id] != available) |
| 120 | { |
131 | { |
| 121 | this.EventBase.prototype.Trigger.call(this, "onStatusChange", id, available); |
132 | this.EventBase.prototype.Trigger.call(this, "onStatusChange", id, available); |
| 122 | } |
133 | } |
| 123 | } |
134 | } |
| 124 | 135 | ||
| 125 | Module.prototype.ReceiveMessage = function(id, command, variables) |
136 | Module.prototype.ReceiveMessage = function(id, command, variables) |
| 126 | { |
137 | { |
| 127 | //Log("received " + command); |
138 | //Log("received " + command); |
| 128 | } |
139 | } |
| 129 | 140 | ||
| 130 | Module.prototype.GetAvailableIds = function() |
141 | Module.prototype.GetAvailableIds = function() |
| 131 | { |
142 | { |
| 132 | var ids = new Array(); |
143 | var ids = new Array(); |
| 133 | 144 | ||
| 134 | for (var id in this.ids_) |
145 | for (var id in this.ids_) |
| 135 | { |
146 | { |
| 136 | if (this.ids_[id]) |
147 | if (this.ids_[id] && typeof this.ids_[id] != 'function') |
| 137 | { |
148 | { |
| 138 | ids[ids.length] = id; |
149 | ids[ids.length] = id; |
| 139 | } |
150 | } |
| 140 | } |
151 | } |
| 141 | 152 | ||
| 142 | return ids; |
153 | return ids; |
| - | 154 | } |
|
| - | 155 | ||
| - | 156 | Module.prototype.GetAvailableNames = function() |
|
| - | 157 | { |
|
| - | 158 | var result = new Array(); |
|
| - | 159 | var available_ids = this.GetAvailableIds(); |
|
| - | 160 | ||
| - | 161 | for (var alias in module_aliases) |
|
| - | 162 | { |
|
| - | 163 | if (module_aliases[alias]["is_group"]) |
|
| - | 164 | { |
|
| - | 165 | for (var n = 0; n < module_aliases[alias]["aliases"].length; n++) |
|
| - | 166 | { |
|
| - | 167 | var group_alias = module_aliases[alias]["aliases"][n]; |
|
| - | 168 | ||
| - | 169 | if (module_aliases[group_alias]["module_name"] == this.name_ && available_ids.contains(module_aliases[group_alias]["module_id"])) |
|
| - | 170 | { |
|
| - | 171 | result.push(alias); |
|
| - | 172 | break; |
|
| - | 173 | } |
|
| - | 174 | } |
|
| - | 175 | } |
|
| - | 176 | else |
|
| - | 177 | { |
|
| - | 178 | if (module_aliases[alias]["module_name"] == this.name_ && available_ids.contains(module_aliases[alias]["module_id"])) |
|
| - | 179 | { |
|
| - | 180 | result.push(alias); |
|
| - | 181 | } |
|
| - | 182 | } |
|
| - | 183 | } |
|
| - | 184 | ||
| - | 185 | return result; |
|
| 143 | } |
186 | } |
| 144 | 187 | ||
| 145 | Module.prototype.IsAvailable = function(id) |
188 | Module.prototype.IsAvailable = function(id) |
| 146 | { |
189 | { |
| 147 | if (typeof this.ids_[id] == 'undefined' || this.ids_[id] == false) |
190 | if (typeof this.ids_[id] == 'undefined' || this.ids_[id] == false) |