Phi: nicer scroll animation for METAR widget
[fg:fgdata.git] / Nasal / checklist.nas
1 # Nasal functions for handling the checklists present under /sim/checklists
2
3 # Convert checklists into full tutorials.
4 var convert_checklists = func {
5
6   if ((props.globals.getNode("/sim/checklists") != nil)                            and 
7       (props.globals.getNode("/sim/checklists").getChildren("checklist") != nil)   and
8       (size(props.globals.getNode("/sim/checklists").getChildren("checklist")) > 0)    )
9   {
10     var checklists = props.globals.getNode("/sim/checklists").getChildren("checklist");
11     var tutorials = props.globals.getNode("/sim/tutorials", 1);
12
13     foreach (var ch; checklists) {
14       var name = ch.getNode("title", 1).getValue();
15       var tutorial = tutorials.getNode("tutorial[" ~ size(tutorials.getChildren("tutorial")) ~ "]", 1);
16
17       # Initial high level config
18       tutorial.getNode("name", 1).setValue("Checklist: " ~ name);
19       var description = 
20         "Tutorial to run through the " ~ 
21         name ~ 
22         " checklist.\n\nChecklist available through the Help->Checklists menu.\n\n";
23         
24       var step = tutorial.getNode("step", 1);
25       step.getNode("message", 1).setValue("Checklist: " ~ name);    
26         
27       # Now go through each of the checklist items and generate a tutorial step 
28       # for each.
29           
30                         # Checklist may consist of one or more pages.
31                         var pages = ch.getChildren("page");
32                         
33                         if (size(pages) == 0) {
34                                 # Or no pages at all, in which case we need to create a checklist of one page
35                                 append(pages, ch);
36                         }
37                         
38                         foreach (var page; pages) {
39                                 foreach (var item; page.getChildren("item")) {
40                                         step = tutorial.getNode("step["~ size(tutorial.getChildren("step")) ~ "]", 1);
41                                         
42                                         var msg = item.getNode("name", 1).getValue();
43                                         
44                                         if (size(item.getChildren("value")) > 0) {
45                                                 msg = msg ~ " :";
46                                                 foreach (var v; item.getChildren("value")) {
47                                                         msg = msg ~ " " ~ v.getValue();
48                                                 }
49                                         }
50                                                                 
51                                         step.getNode("message", 1).setValue(msg);        
52                                         description = description ~ msg ~ "\n";
53                                         
54                                         if (item.getNode("condition") != nil) {
55                                                 var cond = step.getNode("exit", 1).getNode("condition", 1);
56                                                 props.copy(item.getNode("condition"), cond);
57                                         }      
58                                         
59                                         if (item.getNode("marker") != nil) {
60                                                 var marker= step.getNode("marker", 1);
61                                                 props.copy(item.getNode("marker"), marker);
62                                         }      
63                                         
64                                 }
65                         }
66       
67       tutorial.getNode("description", 1).setValue(description);    
68     }
69   }
70 }
71
72 _setlistener("/sim/signals/nasal-dir-initialized", func {
73   convert_checklists();
74 });