Inspired by reactive libraries such as RxJS and Angular, Wisecrack is a powerful library of functions and operators aimed to help make your life easier when dealing with asynchronous and general data management.
All you need to call is wx_init()
somewhere in the begining of your game to get the system running. Without running this code, some functionalities will still work perfectly fine, but some will not such as wx_interval()
and calling global events from WX_GLOBAL
.
- Configurations for schedulers (timesources), global event names, and verbose
- Event handlers and event firing (including a global event handler
WX_GLOBAL
) - Examples for every operator and functions
Observers
,Observables
, andSubjects
Operators in Wisecrack follow the same naming conventions of standard reactive libraries, with wx_*
added before each operator. You can enable short hands in the __wxStenograph
script which allows for CamelCased shorthand operator names.
-
Static operators (more to come)
-
Pipeable operators (more to come)
Global events can return either undefined
or some sort of data. These events include:
- keypress
- async_*
async events will return a struct populated with key/value pairs taken from async_load
, so you can simply just call data.buffer
for instance instead of async_load[? "buffer"]
to get the buffer data. Keypress will return keyboard_key
.
Local events called from wx_event_fire
will always return the object_index of the object that fired it.
You can implement debug logs for observable streams using .trace(OPTIONAL NAME)
after static operators, observables, or subjects like so:
obj_trace_example > Create event
var my_observable_stream = wx_of(1, 2, 3).trace("1, 2, 3 stream"); // Trace our stream
my_observable_stream.subscribe(function(v){ // Subscribe a function to it
show_debug_message("The data was: "+string(v));
});
will produce this in the Output log:
Wisecrack: [ obj_trace_example ] piped [ 1, 2, 3 stream ]
Wisecrack: from [ obj_trace_example ] -> 1, 2, 3 stream emitted: 1
The data was: 1
Wisecrack: from [ obj_trace_example ] -> 1, 2, 3 stream emitted: 2
The data was: 2
Wisecrack: from [ obj_trace_example ] -> 1, 2, 3 stream emitted: 3
The data was: 3
Wisecrack: completed [ obj_trace_example ]
Wisecrack: teardown [ 1, 2, 3 stream ]
This is good for following the the pipeline of an observable. You can turn ALL tracing off by setting WX_VERBOSE
to false in __wxConfig