Change hook_file to hook_require, fix init bug

This commit is contained in:
Aussiemon 2023-02-09 14:00:09 -07:00
parent f645473f31
commit 48218a54d1

View file

@ -422,15 +422,16 @@ function DMFMod:hook_origin(obj, method, handler)
return generic_hook(self, obj, method, handler, "hook_origin") return generic_hook(self, obj, method, handler, "hook_origin")
end end
-- :hook_file() allows you to hook every past and future version of a game file, -- :hook_require() allows you to hook every past and future version of a game file,
-- executing a callback function on every instance. -- executing a callback function on every instance.
-- The chain of event is determined by mod load order. -- The chain of event is determined by mod load order.
function DMFMod:hook_file(obj_str, callback_func) function DMFMod:hook_require(obj_str, callback_func)
-- Set up the tables for the file -- Set up the tables for the file
local mod_name = self:get_name() local mod_name = self:get_name()
_file_hooks_by_file[obj_str] = _file_hooks_by_file[obj_str] or {} _file_hooks_by_file[obj_str] = _file_hooks_by_file[obj_str] or {}
_file_hooks_applied_to_file[obj_str] = _file_hooks_applied_to_file[obj_str] or {[mod_name] = {}} _file_hooks_applied_to_file[obj_str] = _file_hooks_applied_to_file[obj_str] or {}
_file_hooks_applied_to_file[obj_str][mod_name] = _file_hooks_applied_to_file[obj_str][mod_name] or {}
-- Store file hooks by mod name to prevent duplicates per mod -- Store file hooks by mod name to prevent duplicates per mod
_file_hooks_by_file[obj_str][mod_name] = callback_func _file_hooks_by_file[obj_str][mod_name] = callback_func