- make props.initNode a props.Node method
- props.nas: some minor improvements
This commit is contained in:
parent
39934667aa
commit
c74d6ee75e
6 changed files with 67 additions and 62 deletions
|
@ -780,20 +780,20 @@ var tyresmoke = {
|
|||
me.speed = props.initNode("velocities/groundspeed-kt");
|
||||
me.rain = props.initNode("environment/metar/rain-norm");
|
||||
|
||||
var gear = "gear/gear[" ~ number ~ "]/";
|
||||
m.wow = props.initNode(gear ~ "wow");
|
||||
m.tyresmoke = props.initNode(gear ~ "tyre-smoke", 0, "BOOL");
|
||||
m.friction_factor = props.initNode(gear ~ "ground-friction-factor", 1);
|
||||
m.sprayspeed = props.initNode(gear ~ "sprayspeed-ms");
|
||||
m.spray = props.initNode(gear ~ "spray", 0, "BOOL");
|
||||
m.spraydensity = props.initNode(gear ~ "spray-density", 0, "DOUBLE");
|
||||
var gear = props.globals.getNode("gear/gear[" ~ number ~ "]/");
|
||||
m.wow = gear.initNode("wow");
|
||||
m.tyresmoke = gear.initNode("tyre-smoke", 0, "BOOL");
|
||||
m.friction_factor = gear.initNode("ground-friction-factor", 1);
|
||||
m.sprayspeed = gear.initNode("sprayspeed-ms");
|
||||
m.spray = gear.initNode("spray", 0, "BOOL");
|
||||
m.spraydensity = gear.initNode("spray-density", 0, "DOUBLE");
|
||||
|
||||
if (getprop("sim/flight-model") == "jsb") {
|
||||
var wheel_speed = "fdm/jsbsim/gear/unit[" ~ number ~ "]/wheel-speed-fps";
|
||||
m.rollspeed = props.initNode(wheel_speed);
|
||||
m.rollspeed = props.globals.initNode(wheel_speed);
|
||||
m.get_rollspeed = func m.rollspeed.getValue() * 0.3043;
|
||||
} else {
|
||||
m.rollspeed = props.initNode(gear ~ "rollspeed-ms");
|
||||
m.rollspeed = gear.initNode("rollspeed-ms");
|
||||
m.get_rollspeed = func m.rollspeed.getValue();
|
||||
}
|
||||
|
||||
|
|
|
@ -112,11 +112,11 @@ _setlistener("/sim/signals/fdm-initialized", func {
|
|||
continue; # skip native_fdm.cxx generated zombie tanks
|
||||
|
||||
append(tanks, t);
|
||||
props.initNode(t.getNode("level-gal_us", 1), 0.0);
|
||||
props.initNode(t.getNode("level-lbs", 1), 0.0);
|
||||
props.initNode(t.getNode("capacity-gal_us", 1), 0.01); # not zero (div/zero issue)
|
||||
props.initNode(t.getNode("density-ppg", 1), 6.0); # gasoline
|
||||
props.initNode(t.getNode("selected", 1), 1, "BOOL");
|
||||
t.initNode("level-gal_us", 0.0);
|
||||
t.initNode("level-lbs", 0.0);
|
||||
t.initNode("capacity-gal_us", 0.01); # not zero (div/zero issue)
|
||||
t.initNode("density-ppg", 6.0); # gasoline
|
||||
t.initNode("selected", 1, "BOOL");
|
||||
}
|
||||
|
||||
loop();
|
||||
|
|
|
@ -89,7 +89,7 @@ var loopid = 0;
|
|||
|
||||
_setlistener("/sim/signals/fdm-initialized", func {
|
||||
# remove top bar unless otherwise specified
|
||||
var top = props.initNode("/sim/model/geometry/square/top", 1, "BOOL");
|
||||
var top = props.globals.initNode("/sim/model/geometry/square/top", 1, "BOOL");
|
||||
|
||||
setlistener("/sim/rendering/glide-slope-tunnel", func(n) {
|
||||
loopid += 1;
|
||||
|
|
|
@ -319,7 +319,7 @@ var OverlaySelector = {
|
|||
m.sortprop = relpath(sortprop or nameprop);
|
||||
m.mpprop = mpprop;
|
||||
m.callback = callback;
|
||||
m.result = props.initNode(data.getNode("result", 1), "");
|
||||
m.result = data.initNode("result", "");
|
||||
m.listener = setlistener(m.result, func(n) m.select(n.getValue()));
|
||||
|
||||
m.prop.getNode("group/text/label").setValue(title);
|
||||
|
|
|
@ -291,14 +291,14 @@ var search = func(n, s) {
|
|||
_setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||
foreach (var p; props.globals.getNode("/sim/gui/prop-key-handler/history", 1).getChildren("entry"))
|
||||
append(history, p.getValue());
|
||||
var max = props.initNode("/sim/gui/prop-key-handler/history-max-size", 20).getValue();
|
||||
var max = props.globals.initNode("/sim/gui/prop-key-handler/history-max-size", 20).getValue();
|
||||
if (size(history) > max)
|
||||
history = subvec(history, size(history) - max);
|
||||
});
|
||||
|
||||
|
||||
_setlistener("/sim/signals/exit", func {
|
||||
var max = props.initNode("/sim/gui/prop-key-handler/history-max-size", 20).getValue();
|
||||
var max = props.globals.initNode("/sim/gui/prop-key-handler/history-max-size", 20).getValue();
|
||||
if (size(history) > max)
|
||||
history = subvec(history, size(history) - max);
|
||||
forindex (var i; history) {
|
||||
|
|
|
@ -10,30 +10,30 @@
|
|||
# available in C++; just use node.getNode(path).whatever() instead.
|
||||
#
|
||||
var Node = {
|
||||
getNode : func { wrap(_getNode(me._g, arg)) },
|
||||
getParent : func { wrap(_getParent(me._g, arg)) },
|
||||
getChild : func { wrap(_getChild(me._g, arg)) },
|
||||
getChildren : func { wrap(_getChildren(me._g, arg)) },
|
||||
removeChild : func { wrap(_removeChild(me._g, arg)) },
|
||||
removeChildren : func { wrap(_removeChildren(me._g, arg)) },
|
||||
getNode : func wrap(_getNode(me._g, arg)),
|
||||
getParent : func wrap(_getParent(me._g, arg)),
|
||||
getChild : func wrap(_getChild(me._g, arg)),
|
||||
getChildren : func wrap(_getChildren(me._g, arg)),
|
||||
removeChild : func wrap(_removeChild(me._g, arg)),
|
||||
removeChildren : func wrap(_removeChildren(me._g, arg)),
|
||||
|
||||
getName : func { _getName(me._g, arg) },
|
||||
getIndex : func { _getIndex(me._g, arg) },
|
||||
getType : func { _getType(me._g, arg) },
|
||||
getAttribute : func { _getAttribute(me._g, arg) },
|
||||
setAttribute : func { _setAttribute(me._g, arg) },
|
||||
getValue : func { _getValue(me._g, arg) },
|
||||
setValue : func { _setValue(me._g, arg) },
|
||||
setIntValue : func { _setIntValue(me._g, arg) },
|
||||
setBoolValue : func { _setBoolValue(me._g, arg) },
|
||||
setDoubleValue : func { _setDoubleValue(me._g, arg) },
|
||||
unalias : func { _unalias(me._g, arg) },
|
||||
alias : func(n) { _alias(me._g, [isa(n, props.Node) ? n._g : n]) },
|
||||
getName : func _getName(me._g, arg),
|
||||
getIndex : func _getIndex(me._g, arg),
|
||||
getType : func _getType(me._g, arg),
|
||||
getAttribute : func _getAttribute(me._g, arg),
|
||||
setAttribute : func _setAttribute(me._g, arg),
|
||||
getValue : func _getValue(me._g, arg),
|
||||
setValue : func _setValue(me._g, arg),
|
||||
setIntValue : func _setIntValue(me._g, arg),
|
||||
setBoolValue : func _setBoolValue(me._g, arg),
|
||||
setDoubleValue : func _setDoubleValue(me._g, arg),
|
||||
unalias : func _unalias(me._g, arg),
|
||||
alias : func(n) _alias(me._g, [isa(n, Node) ? n._g : n]),
|
||||
|
||||
getPath : func {
|
||||
var name = me.getName();
|
||||
if(me.getIndex() != 0) { name ~= "[" ~ me.getIndex() ~ "]"; }
|
||||
if(me.getParent() != nil) { name = me.getParent().getPath() ~ "/" ~ name; }
|
||||
var (name, index, parent) = (me.getName(), me.getIndex(), me.getParent());
|
||||
if(index != 0) { name ~= "[" ~ index ~ "]"; }
|
||||
if(parent != nil) { name = parent.getPath() ~ "/" ~ name; }
|
||||
return name;
|
||||
},
|
||||
|
||||
|
@ -55,7 +55,7 @@ var Node = {
|
|||
#
|
||||
Node.new = func(values = nil) {
|
||||
var result = wrapNode(_new());
|
||||
if(values != nil and typeof(values) == "hash")
|
||||
if(typeof(values) == "hash")
|
||||
result.setValues(values);
|
||||
return result;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ Node.getValues = func {
|
|||
else {
|
||||
var nc = size(me.getChildren(name));
|
||||
numchld[name] = nc;
|
||||
if (nc > 1 and !contains(val, name)) val[name] = [];
|
||||
if(nc > 1 and !contains(val, name)) val[name] = [];
|
||||
}
|
||||
if(nc > 1) append(val[name], c.getValues());
|
||||
else val[name] = c.getValues();
|
||||
|
@ -119,6 +119,30 @@ Node.getValues = func {
|
|||
return val;
|
||||
}
|
||||
|
||||
##
|
||||
# Initializes property if it's still undefined. First argument
|
||||
# is a property name/path. Second argument is the default value.
|
||||
# The third, optional argument is a property type (one of
|
||||
# "STRING", "DOUBLE", "INT", or "BOOL"). If it is omitted, then
|
||||
# "DOUBLE" is used for numbers, and STRING for everything else.
|
||||
# Returns the property as props.Node.
|
||||
#
|
||||
Node.initNode = func(path, value = 0, type = nil) {
|
||||
var prop = me.getNode(path, 1);
|
||||
if(prop.getType() != "NONE") value = prop.getValue();
|
||||
if(type == nil) prop.setValue(value);
|
||||
elsif(type == "DOUBLE") prop.setDoubleValue(value);
|
||||
elsif(type == "INT") prop.setIntValue(value);
|
||||
elsif(type == "BOOL") prop.setBoolValue(value);
|
||||
elsif(type == "STRING") prop.setValue("" ~ value);
|
||||
else die("initNode(): unsupported type '" ~ type ~ "'");
|
||||
return prop;
|
||||
}
|
||||
# temporary compatibility wrapper [*** DEPRECATED ***]
|
||||
var initNode = func(path, value = 0, type = nil) {
|
||||
return props.globals.initNode(path, value, type);
|
||||
}
|
||||
|
||||
##
|
||||
# Useful debugging utility. Recursively dumps the full state of a
|
||||
# Node object to the console. Try binding "props.dump(props.globals)"
|
||||
|
@ -225,7 +249,7 @@ var nodeList = func {
|
|||
var list = [];
|
||||
foreach(var a; arg) {
|
||||
var t = typeof(a);
|
||||
if(isa(a, props.Node))
|
||||
if(isa(a, Node))
|
||||
append(list, a);
|
||||
elsif(t == "scalar")
|
||||
append(list, props.globals.getNode(a, 1));
|
||||
|
@ -245,25 +269,6 @@ var nodeList = func {
|
|||
return list;
|
||||
}
|
||||
|
||||
##
|
||||
# Initializes property if it's still undefined. First argument is a property
|
||||
# path or a props.Node. Second argument is the default value. The third,
|
||||
# optional argument is a property type (one of "STRING", "DOUBLE", "INT", or
|
||||
# "BOOL"). If it is omitted, then "DOUBLE" is used for numbers, and STRING
|
||||
# for everything else. Returns the property as props.Node.
|
||||
#
|
||||
var initNode = func(prop, value = 0, type = nil) {
|
||||
if(!isa(prop, props.Node)) prop = props.globals.getNode(prop, 1);
|
||||
if(prop.getType() != "NONE") value = prop.getValue();
|
||||
if(type == nil) prop.setValue(value);
|
||||
elsif(type == "DOUBLE") prop.setDoubleValue(value);
|
||||
elsif(type == "INT") prop.setIntValue(value);
|
||||
elsif(type == "BOOL") prop.setBoolValue(value);
|
||||
elsif(type == "STRING") prop.setValue("" ~ value);
|
||||
else die("initNode(): unsupported type '" ~ type ~ "'");
|
||||
return prop;
|
||||
}
|
||||
|
||||
##
|
||||
# Evaluates a <condition> property branch according to the rules
|
||||
# set out in $FG_ROOT/Docs/README.conditions. Undefined conditions
|
||||
|
@ -272,7 +277,7 @@ var initNode = func(prop, value = 0, type = nil) {
|
|||
#
|
||||
var condition = func(p) {
|
||||
if(p == nil) return 1;
|
||||
if(!isa(p, props.Node)) p = props.globals.getNode(p);
|
||||
if(!isa(p, Node)) p = props.globals.getNode(p);
|
||||
return _cond_and(p)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue