Skretzo / shortest-path

Pathfinding for Old School RuneScape
BSD 2-Clause "Simplified" License
14 stars 27 forks source link

Create an interface for external plugins #48

Open jocopa3 opened 1 year ago

jocopa3 commented 1 year ago

This PR is incomplete, namely UI and API is not finalized. I'm publishing it to receive feedback from others.

Overview

A common request I see from other plugin developers is wanting some way to interface with shortest path but there currently doesn't exist a way to do so. This PR proposes a potential API that can be exposed to external plugins to allow them to make requests while also allowing users to control which paths are visible and prioritize which plugin paths should override other paths.

Notes

Video Demo

Video demonstrates that shortest-path's normal functions still work as expected, but also that other plugins (e.x. Quest Helper) can interface with it. Plugins can be re-ordered and paths hidden via the side panel. Shortest Path still tracks request/clear commands even if it's disabled so that the data remains current the next time it's enabled.

https://github.com/Skretzo/shortest-path/assets/2230152/33622cee-eed8-49d2-9b52-a416f0a0bee7

API

This initial proposal is meant to implement the bare minimum feature-set most people want and that can be easily maintained going forward. Additional features like changing pathfinding options, drawing multiple paths, changing path colors, etc., are out of the intended scope of this PR.

Plugins interface over the EventBus by passing a hashmap of type HashMap<String, Object> containing the required parameters. Any invalid requests or requests with invalid/missing parameters are ignored and a debug message printed. For simplicity, the API is entirely one-way communication and Shortest Path does not send responses or acknowledgements back to requesters. Here is a working example class that external plugins can use directly to interface with shortest path or use as a reference.

Internally, the API side is handled by ShortestPathAPI.java. It validates that the objects received are the correct types and prints debug messages when it receives invalid requests or parameters; these messages can be seen in logs or when RuneLite is run with the --debug argument.

Required Parameters

There are a few parameters that are required in all events: Key Type Description
plugin Plugin Required. A reference to the plugin making the path requests.
command String Required. Must start with shortestpath: followed by the command.

Commands

Some commands may have additional parameters as listed below.

request-path Command: Key Type Description
target WorldPoint Required. The world point for where the path ends.
start WorldPoint Optional. The world point that marks where the path should start. If missing or null, then the player's position is used as the start point.
hide-marker Boolean Optional. If the key exists and value is true, shortest path won't draw the target "marker" overlay on the world map. This is useful to plugins like Quest Helper that already draw their own world map marker.
Skretzo commented 1 year ago

All icons for UI are placeholders until I can either make new assets or find some with an agreeable license.

Both the Screen Markers plugin and the Loot Tracker plugin in core RuneLite have enable/disable icons made by Psikoi that I believe are under RuneLite's BSD-2 license.

Skretzo commented 1 year ago

Navigation Button currently uses marker.png as the plugin's icon; open to ideas for something better to use.

I like the look of that icon in the panel. It makes sense and I cannot think of anything better at the moment.

jocopa3 commented 1 year ago

Minor update: hide-marker is now a Boolean type rather than allowing any value. Since it's optional, default behavior is to show the marker, plugins are expected to set hide-marker true to disable the world map marker.

Skretzo commented 1 month ago

https://github.com/runelite/runelite/pull/16863 was added in https://github.com/runelite/runelite/commit/0b12333eafcb9ae1b394849fd65b0526a4e3a8f9