1
0
Fork 0

Nasal fixes for unit testing

Tolerate missing properties in various places, since defaults and 
other subsystems might not have created them.
This commit is contained in:
James Turner 2019-09-18 15:00:00 +01:00
parent 9965d6a674
commit 0172ef9d08
3 changed files with 13 additions and 8 deletions

View file

@ -22,7 +22,11 @@ var showDialog = func(name) {
# Enable/disable named menu entry
#
var menuEnable = func(searchname, state) {
foreach (var menu; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
var menubar = props.globals.getNode("/sim/menubar/default");
if (menubar == nil)
return;
foreach (var menu; menubar.getChildren("menu")) {
foreach (var name; menu.getChildren("name")) {
if (name.getValue() == searchname) {
menu.getNode("enabled").setBoolValue(state);
@ -142,7 +146,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
return 1;
}
menuEnable("autopilot", isAutopilotMenuEnabled() );
menuEnable("joystick-info", size(props.globals.getNode("/input/joysticks").getChildren("js")));
menuEnable("joystick-info", size(props.globals.getNode("/input/joysticks", 1).getChildren("js")));
menuEnable("rendering-buffers", getprop("/sim/rendering/rembrandt/enabled"));
menuEnable("rembrandt-buffers-choice", getprop("/sim/rendering/rembrandt/enabled"));
menuEnable("stereoscopic-options", !getprop("/sim/rendering/rembrandt/enabled"));
@ -173,7 +177,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
var p = "/sim/rendering/precipitation-";
var precip_gui = getprop(p ~ "gui-enable");
var precip_ac = getprop(p ~ "aircraft-enable");
props.globals.getNode(p ~ "enable").setAttribute("userarchive", 0); # TODO remove later
props.globals.getNode(p ~ "enable", 1).setAttribute("userarchive", 0); # TODO remove later
var set_precip = func setprop(p ~ "enable", precip_gui and precip_ac);
setlistener(p ~ "gui-enable", func(n) set_precip(precip_gui = n.getValue()),1);
setlistener(p ~ "aircraft-enable", func(n) set_precip(precip_ac = n.getValue()),1);
@ -1470,7 +1474,7 @@ elsif (qualityLevel != nil) {
# in the Rendering Options dialog
var update_shader_settings = func() {
if (!getprop("/sim/rendering/shaders/custom-settings")){
var qualityLvl = getprop("/sim/rendering/shaders/quality-level-internal");
var qualityLvl = getprop("/sim/rendering/shaders/quality-level-internal") or 0;
setprop("/sim/rendering/shaders/quality-level", qualityLvl);
setprop("/sim/rendering/shaders/landmass",qualityLvl);
setprop("/sim/rendering/shaders/urban",qualityLvl);

View file

@ -935,8 +935,8 @@ var screenWidthCompens = {
_setlistener("/sim/signals/nasal-dir-initialized", func {
views = props.globals.getNode("/sim").getChildren("view");
fovProp = props.globals.getNode("/sim/current-view/field-of-view");
views = props.globals.getNode("/sim", 1).getChildren("view");
fovProp = props.globals.getNode("/sim/current-view/field-of-view", 1);
point.init();
setlistener("/sim/current-view/view-number", func(n) {

View file

@ -9,8 +9,9 @@ var windsock = func {
var wind = getprop("/environment/wind-speed-kt") or 0;
var mag1 = getprop("/environment/turbulence/magnitude-norm") or 0;
var mag2 = getprop("/environment/turbulence/raw-magnitude-norm") or 0;
var sens = getprop("/environment/turbulence/sensitivity") or 0;
var rate = 3.1514*getprop("/environment/turbulence/rate-hz") or 0;
var sens = getprop("/environment/turbulence/sensitivity") or 1.0;
var rateHz = getprop("/environment/turbulence/rate-hz") or 0;
var rate = 3.1514 * rateHz;
var tot1 = math.sin(dt*rate)*mag1*mag1;
var tot2 = math.sin(3.33*dt*rate/sens)*sens*mag2*mag2;
tot2 = mag2*tot2 + (1-mag2)*math.tan(dt/10)/5;