2011-01-17 20:05:01 +00:00
|
|
|
#
|
2011-05-30 15:21:31 +00:00
|
|
|
# find a weather scenario by it's <name> element
|
|
|
|
# returns /environment/weather-scenarios/scenario[name=$name]
|
|
|
|
#
|
|
|
|
find_weather_scenario = func(name) {
|
|
|
|
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
|
|
|
|
if( wsn == nil ) return nil;
|
|
|
|
var scenarios =
|
|
|
|
foreach (var scenario; wsn.getChildren("scenario") )
|
|
|
|
if( scenario.getNode("name").getValue() == name )
|
|
|
|
return scenario;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2011-01-17 20:05:01 +00:00
|
|
|
var initialize_weather_scenario = func {
|
2012-06-12 10:09:50 +00:00
|
|
|
getprop( "/environment/params/metar-updates-environment" ) == 0 and return;
|
|
|
|
getprop( "/environment/realwx/enabled" ) and return;
|
|
|
|
getprop( "/environment/metar/data" ) != "" and return;
|
2011-01-17 20:05:01 +00:00
|
|
|
|
|
|
|
# preset configured scenario
|
|
|
|
var scn = getprop("/environment/weather-scenario", "");
|
|
|
|
var wsn = props.globals.getNode( "/environment/weather-scenarios" );
|
|
|
|
if( wsn != nil ) {
|
|
|
|
var scenarios = wsn.getChildren("scenario");
|
|
|
|
forindex (var i; scenarios ) {
|
|
|
|
if( scenarios[i].getNode("name").getValue() == scn ) {
|
|
|
|
setprop("/environment/metar/data", scenarios[i].getNode("metar").getValue() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-05-30 15:21:31 +00:00
|
|
|
|
2020-05-30 19:55:28 +00:00
|
|
|
initialize_weather_scenario();
|
2011-05-30 15:21:31 +00:00
|
|
|
|
2020-05-30 19:55:28 +00:00
|
|
|
setlistener("/environment/weather-scenario", func(n) {
|
|
|
|
var scenario = find_weather_scenario( n.getValue() );
|
|
|
|
if( scenario == nil ) return;
|
|
|
|
var scenarioName = scenario.getNode("name",1).getValue();
|
|
|
|
if( scenarioName == "Disabled" ) {
|
|
|
|
setprop( "/environment/params/metar-updates-environment", 0 );
|
|
|
|
setprop( "/environment/realwx/enabled", 0 );
|
|
|
|
setprop( "/environment/config/enabled", 0 );
|
2023-09-16 13:37:07 +00:00
|
|
|
setprop( "/environment/atmosphere/is-isa", 0 );
|
2020-05-30 19:55:28 +00:00
|
|
|
} else if( scenarioName == "Live data" ) {
|
|
|
|
setprop( "/environment/params/metar-updates-environment", 1 );
|
|
|
|
setprop( "/environment/realwx/enabled", 1 );
|
|
|
|
setprop( "/environment/config/enabled", 1 );
|
2023-09-16 13:37:07 +00:00
|
|
|
setprop( "/environment/atmosphere/is-isa", 0 );
|
2020-05-30 19:55:28 +00:00
|
|
|
} else if( scenarioName == "Manual input" ) {
|
|
|
|
setprop( "/environment/params/metar-updates-environment", 1 );
|
|
|
|
setprop( "/environment/realwx/enabled", 0 );
|
|
|
|
setprop( "/environment/config/enabled", 1 );
|
2023-09-16 13:37:07 +00:00
|
|
|
setprop( "/environment/atmosphere/is-isa", 0 );
|
2020-05-30 19:55:28 +00:00
|
|
|
} else {
|
|
|
|
setprop( "/environment/params/metar-updates-environment", 1 );
|
|
|
|
setprop( "/environment/realwx/enabled", 0 );
|
|
|
|
setprop( "/environment/config/enabled", 1 );
|
|
|
|
var metar = scenario.getNode("metar",1).getValue();
|
|
|
|
setprop( "environment/metar/data", metar );
|
2023-07-21 22:52:07 +00:00
|
|
|
|
|
|
|
var isISA = scenarioName == "International Standard Atmosphere";
|
2023-09-16 13:37:07 +00:00
|
|
|
setprop( "/environment/atmosphere/is-isa", isISA );
|
2020-05-30 19:55:28 +00:00
|
|
|
}
|
2011-01-17 20:05:01 +00:00
|
|
|
});
|