1
0
Fork 0

Nasal/scenery.nas: Handle joining/leaving the MP network at run time.

This commit is contained in:
Anders Gidenstam 2013-02-03 19:23:53 +01:00
parent 7ef68c310a
commit 235c21985e

View file

@ -2,7 +2,7 @@
##
## Support tools for multiplayer enabled scenery objects.
##
## Copyright (C) 2011 Anders Gidenstam (anders(at)gidenstam.org)
## Copyright (C) 2011 - 2013 Anders Gidenstam (anders(at)gidenstam.org)
## This file is licensed under the GPL license version 2 or later.
##
###############################################################################
@ -65,20 +65,26 @@ var sharedDoor = {
# Internals
var shared_pp = "scenery/share-events";
_setlistener("sim/signals/nasal-dir-initialized", func {
events = mp_broadcast.EventChannel.new("scenery/events");
if (!getprop("/sim/multiplay/online") or !getprop(shared_pp)) {
var _set_state = func {
if (getprop("/sim/signals/reinit")) return; # Ignore resets.
if (getprop(shared_pp)) {
#print("scenery.nas: starting event sharing.");
events.start();
} else {
#print("scenery.nas: stopping event sharing.");
events.stop();
}
setlistener(shared_pp, func (n) {
if (getprop("/sim/signals/reinit")) return; # Ignore resets.
if (n.getValue() and getprop("/sim/multiplay/online")) {
#print("scenery.nas: starting event sharing.");
events.start();
} else {
#print("scenery.nas: stopping event sharing.");
events.stop();
}
});
}
_setlistener("sim/signals/nasal-dir-initialized", func {
events = mp_broadcast.EventChannel.new("scenery/events");
if (getprop(shared_pp)) {
#print("scenery.nas: starting event sharing.");
events.start();
} else {
#print("scenery.nas: stopping event sharing.");
events.stop();
}
setlistener(shared_pp, _set_state);
});