dcs-scratchpad icon indicating copy to clipboard operation
dcs-scratchpad copied to clipboard

Add Extensions (WIP)

Open rkusa opened this issue 1 year ago • 5 comments

⚠️ This is work in progress. I am mostly exploring whether this is a useful addition. I am not yet committed to actually add this. Also keep in mind that the API exposed to extensions is subject to change.

With this PR, the Scratchpad can be extended with additional buttons, by simply adding a Lua script to DCS\Scripts\Scratchpad\Extensions\{extension_name}.lua.

This PR includes a couple of examples in Scripts/Scratchpad/Extensions.

Screenshot 2022-09-10 175359

The exmaple extensions are:

  • clear.lua: add a button to clear the current page (fixes #32)
  • keypad.lua: add a small keypad with enough buttons to insert coordinates
  • ns430.lua: listen foor coordinates and add the NS430 FIX format (as a possible replacement for having this built in)
  • sitrep.lua: add a button to copy the current mission's situation to the top of the current page

The available API to the plugins in a nutshell (proper docs are still to do):

log(text)
formatCoord(format, isLat, d, opts)
addCoordinateListener(listener(text, lat, lon, alt))

local row = addRow()
row:addButton(left, top, width, height, title, onClick(text))

text:getText()
text:setText(text)
text:insertAtCursor(text)
text:insertBelowCursor(text)
text:insertTop(text)
text:insertBottom(text)

Open questions:

  • How to handle the order of extensions?
  • Allow adding buttons to existing rows instead of always adding a new new for each extension?
  • Call them Extensions or Plugins?

Todos:

  • [ ] Document Plugin API

I'll keep this is a draft PR for a while to explore whether it ends up being useful for people and to gather some feedback about the API. If you want to try it out, you can download the version of this PR here: https://github.com/rkusa/dcs-scratchpad/archive/refs/heads/extensions.zip

If I end up adding this extensions feature, I'll be accepting community extensions into this repo. They will just not be included in the default-installation and they will rely on community contributions for maintanance.

rkusa avatar Sep 10 '22 16:09 rkusa

Suggestion from https://forum.dcs.world/topic/195700-in-game-scratchpad-mod-available-works-great-in-vr/?do=findComment&comment=5047073: add an Enter button to the keypad mod

rkusa avatar Sep 10 '22 17:09 rkusa

  • [x] Bug: When selecting text from right to left, the selection isn't replaced with insertAtCursor (neither does deleteBackward work)

rkusa avatar Sep 10 '22 17:09 rkusa

"\n" i think would do the enter button "\b" would be backspace(?) \b doesnt seem to work as backspace

speed-of-heat avatar Sep 10 '22 17:09 speed-of-heat

"\n" i think would do the enter button "\b" would be backspace(?) \b doesnt seem to work as backspace

Backspace needed indeed a new method. I've added text:deleteBackward() in the above commit.

rkusa avatar Sep 10 '22 19:09 rkusa

for extension/plugin ordering, the default to alpha ordering, adding a numeral to the front of the name will allow it to be ordered as desired

speed-of-heat avatar Sep 12 '22 12:09 speed-of-heat

The above commits contain the following API changes for extensions:

  • addRow removed, addButton can now be called directly
  • insertAtCursor renamed to insert
  • insertBelowCursor renamed to insertBelow

Furthermore, the built-in extensions included in this PR have been disabled by default (moved to DCS\Scripts\Scratchpad\Extensions\Disabled\). They have be manually copied to DCS\Scripts\Scratchpad\Extensions\ to enable (and update them).

rkusa avatar Oct 12 '22 14:10 rkusa

for extension/plugin ordering, the default to alpha ordering, adding a numeral to the front of the name will allow it to be ordered as desired

I was thinking about this too. However, I am a bit concerned about the process of updating extensions. If people have to manually copy them into the Extensions directory, and maybe even rename them, they have to repeat those steps each time there is an update.

At least for the update part, it might be better to have everything in the Extensions directory by default, but disabled, and enable plugins via the Config/ScratchpadConfig.lua, e.g.:

{
  plugins = { "ns430", "keypad" },
}

This is return makes the initial installation/activation of extensions more difficult. I am not sure yet what to make easier. Initial installation, or updates.

rkusa avatar Oct 13 '22 07:10 rkusa

for extension/plugin ordering, the default to alpha ordering, adding a numeral to the front of the name will allow it to be ordered as desired

This is return makes the initial installation/activation of extensions more difficult. I am not sure yet what to make easier. Initial installation, or updates.

How about an extension for configuring scratchpad. It could just be button interface for the config lua file. Along those lines an extension for scratchpad help that's just the help/docs for scratchpad that can be read from within scratchpad. There seems to be many uses for extensions. That said how likely is extensions to go in main, especially for those considering making extensions.

aeronautes avatar Oct 20 '22 20:10 aeronautes