Factory methods for FG1000
- Use Factories to handle multiple FG1000 calls better. - Fix DirectTo Map center.
This commit is contained in:
parent
9156006183
commit
be5e16f382
5 changed files with 53 additions and 12 deletions
|
@ -17,6 +17,17 @@ io.load_nasal(nasal_dir ~ '/GUI.nas', "fg1000");
|
||||||
|
|
||||||
var FG1000 = {
|
var FG1000 = {
|
||||||
|
|
||||||
|
_instance : nil,
|
||||||
|
|
||||||
|
# Factory method
|
||||||
|
getInstance : func(EIS_Class = nil, EIS_SVG = nil) {
|
||||||
|
if (FG1000._instance == nil) {
|
||||||
|
FG1000._instance = FG1000.new(EIS_Class, EIS_SVG);
|
||||||
|
}
|
||||||
|
|
||||||
|
return FG1000._instance;
|
||||||
|
},
|
||||||
|
|
||||||
new : func(EIS_Class = nil, EIS_SVG = nil) {
|
new : func(EIS_Class = nil, EIS_SVG = nil) {
|
||||||
var obj = {
|
var obj = {
|
||||||
parents : [FG1000],
|
parents : [FG1000],
|
||||||
|
@ -51,8 +62,18 @@ setEIS : func(EIS_Class, EIS_SVG) {
|
||||||
me.EIS_SVG = EIS.SVG;
|
me.EIS_SVG = EIS.SVG;
|
||||||
},
|
},
|
||||||
|
|
||||||
addMFD : func(index, targetcanvas=nil, screenObject=nil) {
|
getDisplay : func(index) {
|
||||||
if (me.displays[index] != nil) {
|
return me.displays[index];
|
||||||
|
},
|
||||||
|
|
||||||
|
# Add an MFD, optionally setting the index. Returns the index of the MFD.
|
||||||
|
addMFD : func(index=nil, targetcanvas=nil, screenObject=nil) {
|
||||||
|
|
||||||
|
if (index == nil) {
|
||||||
|
index = size(keys(me.displays));
|
||||||
|
debug.dump(keys(me.displays));
|
||||||
|
print("No index passed. Defaulting to " ~ index);
|
||||||
|
} else if (me.displays[index] != nil) {
|
||||||
print("FG1000 Index " ~ index ~ " already exists!");
|
print("FG1000 Index " ~ index ~ " already exists!");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -68,6 +89,7 @@ addMFD : func(index, targetcanvas=nil, screenObject=nil) {
|
||||||
|
|
||||||
var mfd = fg1000.MFD.new(me, me.EIS_Class, me.EIS_SVG, targetcanvas, index);
|
var mfd = fg1000.MFD.new(me, me.EIS_Class, me.EIS_SVG, targetcanvas, index);
|
||||||
me.displays[index] = mfd;
|
me.displays[index] = mfd;
|
||||||
|
return index;
|
||||||
},
|
},
|
||||||
|
|
||||||
display : func(index, target_object=nil) {
|
display : func(index, target_object=nil) {
|
||||||
|
@ -89,7 +111,7 @@ displayGUI : func(index, scale=1.0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var mfd_canvas = me.displays[index].getCanvas();
|
var mfd_canvas = me.displays[index].getCanvas();
|
||||||
var gui = fg1000.GUI.new(mfd_canvas, index, scale);
|
var gui = fg1000.GUI.new(me.displays[index], mfd_canvas, index, scale);
|
||||||
},
|
},
|
||||||
|
|
||||||
getConfigStore : func() {
|
getConfigStore : func() {
|
||||||
|
|
|
@ -72,11 +72,11 @@ var GUI =
|
||||||
{ Id: 12, top_left: [1145, 830], bottom_right: [1200, 875] },
|
{ Id: 12, top_left: [1145, 830], bottom_right: [1200, 875] },
|
||||||
],
|
],
|
||||||
|
|
||||||
new : func(mfd_canvas, device_id, scale = 1.0)
|
new : func(mfd, mfd_canvas, device_id, scale = 1.0)
|
||||||
{
|
{
|
||||||
var obj = {
|
var obj = {
|
||||||
parents : [ GUI ],
|
parents : [ GUI ],
|
||||||
mfd : nil,
|
mfd : mfd,
|
||||||
eisPublisher : nil,
|
eisPublisher : nil,
|
||||||
navcomPublisher : nil,
|
navcomPublisher : nil,
|
||||||
navcomUpdater : nil,
|
navcomUpdater : nil,
|
||||||
|
@ -171,6 +171,9 @@ var GUI =
|
||||||
|
|
||||||
cleanup : func()
|
cleanup : func()
|
||||||
{
|
{
|
||||||
|
# Clean up the MFD. Particularly important to stop if picking up
|
||||||
|
# Emesary notifications.
|
||||||
|
me.mfd.del();
|
||||||
# Clean up the window itself
|
# Clean up the window itself
|
||||||
call(canvas.Window.del, [], me.window);
|
call(canvas.Window.del, [], me.window);
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,6 +13,17 @@ io.load_nasal(nasal_dir ~ 'Interfaces/GenericADCPublisher.nas', "fg1000");
|
||||||
|
|
||||||
var GenericInterfaceController = {
|
var GenericInterfaceController = {
|
||||||
|
|
||||||
|
_instance : nil,
|
||||||
|
|
||||||
|
# Factory method
|
||||||
|
getInstance : func() {
|
||||||
|
if (GenericInterfaceController._instance == nil) {
|
||||||
|
GenericInterfaceController._instance = GenericInterfaceController.new();
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenericInterfaceController._instance;
|
||||||
|
},
|
||||||
|
|
||||||
new : func() {
|
new : func() {
|
||||||
var obj = {
|
var obj = {
|
||||||
parents : [GenericInterfaceController],
|
parents : [GenericInterfaceController],
|
||||||
|
|
|
@ -69,7 +69,7 @@ var DirectTo =
|
||||||
# We will use the screen range for zooming.
|
# We will use the screen range for zooming.
|
||||||
obj.DirectToChart.setRange(8.0);
|
obj.DirectToChart.setRange(8.0);
|
||||||
obj.DirectToChart.setScreenRange(300/2.0);
|
obj.DirectToChart.setScreenRange(300/2.0);
|
||||||
obj.DirectToChart.setTranslation(1045, 485);
|
obj.DirectToChart.setTranslation(860, 440);
|
||||||
obj.DirectToChart.set("clip-frame", canvas.Element.LOCAL);
|
obj.DirectToChart.set("clip-frame", canvas.Element.LOCAL);
|
||||||
obj.DirectToChart.set("clip", "rect(-160px, 160px, 160px, -160px)");
|
obj.DirectToChart.set("clip", "rect(-160px, 160px, 160px, -160px)");
|
||||||
|
|
||||||
|
|
|
@ -827,16 +827,21 @@
|
||||||
<command>nasal</command>
|
<command>nasal</command>
|
||||||
<script>
|
<script>
|
||||||
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
|
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
|
||||||
io.load_nasal(nasal_dir ~ 'FG1000.nas', "fg1000");
|
if (! defined("fg1000")) {
|
||||||
io.load_nasal(nasal_dir ~ 'Interfaces/GenericInterfaceController.nas', "fg1000");
|
print("Loading FG1000 libraries");
|
||||||
|
io.load_nasal(nasal_dir ~ 'FG1000.nas', "fg1000");
|
||||||
|
io.load_nasal(nasal_dir ~ 'Interfaces/GenericInterfaceController.nas', "fg1000");
|
||||||
|
}
|
||||||
|
|
||||||
var fg1000system = fg1000.FG1000.new();
|
var fg1000system = fg1000.FG1000.getInstance();
|
||||||
fg1000system.addMFD(0);
|
var index = fg1000system.addMFD();
|
||||||
fg1000system.displayGUI(0);
|
print("Index " ~ index);
|
||||||
|
fg1000system.displayGUI(index);
|
||||||
|
|
||||||
# Start the interface controller after the FG1000, as it will publish
|
# Start the interface controller after the FG1000, as it will publish
|
||||||
# immediately and update the NAV/COM data.
|
# immediately and update the NAV/COM data.
|
||||||
var interfaceController = fg1000.GenericInterfaceController.new();
|
var interfaceController = fg1000.GenericInterfaceController.getInstance();
|
||||||
|
interfaceController.stop();
|
||||||
interfaceController.start();
|
interfaceController.start();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue