Rev 1614 | Rev 1624 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1614 | Rev 1619 | ||
|---|---|---|---|
| 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 | } |
- | |
| 14 | 3 | ||
| 15 | function GetModule(name) |
4 | function GetModule(name) |
| 16 | { |
5 | { |
| 17 | if (typeof modules[name] == 'undefined') |
6 | if (typeof modules[name] == 'undefined') |
| 18 | { |
7 | { |
| Line 20... | Line 9... | ||
| 20 | 9 | ||
| 21 | if (eval("typeof " + name + " != 'function'")) |
10 | if (eval("typeof " + name + " != 'function'")) |
| 22 | { |
11 | { |
| 23 | Log("Failed to load " + name + " module."); |
12 | Log("Failed to load " + name + " module."); |
| 24 | return; |
13 | return; |
| 25 | } |
14 | } |
| 26 | 15 | ||
| 27 | modules[name] = eval("(new " + name + "('" + name + "'))"); |
16 | modules[name] = eval("(new " + name + "('" + name + "'))"); |
| 28 | } |
17 | } |
| 29 | 18 | ||
| 30 | return modules[name]; |
19 | return modules[name]; |
| 31 | } |
20 | } |
| 32 | 21 | ||
| 33 | function Module_OnChange(full_id, available) |
22 | function Module_OnChange(full_id, available) |
| 34 | { |
23 | { |
| 35 | var parts = full_id.split(":", 2); |
24 | var parts = full_id.split(":", 2); |
| 36 | 25 | ||
| 37 | if (global_legacy) |
26 | if (global_legacy) |
| 38 | { |
27 | { |
| 39 | legacyOnState(full_id, parts[1], parts[0], available); |
28 | legacyOnState(full_id, parts[1], parts[0], available); |
| 40 | return; |
29 | return; |
| 41 | } |
30 | } |
| 42 | 31 | ||
| 43 | var module = GetModule(parts[0]); |
32 | var module = GetModule(parts[0]); |
| 44 | 33 | ||
| 45 | if (module) |
34 | if (module) |
| 46 | { |
35 | { |
| 47 | module.SetStatus(parts[1], available); |
36 | module.SetStatus(parts[1], available); |
| 48 | } |
37 | } |
| 49 | } |
38 | } |
| 50 | 39 | ||
| 51 | function Module_OnMessage() |
40 | function Module_OnMessage() |
| 52 | { |
41 | { |
| 53 | var full_id = arguments[0]; |
42 | var full_id = arguments[0]; |
| 54 | var command = arguments[1]; |
43 | var command = arguments[1]; |
| 55 | var |
44 | var variables = arguments[2]; |
| 56 | - | ||
| 57 | var variables = new Array(); |
- | |
| 58 | 45 | ||
| 59 | for (var i = 3; i < number_of_variables * 2 + 3; i += 2) |
- | |
| 60 | { |
- | |
| 61 | variables[arguments[i]] = arguments[i + 1]; |
- | |
| 62 | } |
- | |
| 63 | - | ||
| 64 | variables.length = number_of_variables; |
- | |
| 65 | - | ||
| 66 | var parts = full_id.split(":", 2); |
46 | var parts = full_id.split(":", 2); |
| 67 | 47 | ||
| 68 | if (global_legacy) |
48 | if (global_legacy) |
| 69 | { |
49 | { |
| 70 | legacyOnMessage(full_id, parts[1], parts[0], command, variables); |
50 | legacyOnMessage(full_id, parts[1], parts[0], command, variables); |
| 71 | return; |
51 | return; |
| 72 | } |
52 | } |
| 73 | - | ||
| 74 | 53 | ||
| 75 | var module = GetModule(parts[0]); |
54 | var module = GetModule(parts[0]); |
| 76 | 55 | ||
| 77 | if (module) |
56 | if (module) |
| 78 | { |
57 | { |
| 79 | module.ReceiveMessage(parts[1], command, variables); |
58 | module.ReceiveMessage(parts[1], command, variables); |
| 80 | } |
59 | } |
| 81 | else |
60 | else |
| Line 139... | Line 118... | ||
| 139 | } |
118 | } |
| 140 | 119 | ||
| 141 | Module.prototype.GetAvailableIds = function() |
120 | Module.prototype.GetAvailableIds = function() |
| 142 | { |
121 | { |
| 143 | var ids = new Array(); |
122 | var ids = new Array(); |
| 144 | 123 | ||
| 145 | for (var id in this.ids_) |
124 | for (var id in this.ids_) |
| 146 | { |
125 | { |
| 147 | if (this.ids_[id] && typeof this.ids_[id] != 'function') |
126 | if (this.ids_[id] && typeof this.ids_[id] != 'function') |
| 148 | { |
127 | { |
| 149 | ids[ids.length] = id; |
128 | ids[ids.length] = id; |
| 150 | } |
129 | } |
| 151 | } |
130 | } |
| 152 | 131 | ||
| 153 | return ids; |
132 | return ids; |
| 154 | } |
133 | } |
| 155 | 134 | ||
| 156 | Module.prototype.GetAvailableNames = function() |
135 | Module.prototype.GetAvailableNames = function() |
| 157 | { |
136 | { |
| 158 | var result = new Array(); |
137 | var result = new Array(); |
| 159 | var available_ids = this.GetAvailableIds(); |
138 | var available_ids = this.GetAvailableIds(); |
| - | 139 | ||
| - | 140 | var module_aliases = getaliases(); |
|
| 160 | 141 | ||
| 161 | for (var alias in module_aliases) |
142 | for (var alias in module_aliases) |
| 162 | { |
143 | { |
| 163 | if (module_aliases[alias]["is_group"]) |
144 | if (module_aliases[alias]["is_group"]) |
| 164 | { |
145 | { |
| 165 | for (var n = 0; n < module_aliases[alias]["aliases"].length; n++) |
146 | for (var n = 0; n < module_aliases[alias]["aliases"].length; n++) |
| 166 | { |
147 | { |
| 167 | var group_alias = module_aliases[alias]["aliases"][n]; |
148 | var group_alias = module_aliases[alias]["aliases"][n]; |
| 168 | 149 | ||
| 169 | if (module_aliases[group_alias]["module_name"] == this.name_ && |
150 | if (module_aliases[group_alias]["module_name"] == this.name_ && ArrayContains(available_ids, module_aliases[group_alias]["module_id"])) |
| 170 | { |
151 | { |
| 171 | result.push(alias); |
152 | result.push(alias); |
| 172 | break; |
153 | break; |
| 173 | } |
154 | } |
| 174 | } |
155 | } |
| 175 | } |
156 | } |
| 176 | else |
157 | else |
| 177 | { |
158 | { |
| 178 | if (module_aliases[alias]["module_name"] == this.name_ && |
159 | if (module_aliases[alias]["module_name"] == this.name_ && ArrayContains(available_ids, module_aliases[alias]["module_id"])) |
| 179 | { |
160 | { |
| 180 | result.push(alias); |
161 | result.push(alias); |
| 181 | } |
162 | } |
| 182 | } |
163 | } |
| 183 | } |
164 | } |