-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathfacilitiesMenu.ts
168 lines (152 loc) · 4.81 KB
/
facilitiesMenu.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import {
open,
Protocol,
RecvEvent,
TextType,
TextResult,
FacilityListType,
NotificationPriority,
} from '../../dist';
/**
* SimConnect FaciliitesData sample
*
* Description:
* Ctrl F1 displays the Get Facilities menu on the screen
* Ctrl F2 displays the Subscribe to Faciliites menu on the screen
*
*/
enum NotificationGroupID {
GROUP0,
}
enum EventID {
OPEN_MENU_1,
OPEN_MENU_2,
EVENT_MENU_1,
EVENT_MENU_2,
}
enum InputGroupID {
INPUT0,
}
enum RequestID {
REQUEST_0,
REQUEST_1,
}
const GET_FACILITIES_MENU_OPTIONS: string[] = [
'Get airport facilities',
'Get waypoints',
'Get NDB',
'Get VOR',
'Close menu',
];
const SUBSCRIBE_FACILITIES_MENU_OPTIONS: string[] = [
'Subscribe to airports',
'Subscribe to waypoints',
'Subscribe to NDB',
'Subscribe to VOR',
'Unsubscribe to airports',
'Unsubscribe to waypoints',
'Unsubscribe to NDB',
'Unsubscribe to VOR',
'Close menu',
];
open('My app', Protocol.FSX_SP2)
.then(({ recvOpen, handle }) => {
console.log('Connected: ', recvOpen);
handle.mapClientEventToSimEvent(EventID.OPEN_MENU_1);
handle.mapClientEventToSimEvent(EventID.OPEN_MENU_2);
handle.addClientEventToNotificationGroup(
NotificationGroupID.GROUP0,
EventID.OPEN_MENU_1,
true
);
handle.addClientEventToNotificationGroup(
NotificationGroupID.GROUP0,
EventID.OPEN_MENU_2,
true
);
handle.setNotificationGroupPriority(
NotificationGroupID.GROUP0,
NotificationPriority.HIGHEST
);
handle.mapInputEventToClientEvent(
InputGroupID.INPUT0,
'Ctrl+F1',
EventID.OPEN_MENU_1
);
handle.mapInputEventToClientEvent(
InputGroupID.INPUT0,
'Ctrl+F2',
EventID.OPEN_MENU_2
);
handle.setInputGroupState(InputGroupID.INPUT0, true);
handle.text(TextType.PRINT_RED, 15, 3, 'Facilities Data');
handle.text(
TextType.PRINT_RED,
15,
3,
'Press Ctrl-F1 for Get Facilities, Ctrl-F2 for Subscribe to Facilities'
);
handle.on('event', ({ clientEventId, data }: RecvEvent) => {
switch (clientEventId) {
case EventID.OPEN_MENU_1:
openMenu(GET_FACILITIES_MENU_OPTIONS);
break;
case EventID.OPEN_MENU_2:
openMenu(SUBSCRIBE_FACILITIES_MENU_OPTIONS);
break;
case EventID.EVENT_MENU_1:
{
if (data > TextResult.MENU_SELECT_10) return;
if (data < FacilityListType.COUNT) {
handle.requestFacilitiesList(
data as FacilityListType,
RequestID.REQUEST_0
);
}
}
break;
case EventID.EVENT_MENU_2:
{
if (data > TextResult.MENU_SELECT_10) return;
if (data < FacilityListType.COUNT) {
handle.subscribeToFacilities(
data as FacilityListType,
RequestID.REQUEST_1
);
} else if (data < 2 * FacilityListType.COUNT) {
handle.unSubscribeToFacilities(
(data -
FacilityListType.COUNT) as FacilityListType
);
}
}
break;
}
});
function openMenu(items: string[]) {
handle.menu(
0.0,
EventID.EVENT_MENU_1,
'SimConnect Facilities Test',
'Choose which item:',
...items
);
}
handle.on('airportList', (recvAirportList) => {
console.log(recvAirportList.airports.map((ap) => ap.icao).join(','));
});
handle.on('ndbList', (recvNDBList) => {
console.log(recvNDBList.ndbs.map((ndb) => ndb.icao).join(','));
});
handle.on('vorList', (recvVORList) => {
console.log(recvVORList.vors.map((vor) => vor.icao).join(','));
});
handle.on('waypointList', (recvWaypointList) => {
console.log(
recvWaypointList.waypoints.map((wp) => wp.icao).join(',')
);
});
})
.catch((error) => {
console.log('Failed to connect', error);
});