1
0
Fork 0

setlistener(): accessing the node via cmdarg() is now depreciated. Use

a regular function argument for that. Note the "n" in this example:

   setlistener("/sim/current-view/view-number", func(n) {
       setprop("/sim/hud/visibility", !n.getValue());
   }, 1);
This commit is contained in:
mfranz 2007-10-15 18:27:42 +00:00
parent 12c11dfa6f
commit 2bcddab9b6
9 changed files with 42 additions and 43 deletions

View file

@ -399,7 +399,7 @@ var data = {
me.loopid = 0;
me.interval = 0;
setlistener("/sim/signals/reinit", func { cmdarg().getBoolValue() and me._save_() });
setlistener("/sim/signals/reinit", func(n) { n.getBoolValue() and me._save_() });
setlistener("/sim/signals/exit", func { me._save_() });
},
load : func {
@ -652,9 +652,9 @@ var steering = {
call(func(v, w) (w < 0 ? leftN : w > 0 ? rightN : switchN).setValue(v),
[v, w], nil, aircraft.steering);
}
setlistener(me.switchN, func {
setlistener(me.switchN, func(n) {
me.loopid += 1;
if (cmdarg().getValue())
if (n.getValue())
me._loop_(me.loopid);
else
me.setbrakes(0, 0);

View file

@ -273,8 +273,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
ghosttypes[ghosttype(props._globals())] = "PropertyNode";
ghosttypes[ghosttype(io.stderr)] = "FileHandle";
setlistener("/sim/startup/terminal-ansi-colors", func {
color(cmdarg().getBoolValue());
setlistener("/sim/startup/terminal-ansi-colors", func(n) {
color(n.getBoolValue());
}, 1);
});

View file

@ -401,18 +401,18 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
# let listeners keep some variables up-to-date, so that they don't have
# to be queried in the loop
setlistener("/sim/panel/visibility", func { panel_visible = cmdarg().getValue() }, 1);
setlistener("/sim/current-view/view-number", func { cockpit_view = enabled[cmdarg().getValue()] }, 1);
setlistener("/devices/status/mice/mouse/button", func { mouse_button = cmdarg().getValue() }, 1);
setlistener("/sim/panel/visibility", func(n) { panel_visible = n.getValue() }, 1);
setlistener("/sim/current-view/view-number", func(n) { cockpit_view = enabled[n.getValue()] }, 1);
setlistener("/devices/status/mice/mouse/button", func(n) { mouse_button = n.getValue() }, 1);
setlistener("/devices/status/mice/mouse/x", freeze);
setlistener("/devices/status/mice/mouse/y", freeze);
setlistener("/devices/status/mice/mouse/mode", func {
if (mouse_mode = cmdarg().getValue())
setlistener("/devices/status/mice/mouse/mode", func(n) {
if (mouse_mode = n.getValue())
view_manager.unfreeze();
}, 1);
setlistener("/sim/signals/reinit", func {
cmdarg().getValue() and return;
setlistener("/sim/signals/reinit", func(n) {
n.getValue() and return;
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
view_manager.reset();
}, 0);
@ -427,8 +427,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
}
settimer(func {
setlistener("/sim/view/dynamic/enabled", func {
dynamic_view = cmdarg().getBoolValue();
setlistener("/sim/view/dynamic/enabled", func(n) {
dynamic_view = n.getBoolValue();
loop_id += 1;
view.resetView();
if (dynamic_view)

View file

@ -104,7 +104,7 @@ var total_norm = nil;
_setlistener("/sim/signals/fdm-initialized", func {
setlistener("/sim/freeze/fuel", func { fuel_freeze = cmdarg().getBoolValue() }, 1);
setlistener("/sim/freeze/fuel", func(n) { fuel_freeze = n.getBoolValue() }, 1);
total_gals = props.globals.getNode("/consumables/fuel/total-fuel-gals", 1);
total_lbs = props.globals.getNode("/consumables/fuel/total-fuel-lbs", 1);

View file

@ -70,7 +70,6 @@ var interpolate = func(node, val...) {
#
var setlistener = func(node, fun, init=0, runtime=1) {
if(isa(node, props.Node)) node = node._g;
var propghost = ghosttype(node);
var id = _setlistener(node, func {
arg[0] = props.wrapNode(arg[0], nil);
arg[1] = props.wrapNode(arg[1], nil);

View file

@ -242,7 +242,7 @@ Dialog = {
#
# SYNOPSIS: FileSelector.new(<callback>, <title>, <button> [, <pattern> [, <dir> [, <file> [, <dotfiles>]]]])
#
# callback ... callback function that gets return value as cmdarg().getValue()
# callback ... callback function that gets return value as first argument
# title ... dialog title
# button ... button text (should say "Save", "Load", etc. and not just "OK")
# pattern ... array with shell pattern or nil (which is equivalent to "*")
@ -252,7 +252,7 @@ Dialog = {
#
# EXAMPLE:
#
# var report = func { print("file ", cmdarg().getValue(), " selected") }
# var report = func(n) { print("file ", n.getValue(), " selected") }
# var selector = gui.FileSelector.new(
# report, # callback function
# "Save Flight", # dialog title
@ -437,7 +437,7 @@ var setWeightOpts = func {
}
# Run it at startup and on reset to make sure the tank settings are correct
_setlistener("/sim/signals/fdm-initialized", func { settimer(setWeightOpts, 0) });
_setlistener("/sim/signals/reset", func { cmdarg().getBoolValue() or setWeightOpts() });
_setlistener("/sim/signals/reset", func(n) { n.getBoolValue() or setWeightOpts() });
# Called from the F&W dialog when the user selects a weight option

View file

@ -75,7 +75,7 @@ echo_message = func(msg, callsign)
settimer(func {
# Call-back to ensure we see our own messages.
setlistener("/sim/multiplay/chat", func{ echo_message(cmdarg().getValue(), getprop("/sim/multiplay/callsign")); });
setlistener("/sim/multiplay/chat", func(n) { echo_message(n.getValue(), getprop("/sim/multiplay/callsign")); });
# check for new messages
check_messages();

View file

@ -185,14 +185,14 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
var b = "/sim/screen/";
setlistener(b ~ "black", func { log.write(cmdarg().getValue(), 0, 0, 0) });
setlistener(b ~ "white", func { log.write(cmdarg().getValue(), 1, 1, 1) });
setlistener(b ~ "red", func { log.write(cmdarg().getValue(), 0.8, 0, 0) });
setlistener(b ~ "green", func { log.write(cmdarg().getValue(), 0, 0.6, 0) });
setlistener(b ~ "blue", func { log.write(cmdarg().getValue(), 0, 0, 0.8) });
setlistener(b ~ "yellow", func { log.write(cmdarg().getValue(), 0.8, 0.8, 0) });
setlistener(b ~ "magenta", func { log.write(cmdarg().getValue(), 0.7, 0, 0.7) });
setlistener(b ~ "cyan", func { log.write(cmdarg().getValue(), 0, 0.6, 0.6) });
setlistener(b ~ "black", func(n) { log.write(n.getValue(), 0, 0, 0) });
setlistener(b ~ "white", func(n) { log.write(n.getValue(), 1, 1, 1) });
setlistener(b ~ "red", func(n) { log.write(n.getValue(), 0.8, 0, 0) });
setlistener(b ~ "green", func(n) { log.write(n.getValue(), 0, 0.6, 0) });
setlistener(b ~ "blue", func(n) { log.write(n.getValue(), 0, 0, 0.8) });
setlistener(b ~ "yellow", func(n) { log.write(n.getValue(), 0.8, 0.8, 0) });
setlistener(b ~ "magenta", func(n) { log.write(n.getValue(), 0.7, 0, 0.7) });
setlistener(b ~ "cyan", func(n) { log.write(n.getValue(), 0, 0.6, 0.6) });
});
@ -244,8 +244,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
# let ATC tell which runway was automatically chosen after startup/teleportation
settimer(func {
setlistener("/sim/atc/runway", func { # set in src/Main/fg_init.cxx
var rwy = cmdarg().getValue();
setlistener("/sim/atc/runway", func(n) { # set in src/Main/fg_init.cxx
var rwy = n.getValue();
if (rwy == nil)
return;
if (getprop("/sim/presets/airport-id") == "KSFO" and rwy == "28R")
@ -256,10 +256,10 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
}, 1);
}, 5);
setlistener("/gear/launchbar/state", func {
if (cmdarg().getValue() == "Engaged")
setlistener("/gear/launchbar/state", func(n) {
if (n.getValue() == "Engaged")
setprop("/sim/messages/copilot", "Engaged!");
}, 1, 0);
}, 0, 0);
# map ATC messages to the screen log and to the voice subsystem
var map = func(type, msg, r, g, b) {
@ -291,18 +291,18 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
var m = "/sim/messages/";
listener["atc"] = setlistener(m ~ "atc",
func { map("atc", cmdarg().getValue(), 0.7, 1.0, 0.7) });
func(n) { map("atc", n.getValue(), 0.7, 1.0, 0.7) });
listener["approach"] = setlistener(m ~ "approach",
func { map("approach", cmdarg().getValue(), 0.7, 1.0, 0.7) });
func(n) { map("approach", n.getValue(), 0.7, 1.0, 0.7) });
listener["ground"] = setlistener(m ~ "ground",
func { map("ground", cmdarg().getValue(), 0.7, 1.0, 0.7) });
func(n) { map("ground", n.getValue(), 0.7, 1.0, 0.7) });
listener["pilot"] = setlistener(m ~ "pilot",
func { map("pilot", cmdarg().getValue(), 1.0, 0.8, 0.0) });
func(n) { map("pilot", n.getValue(), 1.0, 0.8, 0.0) });
listener["copilot"] = setlistener(m ~ "copilot",
func { map("copilot", cmdarg().getValue(), 1.0, 1.0, 1.0) });
func(n) { map("copilot", n.getValue(), 1.0, 1.0, 1.0) });
listener["ai-plane"] = setlistener(m ~ "ai-plane",
func { map("ai-plane", cmdarg().getValue(), 0.9, 0.4, 0.2) });
func(n) { map("ai-plane", n.getValue(), 0.9, 0.4, 0.2) });
});

View file

@ -154,13 +154,13 @@ var flyby = {
if (me.number == nil)
die("can't find 'Fly-By View'");
setlistener("/sim/signals/reinit", func { cmdarg().getValue() or me.reset() });
setlistener("/sim/crashed", func { cmdarg().getValue() and me.reset() });
setlistener("/sim/signals/reinit", func(n) { n.getValue() or me.reset() });
setlistener("/sim/crashed", func(n) { n.getValue() and me.reset() });
setlistener("/sim/freeze/replay-state", func {
settimer(func { me.reset() }, 1); # time for replay to catch up
});
setlistener("/sim/current-view/view-number", func {
me.currview = cmdarg().getValue();
setlistener("/sim/current-view/view-number", func(n) {
me.currview = n.getValue();
me.reset();
}, 1);
},