1
0
Fork 0

Factory methods for FG1000

- Use Factories to handle multiple FG1000 calls better.
- Fix DirectTo Map center.
This commit is contained in:
Stuart Buchanan 2018-02-09 17:26:57 +00:00
parent 9156006183
commit be5e16f382
5 changed files with 53 additions and 12 deletions

View file

@ -17,6 +17,17 @@ io.load_nasal(nasal_dir ~ '/GUI.nas', "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) {
var obj = {
parents : [FG1000],
@ -51,8 +62,18 @@ setEIS : func(EIS_Class, EIS_SVG) {
me.EIS_SVG = EIS.SVG;
},
addMFD : func(index, targetcanvas=nil, screenObject=nil) {
if (me.displays[index] != nil) {
getDisplay : func(index) {
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!");
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);
me.displays[index] = mfd;
return index;
},
display : func(index, target_object=nil) {
@ -89,7 +111,7 @@ displayGUI : func(index, scale=1.0) {
}
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() {

View file

@ -72,11 +72,11 @@ var GUI =
{ 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 = {
parents : [ GUI ],
mfd : nil,
mfd : mfd,
eisPublisher : nil,
navcomPublisher : nil,
navcomUpdater : nil,
@ -171,6 +171,9 @@ var GUI =
cleanup : func()
{
# Clean up the MFD. Particularly important to stop if picking up
# Emesary notifications.
me.mfd.del();
# Clean up the window itself
call(canvas.Window.del, [], me.window);
},

View file

@ -13,6 +13,17 @@ io.load_nasal(nasal_dir ~ 'Interfaces/GenericADCPublisher.nas', "fg1000");
var GenericInterfaceController = {
_instance : nil,
# Factory method
getInstance : func() {
if (GenericInterfaceController._instance == nil) {
GenericInterfaceController._instance = GenericInterfaceController.new();
}
return GenericInterfaceController._instance;
},
new : func() {
var obj = {
parents : [GenericInterfaceController],

View file

@ -69,7 +69,7 @@ var DirectTo =
# We will use the screen range for zooming.
obj.DirectToChart.setRange(8.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", "rect(-160px, 160px, 160px, -160px)");

View file

@ -827,16 +827,21 @@
<command>nasal</command>
<script>
var nasal_dir = getprop("/sim/fg-root") ~ "/Aircraft/Instruments-3d/FG1000/Nasal/";
io.load_nasal(nasal_dir ~ 'FG1000.nas', "fg1000");
io.load_nasal(nasal_dir ~ 'Interfaces/GenericInterfaceController.nas', "fg1000");
if (! defined("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();
fg1000system.addMFD(0);
fg1000system.displayGUI(0);
var fg1000system = fg1000.FG1000.getInstance();
var index = fg1000system.addMFD();
print("Index " ~ index);
fg1000system.displayGUI(index);
# Start the interface controller after the FG1000, as it will publish
# immediately and update the NAV/COM data.
var interfaceController = fg1000.GenericInterfaceController.new();
var interfaceController = fg1000.GenericInterfaceController.getInstance();
interfaceController.stop();
interfaceController.start();
</script>