With some additions to the X-Plane SDK, I think a lot of code could be simplified. Here's what I'd love to have:
An API to notify plugins (via callback) of new/existing commands and datarefs would mean I could avoid scanning files in DRT. This is a hack I'd love to get rid of.
// Called every time a new command is created by a plugin typedef void (* XPLMCommandCreation_f)( const char * inCommandName, const char * inCommandDescription, XPLMPluginID inCreatingPlugin, void * inRefcon); // Register a callback XPLMRegisterCommandCreationCallback( XPLMCommandCreationCallback_f inCallback, void * inRefcon); XPLMUnregisterCommandCreationCallback( XPLMCommandCreationCallback_f inCallback, void * inRefcon); // Called every time a new dataref is created typedef void (* XPLMDataCreationCallback_f)( const char * inDataName, const char * inDataDescription, XPLMPluginID inCreatingPlugin, XPLMDataTypeID inDataType, int inIsWritable, void * inRefcon); XPLMRegisterCommandCreationCallback( XPLMDataCreationCallback_f inCallback, void * inRefcon); XPLMUnregisterDataCreationCallback( XPLMDataCreationCallback_f inCallback, void * inRefcon);
Functions to get attributes of commands and datarefs:
a. Description (as provided in the UI, and DataRefs.txt), etc. The description is often informative for people trying to understand what a dataref found in DRT does. It would also be useful to describe commands to users using this text in the same way that the Settings window does.
// Get the description of a command/dataref int XPLMGetDataRefDescription(XPLMDataRef inDataRef, char *outName, char *outDescription); int XPLMGetCommandDescription(XPLMCommand inCommand, char *outName, char *outDescription);
b. Which plugin created a command/dataref. This would simply be informative in DRT, or could be used as a filter in the search window.
// Which plugin originally created a command/dataref? XPLMPluginID XPLMGetDataRefCreator(XPLMDataRef inDataRef); XPLMPluginID XPLMGetCommandCreator(XPLMDataRef inDataRef);
c. Check if a dataref is deprecated. The current version of DRT scans DataRefs.txt for the word DEPRECATED for this purpose.
// Determine if a dataref is deprecated. // // By the time you have a XPLMDataRef, X-Plane will have already thrown a warning about a // deprecated dataref being used. If possible, maybe that warning should be moved to the first // time a dataref is read? I suppose this is undesirable for performance reasons. // // Another way to accomplish this would be to add a new bit in the dataref type flags to indicate // if a dataref is deprecated, but that could possibly break existing plugins that can't handle the // new bit. int XPLMIsDataRefDeprecated(XPLMDataRef inDataRef);
d. Check if a command has been mapped to a keyboard button or joystick. To me this seems like it might be broadly useful. As an example, PlaneCommand needs the user to push a PTT button; if the user hasn't configured it, I could show a helpful dialog explaining the process.
// Determine if a command is bound to a key or joystick button. This would be useful for plugins // that present controls via a command; for example, PlaneCommand needs a PTT button to be bound, // and could use this function to determine if we need to present a message guiding the user to // bind a key or joystick button to the PTT command. int XPLMIsCommandMapped(XPLMCommandRef inCommand);