more use of initNode & some consistency improvements (method format)
This commit is contained in:
parent
f7e246905b
commit
1e5cf9ff0a
2 changed files with 44 additions and 36 deletions
|
@ -46,19 +46,12 @@ var optarg = func(args, index, default) {
|
||||||
# canopy.open();
|
# canopy.open();
|
||||||
#
|
#
|
||||||
var door = {
|
var door = {
|
||||||
new: func {
|
new: func(node, swingtime, pos = 0) {
|
||||||
m = { parents: [door] };
|
var m = { parents: [door] };
|
||||||
m.node = makeNode(arg[0]);
|
m.node = makeNode(node);
|
||||||
m.swingtime = arg[1];
|
m.swingtime = swingtime;
|
||||||
m.positionN = m.node.getNode("position-norm", 1);
|
m.enabledN = m.node.initNode("enabled", 1, "BOOL");
|
||||||
m.enabledN = m.node.getNode("enabled", 1);
|
m.positionN = m.node.initNode("position-norm", pos);
|
||||||
if (m.enabledN.getValue() == nil)
|
|
||||||
m.enabledN.setBoolValue(1);
|
|
||||||
|
|
||||||
var pos = optarg(arg, 2, 0);
|
|
||||||
if (m.positionN.getValue() == nil)
|
|
||||||
m.positionN.setDoubleValue(pos);
|
|
||||||
|
|
||||||
m.target = pos < 0.5;
|
m.target = pos < 0.5;
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
|
@ -74,20 +67,25 @@ var door = {
|
||||||
me;
|
me;
|
||||||
},
|
},
|
||||||
# double door.getpos() -> return current position as double
|
# double door.getpos() -> return current position as double
|
||||||
getpos: func { me.positionN.getValue() },
|
getpos: func {
|
||||||
|
me.positionN.getValue();
|
||||||
|
},
|
||||||
# door.close() -> move to closed state
|
# door.close() -> move to closed state
|
||||||
close: func { me.move(me.target = 0) },
|
close: func {
|
||||||
|
me.move(me.target = 0);
|
||||||
|
},
|
||||||
# door.open() -> move to open state
|
# door.open() -> move to open state
|
||||||
open: func { me.move(me.target = 1) },
|
open: func {
|
||||||
|
me.move(me.target = 1);
|
||||||
|
},
|
||||||
# door.toggle() -> move to opposite end position
|
# door.toggle() -> move to opposite end position
|
||||||
toggle: func { me.move(me.target) },
|
toggle: func {
|
||||||
|
me.move(me.target);
|
||||||
|
},
|
||||||
# door.stop() -> stop movement
|
# door.stop() -> stop movement
|
||||||
stop: func { interpolate(me.positionN) },
|
stop: func {
|
||||||
|
interpolate(me.positionN);
|
||||||
|
},
|
||||||
# door.move(double) -> move to arbitrary position
|
# door.move(double) -> move to arbitrary position
|
||||||
move: func(target) {
|
move: func(target) {
|
||||||
var pos = me.getpos();
|
var pos = me.getpos();
|
||||||
|
@ -152,9 +150,7 @@ var light = {
|
||||||
if (m.switchN.getValue() == nil)
|
if (m.switchN.getValue() == nil)
|
||||||
m.switchN.setBoolValue(0);
|
m.switchN.setBoolValue(0);
|
||||||
|
|
||||||
m.stateN = m.node.getNode("state", 1);
|
m.stateN = m.node.initNode("state", 0, "BOOL");
|
||||||
if (m.stateN.getValue() == nil)
|
|
||||||
m.stateN.setBoolValue(0);
|
|
||||||
|
|
||||||
forindex (var i; m.pattern)
|
forindex (var i; m.pattern)
|
||||||
m.pattern[i] *= stretch;
|
m.pattern[i] *= stretch;
|
||||||
|
@ -175,9 +171,15 @@ var light = {
|
||||||
},
|
},
|
||||||
# light.switch(bool) -> set light switch (also affects other lights
|
# light.switch(bool) -> set light switch (also affects other lights
|
||||||
# that use the same switch)
|
# that use the same switch)
|
||||||
switch: func(v) { me.switchN.setBoolValue(v); me },
|
switch: func(v) {
|
||||||
|
me.switchN.setBoolValue(v);
|
||||||
|
me;
|
||||||
|
},
|
||||||
# light.toggle() -> toggle light switch
|
# light.toggle() -> toggle light switch
|
||||||
toggle: func { me.switchN.setBoolValue(!me.switchN.getValue()); me },
|
toggle: func {
|
||||||
|
me.switchN.setBoolValue(!me.switchN.getValue());
|
||||||
|
me;
|
||||||
|
},
|
||||||
# light.cont() -> continuous light
|
# light.cont() -> continuous light
|
||||||
cont: func {
|
cont: func {
|
||||||
if (!me.continuous) {
|
if (!me.continuous) {
|
||||||
|
@ -911,9 +913,15 @@ var HUD = {
|
||||||
me.currentN = me.vis0N;
|
me.currentN = me.vis0N;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oldinit1: func { fgcommand("hud-init") },
|
oldinit1: func {
|
||||||
oldinit2: func { fgcommand("hud-init2") },
|
fgcommand("hud-init");
|
||||||
is_active: func { me.vis0N.getValue() or me.vis1N.getValue() },
|
},
|
||||||
|
oldinit2: func {
|
||||||
|
fgcommand("hud-init2");
|
||||||
|
},
|
||||||
|
is_active: func {
|
||||||
|
me.vis0N.getValue() or me.vis1N.getValue();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -392,11 +392,11 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
|
||||||
enabled[i] = ((var n = enabled[i].getNode("config/dynamic-view")) != nil) and n.getBoolValue();
|
enabled[i] = ((var n = enabled[i].getNode("config/dynamic-view")) != nil) and n.getBoolValue();
|
||||||
|
|
||||||
# some properties may still be unavailable or nil
|
# some properties may still be unavailable or nil
|
||||||
props.globals.getNode("/accelerations/pilot/x-accel-fps_sec", 1).setDoubleValue(0);
|
props.globals.initNode("/accelerations/pilot/x-accel-fps_sec", 0);
|
||||||
props.globals.getNode("/accelerations/pilot/y-accel-fps_sec", 1).setDoubleValue(0);
|
props.globals.initNode("/accelerations/pilot/y-accel-fps_sec", 0);
|
||||||
props.globals.getNode("/accelerations/pilot/z-accel-fps_sec", 1).setDoubleValue(-32);
|
props.globals.initNode("/accelerations/pilot/z-accel-fps_sec", -32);
|
||||||
props.globals.getNode("/orientation/side-slip-deg", 1).setDoubleValue(0);
|
props.globals.initNode("/orientation/side-slip-deg", 0);
|
||||||
props.globals.getNode("/gear/gear/wow", 1).setBoolValue(1);
|
props.globals.initNode("/gear/gear/wow", 1, "BOOL");
|
||||||
elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
elapsedN = props.globals.getNode("/sim/time/elapsed-sec", 1);
|
||||||
|
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in a new issue