I'd like to hear what other modders think about the "handlers". Of course any insight Uber could provide into their current implement and like future state would also be greatly appreciated. My issues with handlers are: "handlers" are a shared resource. So Instant Sandbox is going to have to careful not to overwrite the PAStats matchmaking handlers. (This case is doubly bad because both of us would be listening to server state events to try and advance the game creation process.) Single definition. registerWithCoherent appears to define a couple of global functions like engine.asyncCall, so mods can't have their own sets. It also seems that engine.on can only have one handler (but maybe my testing was clouded by the RequireJS caching issues) They have to be defined up front. The panel filters only allow a panel to receive the events that were defined at creation time. Any kind of delayed loading (or only temporary interest) will need to take extra care to define a stub during mod load so that the events get in the filter. Ideally, there would be an API similar to the browser addEvent (and remove) where multiple mods could register handlers. Wouldn't handle every case - the game creation example probably needs some single piece of code in charge of the process. I've been wondering if we might need a sort of Handlers Framework as a shared mod. The panel filters could make that challenging however - you can't do dynamic registration because of the filters, and you don't want to hook everything up front because it would defeat the point of the filters.
I use code like this to add my own handlers to be executed after the original handlers: Code: function hookFunction(obj, fnName, hookFn) { var realFn = obj[fnName]; obj[fnName] = function () { realFn.apply(obj, arguments); hookFn.apply(obj, arguments); }; } hookFunction(handlers, 'army', myOwnArmyHandler); It gets the job done, but a real handler API for mods would be nice.
That's a better way to do it than I usually do, but it helps explain to me why I was confused reading the original post. It's javascript, so you can always replace a function. Code: var original_someFunction = someFunction; someFunction = function() { original_someFunction (); // New code ... ... };
This issue first became clear when both me and raevn fiddeled with the alerts handlers and as a result PA Stats got not the data it wanted. I think in general frameworks like the one I wrote for alerts (https://forums.uberent.com/threads/rel-alertsmanager-61450.55590/) are the way to go. However they should be implemented by Uber to make sure everyone uses them.