mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2025-12-20 07:12:55 +00:00
This commit changes every 'world.log <<' message with a loggable proc- log_to_dd(). This is adjustable in the config; If LOG_WORLD_OUTPUT is present, all things sent to world.log will show up in the standard /data/logs/ logs. These logs will contain the following (in order): Timestamp "DD_OUTPUT:" The message. The config option for this, by default, is turned off.
54 lines
1.4 KiB
Plaintext
54 lines
1.4 KiB
Plaintext
/************
|
|
* D2K5-STYLE HOOKS
|
|
*
|
|
* BLATANTLY STOLEN FROM D2K5 AND MODIFIED
|
|
*
|
|
* SOMEHOW SUCKS LESS THAN BAY'S HOOKS
|
|
************
|
|
|
|
The major change is to standardize them a bit
|
|
by changing the event prefix to On instead of Hook.
|
|
|
|
Oh and it's documented and cleaned up. - N3X
|
|
*/
|
|
|
|
/hook
|
|
var/name = "DefaultHookName"
|
|
var/list/handlers = list()
|
|
|
|
proc/Called(var/list/args) // When the hook is called
|
|
return 0
|
|
|
|
proc/Setup() // Called when the setup things is ran for the hook, objs contain all objects with that is hooking
|
|
|
|
/hook_handler
|
|
// Your hook handler should do this:
|
|
// proc/OnThingHappened(var/list/args)
|
|
// return handled // boolean
|
|
|
|
var/global/list/hooks = list()
|
|
|
|
/proc/SetupHooks()
|
|
for (var/hook_path in typesof(/hook))
|
|
var/hook/hook = new hook_path
|
|
hooks[hook.name] = hook
|
|
// log_to_dd("Found hook: " + hook.name)
|
|
for (var/hook_path in typesof(/hook_handler))
|
|
var/hook_handler/hook_handler = new hook_path
|
|
for (var/name in hooks)
|
|
if (hascall(hook_handler, "On" + name))
|
|
var/hook/hook = hooks[name]
|
|
hook.handlers += hook_handler
|
|
// log_to_dd("Found hook handler for: " + name)
|
|
for (var/hook/hook in hooks)
|
|
hook.Setup()
|
|
|
|
/proc/CallHook(var/name as text, var/list/args)
|
|
var/hook/hook = hooks[name]
|
|
if (!hook)
|
|
//log_to_dd("WARNING: Hook with name " + name + " does not exist")
|
|
return
|
|
if (hook.Called(args))
|
|
return
|
|
for (var/hook_handler/hook_handler in hook.handlers)
|
|
call(hook_handler, "On" + hook.name)(args) |