1
0
Fork 0

Add props.nas getDoubleValue(), getIntValue()

Also fixed an issue with whitespace around view parameters.
This commit is contained in:
Stuart Buchanan 2019-09-22 21:14:07 +01:00
parent f83caf7e45
commit 01dc9d0b38
2 changed files with 44 additions and 36 deletions

View file

@ -52,6 +52,14 @@ var Node = {
return !!val; return !!val;
}, },
getIntValue : func {
return math.round(me.getValue());
},
getDoubleValue : func {
return num(me.getValue());
},
remove : func { remove : func {
if((var p = me.getParent()) == nil) return nil; if((var p = me.getParent()) == nil) return nil;
p.removeChild(me.getName(), me.getIndex()); p.removeChild(me.getName(), me.getIndex());
@ -237,11 +245,11 @@ var setAll = func(base, child, value) {
} }
# createNodeObjectsFromHash - create nasal node objects from hash # createNodeObjectsFromHash - create nasal node objects from hash
# property_list: hash; where keys are variable names and values are # property_list: hash; where keys are variable names and values are
# property paths # property paths
# { foo: "/some/prop/foo", bar: "/some/other/prop", } # { foo: "/some/prop/foo", bar: "/some/other/prop", }
# namespace: optional; variables (objects) are created in this namespace # namespace: optional; variables (objects) are created in this namespace
# defaults to namespace of caller, e.g. after calling this # defaults to namespace of caller, e.g. after calling this
# you can use foo.getValue() or bar.addChild() # you can use foo.getValue() or bar.addChild()
# #
var createNodeObjectsFromHash = func (property_list, namespace = nil) { var createNodeObjectsFromHash = func (property_list, namespace = nil) {
@ -414,7 +422,7 @@ var runBinding = func(node, module = nil) {
# }), # }),
# UpdateManager.FromHashList(["pitch","roll"], 0.025, func(hdp) # UpdateManager.FromHashList(["pitch","roll"], 0.025, func(hdp)
# { # {
# obj.ladder.setTranslation (0.0, hdp.pitch * pitch_factor+pitch_offset); # obj.ladder.setTranslation (0.0, hdp.pitch * pitch_factor+pitch_offset);
# obj.ladder.setCenter (118,830 - hdp.pitch * pitch_factor-pitch_offset); # obj.ladder.setCenter (118,830 - hdp.pitch * pitch_factor-pitch_offset);
# obj.ladder.setRotation (-hdp.roll_rad); # obj.ladder.setRotation (-hdp.roll_rad);
# obj.roll_pointer.setRotation (hdp.roll_rad); # obj.roll_pointer.setRotation (hdp.roll_rad);
@ -432,7 +440,7 @@ var runBinding = func(node, module = nil) {
# ] # ]
# #
#==== the update loop then becomes ====== #==== the update loop then becomes ======
# #
# foreach(var update_item; me.update_items) # foreach(var update_item; me.update_items)
# { # {
# # hdp is a data provider that can be used as the hashlist for the property # # hdp is a data provider that can be used as the hashlist for the property

View file

@ -3,7 +3,7 @@
## ##
## Nasal code for implementing view-specific functionality. ## Nasal code for implementing view-specific functionality.
# ATTENTION: # ATTENTION:
# /sim/current-view/view-number is in the range 0..viewCount, it is NOT # /sim/current-view/view-number is in the range 0..viewCount, it is NOT
# the index used in aircraft XML files (e.g. <view n="100">). # the index used in aircraft XML files (e.g. <view n="100">).
# #
@ -38,7 +38,7 @@ var fovProp = nil;
var setView = func(n) { var setView = func(n) {
setprop("/sim/current-view/view-number", n); setprop("/sim/current-view/view-number", n);
# We install a listener for /sim/current-view/view-number which also sets # We install a listener for /sim/current-view/view-number which also sets
# /sim/current-view/view-number-raw, but set it here anyway, just in case. # /sim/current-view/view-number-raw, but set it here anyway, just in case.
setprop("/sim/current-view/view-number-raw", views[n].getIndex()); setprop("/sim/current-view/view-number-raw", views[n].getIndex());
@ -328,7 +328,7 @@ var manager = {
model_view_handler.start(); model_view_handler.start();
} }
screenWidthCompens.update(); screenWidthCompens.update();
# Make sure /sim/current-view/view-number-raw is kept up to # Make sure /sim/current-view/view-number-raw is kept up to
# date. # date.
setprop("/sim/current-view/view-number-raw", views[which].getIndex()); setprop("/sim/current-view/view-number-raw", views[which].getIndex());
@ -361,7 +361,7 @@ var manager = {
var fly_by_view_handler = { var fly_by_view_handler = {
init : func { init : func {
setlistener("/sim/signals/reinit", func(n) { n.getValue() or 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/crashed", func(n) { n.getValue() and me.reset() });
@ -369,14 +369,14 @@ var fly_by_view_handler = {
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/multiplayer", func(n) { me.reset(); } ); setlistener("/sim/current-view/multiplayer", func(n) { me.reset(); } );
me.reset(); me.reset();
}, },
start : func { start : func {
me.reset(); me.reset();
}, },
# Sets me.root to node with path given by the value of property # Sets me.root to node with path given by the value of property
# /sim/view[6]/config/root (which will be /ai/models/multiplayer[N] # /sim/view[6]/config/root (which will be /ai/models/multiplayer[N]
# where N is the index of the multiplayer aircraft]. Note that this # where N is the index of the multiplayer aircraft]. Note that this
@ -391,7 +391,7 @@ var fly_by_view_handler = {
#printf("root does not exist: %s", str(root)); #printf("root does not exist: %s", str(root));
} }
}, },
aircraft_position: func() { aircraft_position: func() {
if (me.multiplayer) { if (me.multiplayer) {
me._set_multiplayer_root(); me._set_multiplayer_root();
@ -408,28 +408,28 @@ var fly_by_view_handler = {
return geo.aircraft_position(); return geo.aircraft_position();
} }
}, },
reset: func { reset: func {
me.multiplayer = getprop("/sim/current-view/multiplayer") or 0; me.multiplayer = getprop("/sim/current-view/multiplayer") or 0;
if (me.multiplayer) { if (me.multiplayer) {
me._set_multiplayer_root(); me._set_multiplayer_root();
if (me.root == nil) { if (me.root == nil) {
return; return;
} }
me.chase = me.root.getValue("set/sim/chase-distance-m"); me.chase = me.root.getValue("set/sim/chase-distance-m");
} }
else { else {
me.chase = getprop("/sim/chase-distance-m"); me.chase = getprop("/sim/chase-distance-m");
} }
if (me.chase == nil or me.chase == 0) me.chase = -25; if (me.chase == nil or me.chase == 0) me.chase = -25;
me.chase = -me.chase; me.chase = -me.chase;
me.last = me.aircraft_position(); me.last = me.aircraft_position();
me.setpos(1); me.setpos(1);
}, },
setpos : func(force = 0) { setpos : func(force = 0) {
if (me.multiplayer) { if (me.multiplayer) {
me._set_multiplayer_root(); me._set_multiplayer_root();
@ -447,7 +447,7 @@ var fly_by_view_handler = {
var u = me.root.getValue("velocities/uBody-fps"); # forwards var u = me.root.getValue("velocities/uBody-fps"); # forwards
#var v = me.root.getValue("velocities/vBody-fps"); # vertical #var v = me.root.getValue("velocities/vBody-fps"); # vertical
#var w = me.root.getValue("velocities/wBody-fps"); # lateral #var w = me.root.getValue("velocities/wBody-fps"); # lateral
var course = me.root.getValue("orientation/true-heading-deg"); var course = me.root.getValue("orientation/true-heading-deg");
var course_rad = course * math.pi / 180; var course_rad = course * math.pi / 180;
var vn = u * math.cos(course_rad); var vn = u * math.cos(course_rad);
@ -458,9 +458,9 @@ var fly_by_view_handler = {
var ve = getprop("/velocities/speed-east-fps"); var ve = getprop("/velocities/speed-east-fps");
var course = (0.5*math.pi - math.atan2(vn, ve))*R2D; var course = (0.5*math.pi - math.atan2(vn, ve))*R2D;
} }
var pos = me.aircraft_position(); var pos = me.aircraft_position();
var dist = 0.0; var dist = 0.0;
if ( force ) { if ( force ) {
# predict distance based on speed # predict distance based on speed
@ -485,7 +485,7 @@ var fly_by_view_handler = {
# apply random deviation # apply random deviation
var radius = me.chase * (0.5 * rand() + 0.7); var radius = me.chase * (0.5 * rand() + 0.7);
if (me.multiplayer) { if (me.multiplayer) {
# AGL not available for multiplayer aircraft as a property, # AGL not available for multiplayer aircraft as a property,
# so we calculate it explicitly. # so we calculate it explicitly.
@ -537,7 +537,7 @@ var fly_by_view_handler = {
} }
return 7.3; return 7.3;
}, },
update : func { update : func {
return me.setpos(); return me.setpos();
}, },
@ -875,7 +875,7 @@ var screenWidthCompens = {
setStatus: func(state) me.statusNode.setValue(state), setStatus: func(state) me.statusNode.setValue(state),
wNode: nil, # = /sim/startup/xsize wNode: nil, # = /sim/startup/xsize
hNode: nil, # = /sim/startup/ysize hNode: nil, # = /sim/startup/ysize
getDimensions: func [me.wNode.getValue(),me.hNode.getValue()], getDimensions: func [me.wNode.getDoubleValue(),me.hNode.getDoubleValue()],
calcNewFov: func(fov=55, oldW=nil, oldH=nil, w=nil, h=nil) { calcNewFov: func(fov=55, oldW=nil, oldH=nil, w=nil, h=nil) {
var dim = me.getDimensions(); var dim = me.getDimensions();
if (w == nil) w = dim[0]; if (w == nil) w = dim[0];
@ -894,7 +894,7 @@ var screenWidthCompens = {
setsize(me.fovStore, size(views)); setsize(me.fovStore, size(views));
forindex (var i; views) { forindex (var i; views) {
me.fovStore[i] = views[i].getNode("config/default-field-of-view-deg", 1).getValue() or 55; me.fovStore[i] = views[i].getNode("config/default-field-of-view-deg", 1).getDoubleValue() or 55;
me.lastViewStatus[i] = { w:me.assumedW, h:me.assumedH }; me.lastViewStatus[i] = { w:me.assumedW, h:me.assumedH };
} }
me.update(opt:nil, force:1); me.update(opt:nil, force:1);