| 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) return; |
| 7 |
var autoTutorials = props.globals.getNode("/sim/checklists/auto-tutorials"); |
| 8 |
if (autoTutorials != nil and !autoTutorials.getBoolValue()) return; |
| 9 |
|
| 10 |
var tutorials = props.globals.getNode("/sim/tutorials", 1); |
| 11 |
var groups = props.globals.getNode("/sim/checklists").getChildren("group"); |
| 12 |
var checklists = []; |
| 13 |
|
| 14 |
if (size(groups) > 0) { |
| 15 |
foreach (var grp; groups) { |
| 16 |
var allowed = grp.getNode("auto-tutorial"); |
| 17 |
if (allowed != nil and !allowed.getBoolValue()) continue; |
| 18 |
|
| 19 |
var checks = grp.getChildren("checklist"); |
| 20 |
foreach (var chk; checks) { |
| 21 |
append(checklists, chk); |
| 22 |
} |
| 23 |
} |
| 24 |
} else { |
| 25 |
checklists = props.globals.getNode("/sim/checklists").getChildren("checklist"); |
| 26 |
} |
| 27 |
|
| 28 |
if (size(checklists) == 0) return; |
| 29 |
foreach (var ch; checklists) { |
| 30 |
var name = ch.getNode("title", 1).getValue(); |
| 31 |
|
| 32 |
var allowed = ch.getNode("auto-tutorial"); |
| 33 |
if (allowed != nil and !allowed.getBoolValue()) continue; |
| 34 |
|
| 35 |
var tutorial = tutorials.addChild("tutorial"); |
| 36 |
|
| 37 |
# Initial high level config |
| 38 |
tutorial.getNode("name", 1).setValue("Checklist: " ~ name); |
| 39 |
var description = |
| 40 |
"Tutorial to run through the " ~ |
| 41 |
name ~ |
| 42 |
" checklist.\n\nChecklist available through the Help->Checklists menu.\n\n"; |
| 43 |
|
| 44 |
var step = tutorial.getNode("step", 1); |
| 45 |
step.getNode("message", 1).setValue("Checklist: " ~ name); |
| 46 |
|
| 47 |
# Now go through each of the checklist items and generate a tutorial step |
| 48 |
# for each. |
| 49 |
|
| 50 |
# Checklist may consist of one or more pages. |
| 51 |
var pages = ch.getChildren("page"); |
| 52 |
|
| 53 |
if (size(pages) == 0) { |
| 54 |
# Or no pages at all, in which case we need to create a checklist of one page |
| 55 |
append(pages, ch); |
| 56 |
} |
| 57 |
|
| 58 |
foreach (var page; pages) { |
| 59 |
foreach (var item; page.getChildren("item")) { |
| 60 |
step = tutorial.getNode("step["~ size(tutorial.getChildren("step")) ~ "]", 1); |
| 61 |
|
| 62 |
var msg = item.getNode("name", 1).getValue(); |
| 63 |
|
| 64 |
if (size(item.getChildren("value")) > 0) { |
| 65 |
msg = msg ~ " :"; |
| 66 |
foreach (var v; item.getChildren("value")) { |
| 67 |
msg = msg ~ " " ~ v.getValue(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
step.getNode("message", 1).setValue(msg); |
| 72 |
description = description ~ msg ~ "\n"; |
| 73 |
|
| 74 |
if (item.getNode("condition") != nil) { |
| 75 |
var cond = step.getNode("exit", 1).getNode("condition", 1); |
| 76 |
props.copy(item.getNode("condition"), cond); |
| 77 |
} |
| 78 |
|
| 79 |
if (item.getNode("marker") != nil) { |
| 80 |
var marker= step.getNode("marker", 1); |
| 81 |
props.copy(item.getNode("marker"), marker); |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
tutorial.getNode("description", 1).setValue(description); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
convert_checklists(); |