Skip to content

Commit

Permalink
document extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Jul 1, 2023
1 parent 664f89d commit c943b4d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,40 @@ When DCS starts, the Scratchpad looks for all text files inside the `Scratchpad\

This is only available in single player or for servers that have _Allow Player Export_ enabled. If available, you'll have a checkbox at the bottom for the Scratchpad. The mode to insert coordinates is active while the checkbox is checked. While active, you'll have a white dot in the center of your screen and an additional `+ L/L` button below the text area of the Scratchpad. Open the F10 map and align the white dot with your location of interest and hit the `+ L/L` button. This will add the coordinates of the location below the white cursor to your Scratchpad.

### Insert waypoints into the NS430

Hitting the `+L/L` button in spectator or an aircraft that can use the NS430 inserts a line that looks like `FIX;-88.245167;36.117167;%PlaceholderName`. The `%PlaceholderName` must be changed to a 1-5 character long alpha-numeric string (e.g. `1A`, `1B`, `2`, `3`, `WILLO`). This can then be added into the `navaids.dat` in the main DCS folder `.\DCS World OpenBeta\Mods\aircraft\NS430\Cockpit\Scripts\avionics\terrain\navaids.dat` (you need to respawn for the `navaids.dat` changes to take effect) and then be loaded into the NS430 via the Flight Plan Page or Direct-To page.

## Extensions

Scratchpad supports extensions. Most prominent use-case is to add a virtual keyboard. There are some example extensions in `Saved Games\DCS.openbeta\Scripts\Scratchpad\Extensions\Disabled\`. To
enable any of them, copy the file over to `Saved Games\DCS.openbeta\Scripts\Scratchpad\Extensions\`.

The available APIs to the extensions are:

```lua
-- Log to `Saved Games\DCS.openbeta\Logs\Scratchpad.log`
log(text)

-- Format coordinates with `format` being either `DMS` or `DDM`, `isLat` `true` if the provided `d`
-- is the latitude, and `false` if it is the longitude, and `opts` allow to fine-tune the format
-- (checkout `Scripts/Hooks/scratchpad-hook.lua` `function coordsType()` for examples).
formatCoord(format, isLat, d, opts)

-- Add a `listener` that is executed every time the user adds a coordinate (via the +L/L button).
-- See `Extensions/Disabled/ns430.lua` for an example.
addCoordinateListener(listener(text, lat, lon, alt))

-- Add a button positioned at `left`/`top` (relative to the plugin's container), with the size of
-- `width`/`height`, the given `title` and the `onClick` callback that is executed when the button
-- is pressed.
addButton(left, top, width, height, title, onClick(text))

-- The `text` given to the `addCoordinateListener` and `onClick` callbacks can be mutated with the
-- following methods:
text:getText()
text:setText(text)
text:insertAtCursor(text)
text:insertBelowCursor(text)
text:insertTop(text)
text:insertBottom(text)
```

## Kudos

Expand Down
2 changes: 1 addition & 1 deletion Scripts/Scratchpad/Extensions/Disabled/keypad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ for _, r in pairs(keyMatrix) do
x = x + width
end
y = y + width
end
end
13 changes: 11 additions & 2 deletions Scripts/Scratchpad/Extensions/Disabled/ns430.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
-- Degree Decimal formatted to be used in NS430 navaid.dat file for flight planning purposes. Just edit the %PlaceHolderName
-- Degree Decimal formatted to be used in NS430 navaid.dat file for flight planning purposes. Just
-- edit the %PlaceHolderName.
-- With this extension active, hitting the `+L/L` button inserts a line that looks like:
-- `FIX;-88.245167;36.117167;%PlaceholderName`.
-- The `%PlaceholderName` must be changed to a 1-5 character long alpha-numeric string (e.g. `1A`,
-- `1B`, `2`, `3`, `WILLO`). This can then be added into the `navaids.dat` in the main DCS folder
-- (`DCS World OpenBeta\Mods\aircraft\NS430\Cockpit\Scripts\avionics\terrain\navaids.dat`). You need
-- to respawn for the `navaids.dat` changes to take effect. The waypoint can then be loaded into the
-- NS430 via the Flight Plan Page or Direct-To page.

addCoordinateListener(function(text, lat, lon, alt)
text:insertBelow(
"FIX;" .. formatCoord("DD", true, lon) .. ";" .. formatCoord("DD", false, lat) .. ";%PlaceHolderName\n"
)
end)
end)
2 changes: 1 addition & 1 deletion Scripts/Scratchpad/Extensions/Disabled/sitrep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

addButton(0, 0, 80, 30, "+ SITREP", function(text)
text:insertTop(DCS.getMissionDescription())
end)
end)

0 comments on commit c943b4d

Please sign in to comment.