Fix bug #280. Allow setting of weather-scenario at runtime
Add a listener to /environment/weather-scenario to allow setting the scenario at runtime. Need some cleanup of the global weather dialog to remove duplicate code.
This commit is contained in:
parent
e1b82c3a3a
commit
bef8f1fc6e
1 changed files with 39 additions and 3 deletions
|
@ -1,6 +1,17 @@
|
|||
# Set the global weather according to the defined
|
||||
# scenario in /environment/weather-scenario
|
||||
#
|
||||
# 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;
|
||||
}
|
||||
|
||||
var initialize_weather_scenario = func {
|
||||
getprop( "/environment/params/metar-updates-environment", 0 ) == 0 and return;
|
||||
getprop( "/environment/realwx/enabled", 0 ) and return;
|
||||
|
@ -21,7 +32,32 @@ var initialize_weather_scenario = func {
|
|||
};
|
||||
|
||||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
|
||||
initialize_weather_scenario();
|
||||
delete(globals, "weather_scenario");
|
||||
|
||||
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 );
|
||||
} else if( scenarioName == "Live data" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 1 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} else if( scenarioName == "Manual input" ) {
|
||||
setprop( "/environment/params/metar-updates-environment", 1 );
|
||||
setprop( "/environment/realwx/enabled", 0 );
|
||||
setprop( "/environment/config/enabled", 1 );
|
||||
} 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 );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue