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:
parent
12c11dfa6f
commit
2bcddab9b6
9 changed files with 42 additions and 43 deletions
|
@ -399,7 +399,7 @@ var data = {
|
||||||
me.loopid = 0;
|
me.loopid = 0;
|
||||||
me.interval = 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_() });
|
setlistener("/sim/signals/exit", func { me._save_() });
|
||||||
},
|
},
|
||||||
load : func {
|
load : func {
|
||||||
|
@ -652,9 +652,9 @@ var steering = {
|
||||||
call(func(v, w) (w < 0 ? leftN : w > 0 ? rightN : switchN).setValue(v),
|
call(func(v, w) (w < 0 ? leftN : w > 0 ? rightN : switchN).setValue(v),
|
||||||
[v, w], nil, aircraft.steering);
|
[v, w], nil, aircraft.steering);
|
||||||
}
|
}
|
||||||
setlistener(me.switchN, func {
|
setlistener(me.switchN, func(n) {
|
||||||
me.loopid += 1;
|
me.loopid += 1;
|
||||||
if (cmdarg().getValue())
|
if (n.getValue())
|
||||||
me._loop_(me.loopid);
|
me._loop_(me.loopid);
|
||||||
else
|
else
|
||||||
me.setbrakes(0, 0);
|
me.setbrakes(0, 0);
|
||||||
|
|
|
@ -273,8 +273,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
ghosttypes[ghosttype(props._globals())] = "PropertyNode";
|
ghosttypes[ghosttype(props._globals())] = "PropertyNode";
|
||||||
ghosttypes[ghosttype(io.stderr)] = "FileHandle";
|
ghosttypes[ghosttype(io.stderr)] = "FileHandle";
|
||||||
|
|
||||||
setlistener("/sim/startup/terminal-ansi-colors", func {
|
setlistener("/sim/startup/terminal-ansi-colors", func(n) {
|
||||||
color(cmdarg().getBoolValue());
|
color(n.getBoolValue());
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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
|
# let listeners keep some variables up-to-date, so that they don't have
|
||||||
# to be queried in the loop
|
# to be queried in the loop
|
||||||
setlistener("/sim/panel/visibility", func { panel_visible = cmdarg().getValue() }, 1);
|
setlistener("/sim/panel/visibility", func(n) { panel_visible = n.getValue() }, 1);
|
||||||
setlistener("/sim/current-view/view-number", func { cockpit_view = enabled[cmdarg().getValue()] }, 1);
|
setlistener("/sim/current-view/view-number", func(n) { cockpit_view = enabled[n.getValue()] }, 1);
|
||||||
setlistener("/devices/status/mice/mouse/button", func { mouse_button = cmdarg().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/x", freeze);
|
||||||
setlistener("/devices/status/mice/mouse/y", freeze);
|
setlistener("/devices/status/mice/mouse/y", freeze);
|
||||||
setlistener("/devices/status/mice/mouse/mode", func {
|
setlistener("/devices/status/mice/mouse/mode", func(n) {
|
||||||
if (mouse_mode = cmdarg().getValue())
|
if (mouse_mode = n.getValue())
|
||||||
view_manager.unfreeze();
|
view_manager.unfreeze();
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
setlistener("/sim/signals/reinit", func {
|
setlistener("/sim/signals/reinit", func(n) {
|
||||||
cmdarg().getValue() and return;
|
n.getValue() and return;
|
||||||
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
|
cockpit_view = enabled[getprop("/sim/current-view/view-number")];
|
||||||
view_manager.reset();
|
view_manager.reset();
|
||||||
}, 0);
|
}, 0);
|
||||||
|
@ -427,8 +427,8 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
}
|
}
|
||||||
|
|
||||||
settimer(func {
|
settimer(func {
|
||||||
setlistener("/sim/view/dynamic/enabled", func {
|
setlistener("/sim/view/dynamic/enabled", func(n) {
|
||||||
dynamic_view = cmdarg().getBoolValue();
|
dynamic_view = n.getBoolValue();
|
||||||
loop_id += 1;
|
loop_id += 1;
|
||||||
view.resetView();
|
view.resetView();
|
||||||
if (dynamic_view)
|
if (dynamic_view)
|
||||||
|
|
|
@ -104,7 +104,7 @@ var total_norm = nil;
|
||||||
|
|
||||||
|
|
||||||
_setlistener("/sim/signals/fdm-initialized", func {
|
_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_gals = props.globals.getNode("/consumables/fuel/total-fuel-gals", 1);
|
||||||
total_lbs = props.globals.getNode("/consumables/fuel/total-fuel-lbs", 1);
|
total_lbs = props.globals.getNode("/consumables/fuel/total-fuel-lbs", 1);
|
||||||
|
|
|
@ -70,7 +70,6 @@ var interpolate = func(node, val...) {
|
||||||
#
|
#
|
||||||
var setlistener = func(node, fun, init=0, runtime=1) {
|
var setlistener = func(node, fun, init=0, runtime=1) {
|
||||||
if(isa(node, props.Node)) node = node._g;
|
if(isa(node, props.Node)) node = node._g;
|
||||||
var propghost = ghosttype(node);
|
|
||||||
var id = _setlistener(node, func {
|
var id = _setlistener(node, func {
|
||||||
arg[0] = props.wrapNode(arg[0], nil);
|
arg[0] = props.wrapNode(arg[0], nil);
|
||||||
arg[1] = props.wrapNode(arg[1], nil);
|
arg[1] = props.wrapNode(arg[1], nil);
|
||||||
|
|
|
@ -242,7 +242,7 @@ Dialog = {
|
||||||
#
|
#
|
||||||
# SYNOPSIS: FileSelector.new(<callback>, <title>, <button> [, <pattern> [, <dir> [, <file> [, <dotfiles>]]]])
|
# 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
|
# title ... dialog title
|
||||||
# button ... button text (should say "Save", "Load", etc. and not just "OK")
|
# button ... button text (should say "Save", "Load", etc. and not just "OK")
|
||||||
# pattern ... array with shell pattern or nil (which is equivalent to "*")
|
# pattern ... array with shell pattern or nil (which is equivalent to "*")
|
||||||
|
@ -252,7 +252,7 @@ Dialog = {
|
||||||
#
|
#
|
||||||
# EXAMPLE:
|
# EXAMPLE:
|
||||||
#
|
#
|
||||||
# var report = func { print("file ", cmdarg().getValue(), " selected") }
|
# var report = func(n) { print("file ", n.getValue(), " selected") }
|
||||||
# var selector = gui.FileSelector.new(
|
# var selector = gui.FileSelector.new(
|
||||||
# report, # callback function
|
# report, # callback function
|
||||||
# "Save Flight", # dialog title
|
# "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
|
# 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/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
|
# Called from the F&W dialog when the user selects a weight option
|
||||||
|
|
|
@ -75,7 +75,7 @@ echo_message = func(msg, callsign)
|
||||||
|
|
||||||
settimer(func {
|
settimer(func {
|
||||||
# Call-back to ensure we see our own messages.
|
# 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 for new messages
|
||||||
check_messages();
|
check_messages();
|
||||||
|
|
|
@ -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
|
log.sticky = 0; # don't turn on; makes scrolling up messages jump left and right
|
||||||
|
|
||||||
var b = "/sim/screen/";
|
var b = "/sim/screen/";
|
||||||
setlistener(b ~ "black", func { log.write(cmdarg().getValue(), 0, 0, 0) });
|
setlistener(b ~ "black", func(n) { log.write(n.getValue(), 0, 0, 0) });
|
||||||
setlistener(b ~ "white", func { log.write(cmdarg().getValue(), 1, 1, 1) });
|
setlistener(b ~ "white", func(n) { log.write(n.getValue(), 1, 1, 1) });
|
||||||
setlistener(b ~ "red", func { log.write(cmdarg().getValue(), 0.8, 0, 0) });
|
setlistener(b ~ "red", func(n) { log.write(n.getValue(), 0.8, 0, 0) });
|
||||||
setlistener(b ~ "green", func { log.write(cmdarg().getValue(), 0, 0.6, 0) });
|
setlistener(b ~ "green", func(n) { log.write(n.getValue(), 0, 0.6, 0) });
|
||||||
setlistener(b ~ "blue", func { log.write(cmdarg().getValue(), 0, 0, 0.8) });
|
setlistener(b ~ "blue", func(n) { log.write(n.getValue(), 0, 0, 0.8) });
|
||||||
setlistener(b ~ "yellow", func { log.write(cmdarg().getValue(), 0.8, 0.8, 0) });
|
setlistener(b ~ "yellow", func(n) { log.write(n.getValue(), 0.8, 0.8, 0) });
|
||||||
setlistener(b ~ "magenta", func { log.write(cmdarg().getValue(), 0.7, 0, 0.7) });
|
setlistener(b ~ "magenta", func(n) { log.write(n.getValue(), 0.7, 0, 0.7) });
|
||||||
setlistener(b ~ "cyan", func { log.write(cmdarg().getValue(), 0, 0.6, 0.6) });
|
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
|
# let ATC tell which runway was automatically chosen after startup/teleportation
|
||||||
settimer(func {
|
settimer(func {
|
||||||
setlistener("/sim/atc/runway", func { # set in src/Main/fg_init.cxx
|
setlistener("/sim/atc/runway", func(n) { # set in src/Main/fg_init.cxx
|
||||||
var rwy = cmdarg().getValue();
|
var rwy = n.getValue();
|
||||||
if (rwy == nil)
|
if (rwy == nil)
|
||||||
return;
|
return;
|
||||||
if (getprop("/sim/presets/airport-id") == "KSFO" and rwy == "28R")
|
if (getprop("/sim/presets/airport-id") == "KSFO" and rwy == "28R")
|
||||||
|
@ -256,10 +256,10 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
}, 1);
|
}, 1);
|
||||||
}, 5);
|
}, 5);
|
||||||
|
|
||||||
setlistener("/gear/launchbar/state", func {
|
setlistener("/gear/launchbar/state", func(n) {
|
||||||
if (cmdarg().getValue() == "Engaged")
|
if (n.getValue() == "Engaged")
|
||||||
setprop("/sim/messages/copilot", "Engaged!");
|
setprop("/sim/messages/copilot", "Engaged!");
|
||||||
}, 1, 0);
|
}, 0, 0);
|
||||||
|
|
||||||
# map ATC messages to the screen log and to the voice subsystem
|
# map ATC messages to the screen log and to the voice subsystem
|
||||||
var map = func(type, msg, r, g, b) {
|
var map = func(type, msg, r, g, b) {
|
||||||
|
@ -291,18 +291,18 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
|
|
||||||
var m = "/sim/messages/";
|
var m = "/sim/messages/";
|
||||||
listener["atc"] = setlistener(m ~ "atc",
|
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",
|
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",
|
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",
|
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",
|
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",
|
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) });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -154,13 +154,13 @@ var flyby = {
|
||||||
if (me.number == nil)
|
if (me.number == nil)
|
||||||
die("can't find 'Fly-By View'");
|
die("can't find 'Fly-By View'");
|
||||||
|
|
||||||
setlistener("/sim/signals/reinit", func { cmdarg().getValue() or me.reset() });
|
setlistener("/sim/signals/reinit", func(n) { n.getValue() or me.reset() });
|
||||||
setlistener("/sim/crashed", func { cmdarg().getValue() and me.reset() });
|
setlistener("/sim/crashed", func(n) { n.getValue() and me.reset() });
|
||||||
setlistener("/sim/freeze/replay-state", func {
|
setlistener("/sim/freeze/replay-state", func {
|
||||||
settimer(func { me.reset() }, 1); # time for replay to catch up
|
settimer(func { me.reset() }, 1); # time for replay to catch up
|
||||||
});
|
});
|
||||||
setlistener("/sim/current-view/view-number", func {
|
setlistener("/sim/current-view/view-number", func(n) {
|
||||||
me.currview = cmdarg().getValue();
|
me.currview = n.getValue();
|
||||||
me.reset();
|
me.reset();
|
||||||
}, 1);
|
}, 1);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue