2011-01-19 18:42:40 +00:00
|
|
|
##
|
|
|
|
## environment.nas
|
|
|
|
##
|
|
|
|
## Nasal code for implementing environment-specific functionality.
|
|
|
|
|
|
|
|
##
|
|
|
|
# Handler. Increase visibility by one step
|
|
|
|
#
|
|
|
|
var increaseVisibility = func {
|
|
|
|
adjustVisibility(1.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
##
|
|
|
|
# Handler. Decrease visibility by one step
|
|
|
|
#
|
|
|
|
var decreaseVisibility = func {
|
|
|
|
adjustVisibility(0.9);
|
|
|
|
}
|
|
|
|
|
|
|
|
var adjustVisibility = func( factor ) {
|
2013-03-02 19:32:46 +00:00
|
|
|
var val = 0;
|
|
|
|
var aux_val = 0;
|
2014-01-01 21:49:17 +00:00
|
|
|
# better to use a non gui/dialog property here, but there doesn't
|
|
|
|
# seem to be one for local-weather.
|
|
|
|
var localWeatherEnabled = getprop("sim/gui/dialogs/metar/mode/local-weather");
|
2013-03-02 19:32:46 +00:00
|
|
|
var max_aux_vis = 12.429216196;
|
|
|
|
var min_aux_vis = 9.90348;
|
|
|
|
|
2014-01-01 21:49:17 +00:00
|
|
|
if (localWeatherEnabled) {
|
2013-03-02 19:32:46 +00:00
|
|
|
if (factor == 1.1)
|
|
|
|
factor = 1.001;
|
|
|
|
else
|
|
|
|
factor = 0.999;
|
|
|
|
|
|
|
|
aux_val = auxvisibilityProp.getValue() * factor;
|
|
|
|
|
|
|
|
if( aux_val <= min_aux_vis)
|
|
|
|
auxvisibilityProp.setDoubleValue(min_aux_vis);
|
|
|
|
elsif(aux_val >= max_aux_vis)
|
|
|
|
auxvisibilityProp.setDoubleValue(max_aux_vis);
|
|
|
|
else
|
|
|
|
auxvisibilityProp.setDoubleValue(aux_val);
|
|
|
|
|
|
|
|
gui.popupTip(sprintf("Max Visibility: %.0f m", getprop("/local-weather/config/max-vis-range-m")));
|
2014-01-01 21:49:17 +00:00
|
|
|
} else {
|
|
|
|
val = visibilityProp.getValue() * factor;
|
|
|
|
|
|
|
|
if( val < 1.0 ) val = getprop("/environment/visibility-m");
|
|
|
|
|
|
|
|
if( val > 30 ) {
|
|
|
|
visibilityProp.setDoubleValue(val);
|
|
|
|
visibilityOverrideProp.setBoolValue(1);
|
|
|
|
}
|
2013-03-02 19:32:46 +00:00
|
|
|
|
2014-01-01 21:49:17 +00:00
|
|
|
gui.popupTip(sprintf("Visibility: %.0f m", val));
|
2013-03-02 19:32:46 +00:00
|
|
|
}
|
2014-01-01 21:49:17 +00:00
|
|
|
}
|
2011-01-19 18:42:40 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Handler. Reset visibility to default.
|
|
|
|
#
|
|
|
|
var resetVisibility = func {
|
|
|
|
visibilityProp.setDoubleValue(0);
|
|
|
|
visibilityOverrideProp.setBoolValue(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var visibilityProp = nil;
|
|
|
|
var visibilityOverrideProp = nil;
|
2013-03-02 19:32:46 +00:00
|
|
|
var auxvisibilityProp = nil;
|
2011-01-19 18:42:40 +00:00
|
|
|
|
|
|
|
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
|
|
|
visibilityProp = props.globals.initNode("/environment/config/presets/visibility-m", 0, "DOUBLE" );
|
|
|
|
visibilityOverrideProp = props.globals.initNode("/environment/config/presets/visibility-m-override", 0, "BOOL" );
|
2013-03-02 19:32:46 +00:00
|
|
|
auxvisibilityProp = props.globals.initNode("/local-weather/config/aux-max-vis-range-m", 0, "DOUBLE" );
|
2011-01-19 18:42:40 +00:00
|
|
|
});
|