xNVSE / NVSE

New Vegas Script Extender (NVSE)
https://git.io/JfSAo
713 stars 56 forks source link

Add DispatchEventAlt, DumpEventHandlers, GetEventHandlers, further tweak event handler system. #126

Closed Demorome closed 2 years ago

Demorome commented 2 years ago

== New Script Functions == DispatchEventAlt Description: An alternate way to dispatch User-Defined Events. Args are passed using the same syntax for Call, and are all optional. Return true if no errors were encountered. Syntax:

(bool) callingRefr{0}.DispatchEventAlt userDefinedEventName:string arg1:anyType arg2:anyType arg3:anyType ... (up to 15 args)

DumpEventHandlers Description: Outputs to console all event handlers currently set, optionally filtered by eventName and scriptHandler. Syntax:

(void) DumpEventHandlers eventName:string{""}  scriptHandler:baseForm{0} 

GetEventHandlers Description: Same as DumpEventHandlers, but dumps the information into a multidimensional array instead. If unfiltered, returns a stringmap array where each key is the name of an event, and each value is an array containing arrays with 2 elements. Those 2 elements are 1) the script handler and 2) a stringmap of filters ("1"::SomeFilter, etc.). If filtered by eventName, then it will return the same as (DumpEventHandlers)["myEventName"].

Mostly meant for Asserts and debugging. Syntax:

(array) GetEventHandlers eventName:string{""}  scriptHandler:baseForm{0} 

== Bug Fixes ==

== Codebase changes ==

Moved filter type-checking for SetEventHandler outside of ExtractEventCallback, into its own function that is called by SetEventHandler.

To support DumpEventHandlers being able to ouput all handlers for a script callback consecutively, the callbacks list in EventInfo is now an std::multimap, where the keys are callbacks (1 callback can have multiple associated handlers).

Added a flag to identify User-Defined Events - it is set when they are being registered via SetEventHandler.

For the new event handler filtering system, made SetEventHandler remove all minimally matching handlers, similar to how JG's events do it.

For unit tests, added "nvseTestEvent" event that uses almost all paramTypes (debug mode only).

Added support for multiple Unit Test script files (they go in data/nvse/unit_tests/..). Also wrote unit tests for the event handler functions, in event_handler_functions.txt.

Renamed ArrayElement::SetForm to ArrayElement::SetTESForm, since it was accidentally using the SetForm windows macro. Added ArrayElement::Equals because I felt it was missing, unused.