Skip to content

Commit 85f7073

Browse files
committed
Updated example and build script
1 parent 5c4faac commit 85f7073

File tree

5 files changed

+103
-26
lines changed

5 files changed

+103
-26
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
## Overview
44

55
The plugins and scripts for vmsACARS are written in Typescript, and then
6-
transpiled to JS.
7-
Typescript ensures that the interfaces required are following, and that the
8-
proper things
9-
are returned so ACARS can run them. While Typescript isn't required, it's best
10-
to use it to
11-
ensure proper values are passed - especially around enums.
6+
transpiled to JS. Typescript ensures that the interfaces required are following,
7+
and that the proper things are returned so ACARS can run them. While Typescript
8+
isn't required, it's best to use it to ensure proper values are passed - especially
9+
around enums.
1210

1311
This PDK includes build scripts to:
1412

@@ -19,11 +17,15 @@ This PDK includes build scripts to:
1917

2018
---
2119

20+
# Structure
21+
22+
All of the scripts are contained in the `/src` folder.
23+
2224
# Setup
2325

2426
## Required:
2527

26-
- nodejs/npm
28+
- nodejs/npm or pnpm
2729
- Typescript
2830
- Gulp
2931

@@ -681,3 +683,9 @@ export default class MyScript implements CallbackHook {
681683
}
682684
}
683685
```
686+
687+
### Sounds
688+
689+
Place your sounds (`mp3` or `wav`) format in the `src/sounds` directory (create
690+
it if it doesn't exist). When you call `Acars.PlayAudio`, it will look in this
691+
directory for them.

gulpfile.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const paths = {
2929
* Build the project, copy the appropriate files over
3030
* @public
3131
*/
32-
export const build = series(buildTsTask, copyPackageJsonTask)
32+
export const build = series(buildTsTask, copySoundsTask, copyPackageJsonTask)
3333

3434
/**
3535
* Clean the build directories
@@ -108,6 +108,14 @@ function buildTsTask() {
108108
return pipeline
109109
}
110110

111+
/**
112+
* This copies the package.json file to the output directory
113+
*
114+
*/
115+
function copySoundsTask() {
116+
return src([paths.src + '/sounds/**/*']).pipe(dest(paths.out + '/sounds'))
117+
}
118+
111119
/**
112120
* This copies the package.json file to the output directory
113121
*

src/scripts/announcements.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { PirepState } from '../defs'
2+
import { CallbackHook, Meta } from '../types/callback'
3+
import { Pirep, Telemetry } from '../types/types'
4+
5+
/**
6+
* This is an example of a script which does announcements on the different
7+
* flight phases. It's missing the audio files - place your files into the
8+
* `sounds` directory, and then package up the script.
9+
*
10+
* See the phaseChange() method for the meat of it. Note, this is also disabled
11+
* by default
12+
*/
13+
export default class Annoucements implements CallbackHook {
14+
meta: Meta = {
15+
id: 'default_announcements',
16+
name: 'Default phase change announcements',
17+
enabled: false,
18+
}
19+
20+
setup() {}
21+
22+
/**
23+
* This runs about once a second, sometimes more
24+
* @param pirep
25+
* @param data
26+
*/
27+
run(pirep: Pirep, data: Telemetry): void {}
28+
29+
/**
30+
* Play these sounds on the different phase changes
31+
*
32+
* @param pirep
33+
* @param data
34+
* @param newPhase
35+
* @param oldPhase
36+
*/
37+
phaseChange(
38+
pirep: Pirep,
39+
data: Telemetry,
40+
newPhase: PirepState,
41+
oldPhase: PirepState,
42+
) {
43+
if (newPhase == PirepState.Pushback) {
44+
Acars.PlayAudio('pushback.mp3')
45+
} else if (newPhase == PirepState.TaxiIn) {
46+
Acars.PlayAudio('taxi_in.mp3')
47+
} else if (newPhase == PirepState.TaxiOut) {
48+
Acars.PlayAudio('taxi_out.mp3')
49+
} else if (newPhase == PirepState.Takeoff) {
50+
Acars.PlayAudio('takeoff.mp3')
51+
} else if (newPhase == PirepState.Enroute) {
52+
Acars.PlayAudio('enroute.mp3')
53+
} else if (newPhase == PirepState.Approach) {
54+
Acars.PlayAudio('approach.mp3')
55+
} else if (newPhase == PirepState.Final) {
56+
Acars.PlayAudio('landing.mp3')
57+
} else if (newPhase == PirepState.Landed) {
58+
Acars.PlayAudio('landing.mp3')
59+
} else if (newPhase == PirepState.Arrived) {
60+
Acars.PlayAudio('arrived.mp3')
61+
}
62+
}
63+
}

src/scripts/example.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,33 @@ export default class ExampleScript implements CallbackHook {
1414
}
1515

1616
setup() {
17-
Acars.Set('above_1k', false)
18-
Acars.Set('launched_message', false)
17+
Acars.Set('above_18k', false)
1918
}
2019

2120
/**
22-
* This once a second.
21+
* This runs about once a second.
2322
* @param pirep
2423
* @param data
2524
*/
2625
run(pirep: Pirep, data: Telemetry): void {
2726
Acars.AddPirepLogOnce('script_loaded', 'Example script loaded')
28-
if (Acars.Get('launched_message') === false) {
29-
Acars.SetPirepField('Loaded', 'True')
27+
Acars.SetPirepField('Example Script Loaded', 'True')
3028

31-
Acars.Set('launched_message', true)
32-
}
29+
this.descentAnnouncement(data)
30+
}
3331

34-
if (data.groundAltitude.Feet > 1000) {
35-
Acars.Set('above_1k', true)
36-
Acars.SetPirepField('Above 1000 feet', 'True')
32+
/**
33+
* See if we should play the descent announcement. It should only play
34+
* if we were above 18k', and now are below 16k or so
35+
* @param data
36+
*/
37+
descentAnnouncement(data: Telemetry) {
38+
if (data.groundAltitude.Feet > 18000) {
39+
Acars.Set('above_18k', false)
3740
}
3841

39-
/*
40-
* Just a silly example, if they crossed above 1000 feet and then they went
41-
* back below it, send a message about that
42-
*/
43-
if (Acars.Get('above_1k') === true && data.groundAltitude.Feet < 1000) {
44-
Acars.AddPirepLog("Went above 1000', now back down")
42+
if (data.groundAltitude.Feet < 16000 && Acars.Get('above_18k')) {
43+
Acars.PlayAudio('descent_annoucement.mp3')
4544
}
4645
}
4746

@@ -58,9 +57,8 @@ export default class ExampleScript implements CallbackHook {
5857
newPhase: PirepState,
5958
oldPhase: PirepState,
6059
) {
61-
Acars.AddPirepLog(`Phase changed from ${oldPhase} to ${newPhase}`)
6260
if (newPhase == PirepState.Pushback) {
63-
Acars.PlayAudio('departure.mp3')
61+
Acars.PlayAudio('pushback.mp3')
6462
}
6563
}
6664
}

src/sounds/empty

Whitespace-only changes.

0 commit comments

Comments
 (0)