Skip to content

Commit 4fd096c

Browse files
committed
Add tutorial for the PDK
1 parent 0ea640e commit 4fd096c

14 files changed

+1494
-2978
lines changed

.editorconfig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
root = true
21

32
[*]
3+
# Non-configurable Prettier behaviors
4+
charset = utf-8
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
# Configurable Prettier behaviors
9+
# (change these if your Prettier config differs)
410
end_of_line = lf
5-
insert_final_newline = true
11+
indent_style = space
12+
indent_size = 2
13+
max_line_length = 80
File renamed without changes.
38.5 KB
Loading
File renamed without changes.
File renamed without changes.

docs/acars/customizing/tutorial.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
id: tutorial
3+
title: Plugin Tutorial
4+
---
5+
6+
# Setting Up Your Environment
7+
8+
You are required to have Node.js installed on your machine. You can download it
9+
from [here](https://nodejs.org/en/download/).
10+
11+
Create a new plugin repository by cloning the [acars-pdk](https://github.com/phpvms/acars-pdk) repository by
12+
clicking "Use this template", and then "Creat a new repository"
13+
14+
![](img/clone-repo.png)
15+
16+
Clone your new repository to your local machine
17+
18+
1. Copy the `.env.example` to `.env`
19+
2. Edit the file to set your `ACARS_PROFILE_NAME`
20+
3. Run `npm install`
21+
22+
```dotenv
23+
# This is the profile name to use when exporting
24+
ACARS_PROFILE_NAME=phpvms.net
25+
26+
# This is the path to the configuration root
27+
ACARS_CONFIG_PATH=$HOME/Documents/vmsacars
28+
29+
# This is the path to where the scripts, etc are stored
30+
# It's used in the live-watch
31+
ACARS_SCRIPTS_PATH=$HOME/Documents/vmsacars/data/$ACARS_PROFILE_NAME/config
32+
33+
# Name of the distribution zip file that's created
34+
ACARS_DIST_ZIP=dist.zip
35+
36+
```
37+
38+
---
39+
40+
# Creating a rule
41+
42+
Create a rule file under `src/rules/example.ts`, and you can use the following:
43+
44+
```typescript
45+
/**
46+
* This is an example rule that you can use as a template
47+
*/
48+
import { Meta, Rule, RuleValue } from '../types/rule'
49+
import { Pirep, Telemetry } from '../types/types'
50+
import { PirepState } from '../defs.js'
51+
52+
/**
53+
* This is the rule class that will be used to check the rule
54+
* The name doesn't really matter, but it should be unique
55+
*/
56+
export default class ExampleRule implements Rule {
57+
58+
/*
59+
* You can look at the definition of Meta for the fields
60+
* But you can also add additional fields for your rule
61+
* if you want
62+
*/
63+
meta: Meta = {
64+
id: 'ExampleRule',
65+
name: 'An Example Rule',
66+
enabled: true,
67+
message: 'A example rule!',
68+
states: [],
69+
repeatable: false,
70+
cooldown: 60,
71+
max_count: 3,
72+
points: -1,
73+
delay_time: 5000,
74+
}
75+
76+
violated(pirep: Pirep, data: Telemetry, previousData?: Telemetry): RuleValue {
77+
78+
/*
79+
* This will check that this rule has been violated
80+
* for this number of milliseconds specified in the
81+
* delay_time
82+
*/
83+
return Acars.ViolatedAfterDelay(
84+
this.meta.name,
85+
this.meta.delay_time,
86+
(): RuleValue => {
87+
return ['The example was violated!', this.meta.points]
88+
},
89+
)
90+
}
91+
}
92+
```
93+
94+
# Compile and Build
95+
96+
Run the following to compile the Typescript and build the distribution:
97+
98+
```bash
99+
npm run local
100+
```
101+
102+
This will also watch the `src/` directory for changes and recompile and copy
103+
them. Next, launch ACARS, and start a flight. In the logs, you should see a log
104+
that looks like:
105+
106+
107+
> Adding module file:///path/to/data/phpvms.net/config/aircraft/example.js
108+
109+
Now the above rule won't do anything, because we haven't added any active states.
110+
Make sure that you're still running the above `npm run local` command, and let's
111+
change the rule to add states it's valid in:
112+
113+
```typescript
114+
meta: Meta = {
115+
// ...
116+
states: [PirepState.Boarding],
117+
// ...
118+
}
119+
```
120+
121+
You should see the rule being copied to the directory, and then ACARS reloading
122+
the rules:
123+
124+
> Detected change in space=rules; file=example.js; type="Changed"
125+
126+
And then you should see some logs about the rule being run:
127+
128+
> Starting timer for An Example Rule_violated_after\
129+
> Rule: An Example Rule - Timer delay of 5993.9036 passed, marking violated\
130+
> Rule: An Example Rule, rule: The example was violated!, -1 points\
131+
> Violation: An Example Rule (1x) - The example was violated!;
132+
133+
# Distribute
134+
135+
Now that you have your rule, you can distribute it to other users. Run the
136+
following to create a distribution zip file:
137+
138+
```bash
139+
npm run export
140+
```
141+
142+
This will create a zip file in the `dist/` directory, by default it's named
143+
`dist.zip`. You can rename this in the `.env` file. Upload this file somewhere,
144+
and then, in the ACARS web module, set the URL. It will then get downloaded by
145+
ACARS and loaded in.

0 commit comments

Comments
 (0)