· 6 years ago · Jun 26, 2019, 10:09 PM
1'use strict';
2
3function setup(args, ctx){
4
5 /*
6
7
8
9
10 !!! This script handles setting up element creation, and simplifies the process greatly. Simply add your elements and elementgroups to the lists !!!
11
12 You can call an element from lex or a speech file by using the following commands:
13
14 Displaying an Element:
15 <mark name="showElement:elementName"/>
16
17 Hiding an Element:
18 <mark name="hideElement:elementName"/>
19
20 Showing an Element Group:
21 <mark name="showGroup:groupName"/>
22
23 Hiding an Element Group:
24 <mark name="hideGroup:groupName"/>
25
26 Hiding all non stickied groups:
27 <mark name="hideGroups"/>
28
29 Elements are UI things that need animation. Outlines, tables, etc, go here.
30 This is where we setup shorthand for speech to call, or for another function to call, without us having to put a whole element summon in a speech file.
31 Use the default options as examples to expand upon.
32 Use sEmit for a sumerian emit, and emit for an amplify emit. You can have both.
33
34
35 * Button Types:
36 Here is a list of all button types we can adjust. This should account for any button in the scene
37 All buttons should be modular and allow for any value, with the exception of *maybe* start and stop listening. That may change.
38
39 Each of these is structured like this
40 - id : Description. When you're creating a button, the id of the type is the only thing you should worry about.
41
42 - $ at beginning of emit means it will send to the sumerian system bus instead of the amplify hub.
43
44 = Top Bar Buttons = (These probably won't need to be changed from defaults, but who knows)
45 - assist : Assist
46 - addison : Addison
47 - listen : Stop Listening / Start Listening (Probably not modular, hardcoded)
48 - tertiary : Tertiary / button on top. Used primarily for testing.
49
50 = Three Button Sidebar =
51 - sBtn1 : Sidebar Button 1
52 - sBtn2 : Sidebar Button 2
53 - sBtn3 : Sidebar Button 3
54
55 = Yes / No Sidebar =
56 - sYes : Sidebar Yes
57 - sNo : Sidebar No
58
59 = Sidebar Other =
60 - sDone : Sidebar Done
61 - sReady : Sidebar Ready (The one with the flag?)
62
63
64 * Element Types
65 Elements are functionally the same as buttons, but do not use any onclick events. This may be graphs, tables, graphics, titles, etc.
66
67 = Tables =
68 - mTable : Medical Table. Used for most tables / Lists
69 - scatterChart : Scatter Chart, default addison scatter chart.
70
71 **************************************************************************************
72 * *
73 * Elements *
74 * *
75 **************************************************************************************/
76
77 ctx.elements = {
78 //Top Bar
79 assist : {text: "Assist", type:"assist", emit:"assist"},
80 addison : {text: "Addison", type:"addison", sEmit:"activeListen", delay:"50"},
81 listen : {text: "", type:"listen", emit:"listen"},
82 reload : {text: "Reload", type:"tertiary", emit:"reload", delay:"100"},
83
84 sampleButton1 : {text: "Button 1", type:"sBtn1", sEmit:"post_to_lex:button 1", id:"btn1"}, //Blood pressure select
85 sampleButton2 : {text: "Button 2", type:"sBtn2", sEmit:"post_to_lex:button 2", id:"btn2"}, //Blood pressure select
86
87 sampleVideo : {type:"fullscreenVideo", link:"https://addison-project-anim-files.s3.amazonaws.com/Videos/VitalsTutorials/BPTutorial_v01.mp4"},
88
89 }
90
91
92
93 /**************************************************************************************
94 * *
95 * Element Groups *
96 * *
97 **************************************************************************************
98
99 Element groups.
100 This allows us to create, say, one group for the top bar, and hide and show that as it's own thing. */
101
102 ctx.groups = {
103 topBar : {elements : ["assist", "addison", "listen", "reload"], stick : true},
104 exampleSidebar : {elements : ["sampleButton1", "sampleButton2"]},
105 }
106
107
108 //The currently active groups, used for removing groups.
109 ctx.currentGroups = [];
110 //The current 'Screen', aka the current group that is open.
111 ctx.currentScreen;
112
113
114 /**************************************************************************************
115 * *
116 * Core Setup Functionality *
117 * *
118 **************************************************************************************/
119
120 /********************************************************************************
121 Enable Element Function - Pass an element name and it will enable that element
122 *********************************************************************************/
123 ctx.showElementFunc = function(elm){
124
125 //Here is where we add custom whatevers for element showing. Most should not use this.
126 if(elm == "custom"){
127 if(ctx.elements[elm] != null) // If the element exists in our element definition.
128 {
129
130 }
131 } else {
132 if(ctx.elements[elm] != null) // If the element exists in our element definition.
133 {
134
135 let payload = {};
136 payload.elements = [];
137 payload.elements.push(ctx.elements[elm]);
138 sumerian.SystemBus.emit("showAmplifyElement", payload);
139 }
140 else // Otherwise, error out. Make sure that the element exists in ctx.elements above!
141 {
142 console.error("Trying to create element '" + elm + "' not listed in JS_SceneElements");
143 return;
144 }
145 }
146
147 };
148
149 /********************************************************************************
150 Disable Element Function - Pass an element name and it will disable that element
151 *********************************************************************************/
152 ctx.hideElementFunc = function(elm){
153 console.log("hiding element");
154 if(elm == "Custom") // If the element exists in our element definition.
155 {
156
157 } else {
158 if(ctx.elements[elm] != null) // If the element exists in our element definition.
159 {
160 let payload = {};
161 payload.elements = [];
162 payload.elements.push(ctx.elements[elm]);
163 sumerian.SystemBus.emit("hideAmplifyElement", payload);
164 }
165 else // Otherwise, error out. Make sure that the element exists in ctx.elements above!
166 {
167 console.error("Trying to create element '" + elm + "' not listed in JS_SceneElements");
168 return;
169 }
170 }
171
172 };
173
174
175 /********************************************************************************
176 Reload Element Function - Pass an element name and it will reload that element
177 *********************************************************************************/
178 ctx.reloadElementFunc = function(elm){
179
180 if(ctx.elements[elm] != null) // If the element exists in our element definition.
181 {
182
183 let payload = {};
184 payload.elements = [];
185 payload.elements.push(ctx.elements[elm]);
186 payload.reload = true;
187 sumerian.SystemBus.emit("showAmplifyElement", payload);
188 }
189 else // Otherwise, error out. Make sure that the element exists in ctx.elements above!
190 {
191 console.error("Trying to reload element '" + elm + "' not listed in JS_SceneElements");
192 return;
193 }
194
195 };
196
197 /*************************************************************************************
198 Show Group Function - Pass a group name and it will show any elements in that group.
199 **************************************************************************************/
200 ctx.showGroupFunc = function(grp){
201
202 //Here is where we add custom groupings for vitals.
203 if(ctx.groups[grp] != null) // If the element exists in our element definition.
204 {
205 console.log("Showing Group " + grp);
206 //Iterate through every element in that group.
207 for(let i = 0; i < ctx.groups[grp].elements.length; i++){
208 let elm = ctx.groups[grp].elements[i];
209
210 if(ctx.elements[elm] != null){
211 let payload = {};
212 payload.elements = [];
213 payload.elements.push(ctx.elements[elm]);
214 sumerian.SystemBus.emit("showAmplifyElement", payload);
215 } else {
216 console.error("Element '" + elm + "'listed in group '"+ grp + "' does not exist.");
217 }
218 }
219
220 ctx.currentGroups.push(grp);
221 ctx.currentScreen = grp;
222 }
223 else // Otherwise, error out. Make sure that the element exists in ctx.elements above!
224 {
225 console.error("Trying to create group not listed in JS_SceneElements");
226 return;
227 }
228 };
229
230 /*************************************************************************************
231 Hide Group Function - Pass a group name and it will hide any elements in that group.
232 **************************************************************************************/
233 ctx.hideGroupFunc = function(grp){
234
235 //Here is where we add custom groupings for vitals.
236 if(ctx.groups[grp] != null) // If the element exists in our element definition.
237 {
238
239 //Iterate through every element in that group.
240 for(let i = 0; i < ctx.groups[grp].elements.length; i++){
241 let elm = ctx.groups[grp].elements[i];
242
243 if(ctx.elements[elm] != null){
244 let payload = {};
245 payload.elements = [];
246 payload.elements.push(ctx.elements[elm]);
247 sumerian.SystemBus.emit("hideAmplifyElement", payload);
248 } else {
249 console.error("Removing Element '" + elm + "'listed in group '"+ grp + "' does not exist.");
250 }
251 }
252
253 //Remove the group from currentgroups.
254 for( var i = 0; i < ctx.currentGroups.length; i++){
255 if ( ctx.currentGroups[i] === grp) {
256 ctx.currentGroups.splice(i, 1);
257 }
258 }
259 }
260 else // Otherwise, error out. Make sure that the element exists in ctx.elements above!
261 {
262 console.error("Trying to remove group not listed in JS_SceneElements");
263 return;
264 }
265 };
266
267 //Hide all non sticky groups. Used for removing whatever is currently open.
268 ctx.hideAllNonStickyGroups = function(grp){
269 for(let i = 0; i < ctx.currentGroups.length; i++){
270 if(ctx.groups[ctx.currentGroups[i]].stick == null){
271 ctx.hideGroupFunc(ctx.currentGroups[i]);
272 }
273 }
274 }
275
276 //Create the topbar at the beginning of the scene.
277 ctx.showGroupFunc("topBar");
278
279 //Listener setup
280 sumerian.SystemBus.addListener('showElement', ctx.showElementFunc, true);
281 sumerian.SystemBus.addListener('hideElement', ctx.hideElementFunc, true);
282
283 sumerian.SystemBus.addListener('showGroup', ctx.showGroupFunc, true);
284 sumerian.SystemBus.addListener('hideGroup', ctx.hideGroupFunc, true);
285
286 sumerian.SystemBus.addListener('hideAllGroups', ctx.hideAllNonStickyGroups, true);
287}
288
289
290
291// Called when play mode stops.
292//
293function cleanup(args, ctx) {
294 sumerian.SystemBus.removeAllOnChannel('showElement');
295 sumerian.SystemBus.removeAllOnChannel('hideElement');
296 sumerian.SystemBus.removeAllOnChannel('showGroup');
297
298 sumerian.SystemBus.removeAllOnChannel('hideGroup');
299
300 sumerian.SystemBus.removeAllOnChannel('hideAllGroups');
301
302 sumerian.SystemBus.removeAllOnChannel('setVitalGraph');
303
304}
305
306// Defines script parameters.
307//
308var parameters = [];