v1.2.0.1-beta1
|
Functions, data, and events for interacting with Touch Portal directly, such as updating state values or sending notifications.
These functions are part of the global TP
namespace, used with TP.
qualifier, eg. TP.stateUpdate("Hello!");
.
Note that the "Touch Portal API" documented here, while closely related to Touch Portal's Plugin API, is not always an exact match, nor can always provide all the features a full plugin could have (such as custom Actions). Nevertheless it can be helpful to understand how Touch Portal interacts with data sent from plugins in the first place, since all those limits would apply here as well (in other words, this plugin can only work with the API features which are available to us in the first place).
Members | |
class | TP |
class | ConnectorRecord |
Sending Data | |
These functions all send information or commands to Touch Portal. | |
void | stateUpdate (String value) |
void | stateUpdate (String name, String value) |
void | stateUpdateById (String id, String value) |
void | stateCreate (String id, String parentGroup, String desc="", String defaultValue="") |
void | stateRemove (String id) |
void | choiceUpdate (String id, Array< String > values) |
void | choiceUpdateInstance (String id, String instanceId, Array< String > values) |
void | connectorUpdate (String shortId, int value) |
void | connectorUpdateByLongId (String connectorId, int value) |
void | showNotification (String notificationId, String title, String message, Array< Object > options=[],< Function|String|Array > callback=null) |
void | settingUpdate (String name, String value) |
Events | |
These are events which are raised whenever some kind of data update is received from Touch Portal. Events may pass one or more parameters to callback handlers (check documentation for specific events). There are two syntactical ways to connect a callback function to an event. First is by using the usual 'on*' style syntax: TP.oneventName( (parameters) => { .... } );
The global TP namespace is used as a container for all Touch Portal API methods, which are invoked wi... Definition: touchportal.dox:7 The other way is with the TP.eventName.connect( (parameters) => { .... } );
Both forms have a 2-parameter version which allows a context object to be given, which then becomes the "this" object when the event handler callback is executed. | |
void | messageEvent (Object message) |
void | broadcastEvent (String event, Object data) |
void | connectorIdsChanged (String instanceName, String shortId) |
Connector Data | |
Touch Portal reports connector instances to the plugin via These messages are parsed and logged into a database. The functions in this group can be used to query the data based on various criteria about logged connectors. The connector short IDs can then be used to send updates back to Touch Portal, which will move the corresponding slider(s) into a particular position. | |
Array< String > | getConnectorShortIds (Object criteria={}) |
Array< ConnectorRecord > | getConnectorRecords (Object criteria={}) |
ConnectorRecord | getConnectorByShortId (String shortId) |
Other Data | |
Miscellaneous other data/information access functions. | |
String | currentPageName () |
|
static |
Send a State update to Touch Portal with given value
for the current script instance.
This only works with instances in a Private
script engine.
Send a State update to Touch Portal for a DSE instance named name
with given value
.
This works with any type of engine instance, Shared
or Private
. The name
will be turned into a fully qualified state ID as necessary (adding the required prefix to match default DSE state IDs).
Send a State update to Touch Portal for any arbitrary state/value matching the id
, with given value
.
|
static |
Create a new Touch Portal dynamic State (if it doesn't already exist).
id | Must be a fully qualified state ID (meaning it is not changed in any way and must be unique in TP). |
parentGroup | Sets or creates the sorting category into which the state is placed in the user interface (it will show up as a child of this plugin's states list). |
desc | This text will be used in the Touch Portal interface to represent the new state (optional if you don't need it selectable in TP UI). |
defaultValue | An optional default value for the state, meaning it's initial value. |
Note that if you do not want/need a state to be available in the UI, then any stateUpdateById()
call will also work (the state will be created if needed but not accessible via the UI).
Also note that there's currently a bug in TP (<= v3.1) that prevents state change events from being detected based on a default value.
|
static |
Remove a Touch Portal dynamic State (if it exists).
The id
must be fully qualified to match the ID of the existing state.
Update a list of choices for a selector with given id
, which must be a fully qualified ID of some existing action data member (from some plugin).
values
should be an array of strings.
Update a list of choices for a selector with given id
and specific instanceId
.
id
must be a fully qualified ID of some existing action data member.
instanceId
is the internal Touch Portal ID of a specific action instance. This is typically obtained from a 'listChange' Touch Portal message, but could also be obtained from the button ID or page source code.
values
should be an array of strings.
|
static |
Sends a connector (slider) update with given value
which should be an integer in the range of 0 - 100.
The shortId
should be a Touch Portal "short connector ID" as reported by Touch Portal in shortConnectorIdNotification
messages.
These IDs can be looked up using TP.getShortConnectorIds()
method. Another option is to subscribe to the TP.connectorIdsChanged()
event and track any reported connectors that way. Another, somewhat slower, option is to retrieve a list of reported short IDs with TP.getConnectorRecords()
and further process the result(s) to find the connector(s) you're looking for.
Note that is also possible to find these short IDs in the source JSON of a Touch Portal page (.tml file). Not recommended, but it can do in a pinch.
|
static |
Sends a connector (slider) update with given value
which should be an integer in the range of 0 - 100.
The connectorId
must be fully qualified "long ID" as described in Touch Portal API docs.
This method could in theory be used to update sliders with connectors provided by other plugins. In practice it is fairly limited since the full connectorId
must be 200 characters or less, and coming up with those IDs in the first place can be challenging. However you may find some use for it after all.
|
static |
Creates or raises a user notification in the Touch Portal window.
See TP API docs for details on notifications.
notificationId | should be a unique string, if the user has already responded to a notification with the same notificationId then nothing will be shown. |
title | This will be shown at the top of the notification window. |
message | This is the body of the notification, the main text. |
options | This is an optional array of "choice" objects which are presented in the notification for user to click on. For example: [
{
"id":"option1",
"title":"Option 1 title"
},
{
"id":"option2",
"title":"Option 2 title"
}
]
|
callback | A callback to invoke when one of the options is clicked. The callback value can be a string, function, or an array.
|
Update a plugin Setting in Touch Portal named name
to value
.
This only works for settings of the current plugin (defined in corresponding entry.tp).
|
static |
This event is emitted upon every Touch Portal message received by this plugin.
The message
parameter is an object representing the "raw" message data received from Touch Portal (originally as a JSON object). Each message will have a type
property indicating the message type. Refer to Touch Portal API for further details on each message type and data it contains.
|
static |
This event is emitted when Touch Portal sends a broadcast
message to all plugins.
The event
parameter is the name of the event type.
The data
contains any further information about the event.
pageChange
event there is one member named pageName
which holds the name of the newly selected page. The name may contain a "path" if the page is in side a subfolder. For example "(main)" or "games/MSFS".You can connect to this event as described in the overall event documentation above, with either onbroadcastEvent()
or broadcastEvent.connect()
syntax.
This event is emitted whenever a shortConnectorIdNotification
message from Touch Portal has been received, parsed, and added to the tracking database.
The first parameter passed to event handlers is the State Name used in the connector which has been added/modified. Note that for all "Anonymous (One-Time)" type connectors the instanceName
will always be "ANONYMOUS".
The second parameter is the shortId
of this slider instance as created by Touch Portal. This short ID can be used later to send updates back to this slider.
You can connect to this event as described in the overall event documentation above, with either onconnectorIdsChanged()
or connectorIdsChanged.connect()
syntax.
|
static |
Returns zero or more connector "short IDs" based on the given criteria
from the currently logged connector notification data.
criteria
is an object that can contain any of the properties of ConnectorRecord
(unless explicitly documented otherwise). For most properties wildcard patterns can be used in the values (again, check ConnectorRecord
documentation for details on each property).
For example, to find a Slider instance short ID for a connector with which loads a "example.mjs" module script and invokes a "run()" function with any parameters:
Wildcards are typical "GLOB" style: *
for "match anything", ?
for "any one character", or [xyz]
to match any of a set of characters.
As noted in the ConnectorRecord
documentation, some enumeration type properties can only be matched by their full value, like ConnectorRecord.actionType
.
If criteria
is empty/null/undefined, then all connector records currently in the database will be returned.
By default the results are sorted by newest first, that is by the timestamp
property in descending (largest first) order. To specify a custom sort order, add the special property orderBy
to the search criteria
. The value of orderBy
can be the name of any of the ConnectorRecord
properties, optionally followed by ASC
or DESC
to specify the ordering for ascending (smaller first) or descending (largest first), respectively. Default is ascending order ("ASC"). Multiple properties can also be specified by separating them with a comma.
For example to find a all sliders for the current engine instance by State Name, sorted by oldest first and then by expression value in reverse alphabetical order:
|
static |
Returns zero or more ConnectorRecord
objects based on the given criteria
from the currently logged connector notification data.
criteria
is exactly the same as described for getConnectorShortIds()
function, above.
The only difference here is that the results include the whole ConnectorRecord
object, instead of just the shortId
property. The objects can then be further examined as needed. Keep in mind these are all read-only results.
|
static |
Returns a ConnectorRecord
based on the given shortId
from the currently logged connector notification data, if any.
If no matching record is found, the returned ConnectorRecord
will be empty/null, which can be checked with ConnectorRecord.isNull
property.
Short IDs are unique, so each one identifies a unique slider instance. This function could be particularly useful with the TP.connectorIdsChanged()
event to get more information about the new slider short ID which is passed by that event to handlers as the 2nd parameter.
You can use a wildcard pattern in the shortId
parameter, as described in previous documentation about search criteria. However this query will always return only one record. If the wildcard pattern matches multiple records, only the newest one (by timestamp
) will be returned.
|
static |
Returns the name of the page the user last opened on their Touch Portal device (not in the desktop page editor).
This is always the result of the last broadcastEvent()
's pageName
property. See broadcastEvent()
documentation for details.