1
0
Fork 0
fgdata/Nasal/canvas/map/VOR.lcontroller
Philosopher 7ca8482b07 MapStructure work & (partial) integration
In time for 3.0. The API is still not fully complete, and not fully
cleaned up, but this is good enough for this release cycle (and it
should offer benefit longer term, if not now -- hopefully performance as
well).

Many thanks to Hooray as well, who has helped prepare things while I
could not, and often suggested ideas.
2014-01-09 21:24:22 -06:00

55 lines
1.5 KiB
Text

# Class things:
var parents = [SymbolLayer.Controller];
var __self__ = caller(0)[0];
SymbolLayer.Controller.add("VOR", __self__);
SymbolLayer.add("VOR", {
parents: [SymbolLayer],
type: "VOR", # Symbol type
df_controller: __self__, # controller to use by default -- this one
});
var a_instance = nil;
var new = func(layer) {
var m = {
parents: [__self__],
layer: layer,
active_vors: [],
navNs: props.globals.getNode("instrumentation").getChildren("nav"),
listeners: [],
query_type:'vor',
};
setsize(m.active_vors, size(m.navNs));
foreach (var navN; m.navNs) {
append(m.listeners, setlistener(
navN.getNode("frequencies/selected-mhz"),
func m.changed_freq()
));
}
#call(debug.dump, keys(layer));
m.changed_freq(update:0);
__self__.a_instance = m;
return m;
};
var del = func() {
#print("VOR.lcontroller.del()");
foreach (var l; me.listeners)
removelistener(l);
};
# Controller methods
var isActive = func(model) {
var my_freq = model.frequency/100;
foreach (var freq; me.active_vors)
if (freq == my_freq) return 1;
return 0;
};
var changed_freq = func(update=1) {
#debug.dump(me.active_vors);
foreach (var navN; me.navNs)
me.active_vors[ navN.getIndex() ] = navN.getValue("frequencies/selected-mhz");
if (update) me.layer.update();
};
var searchCmd = func {
#print("Running query:", me.query_type);
return positioned.findWithinRange(100, me.query_type); # the range should also be exposed, it will typically be controlled via a GUI widget or NavDisplay switch
};