📅  最后修改于: 2023-12-03 14:47:27.084000             🧑  作者: Mango
Foundry Virtual Tabletop (Foundry VTT) is a popular virtual tabletop platform for playing tabletop games remotely. One of the many great features of Foundry VTT is its ability to allow module developers to extend its core functionality through Hooks.
Hooks are predefined events that allow developers to execute specific code at certain points in Foundry VTT's lifecycle. This enables developers to modify and enhance core functionality without modifying the source code directly.
There are several types of Hooks available in Foundry VTT. Some of the most commonly used include:
Developers can register their Hooks using the game's Hooks
object. For example:
Hooks.on("ready", () => {
console.log("The game is ready!");
});
This code registers a ready
Hook that logs a message to the console when the game is ready.
Developers can use Hooks to modify or enhance core Foundry VTT functionality. For example, they can use the preCreateXXX
and createXXX
Hooks to modify or add custom behavior to certain Foundry VTT objects.
Hooks.on("preCreateActor", (actor, options, userId) => {
if (actor.data.type === "npc") {
actor.data.flags = { isNPC: true };
}
});
This code registers a preCreateActor
Hook that adds a custom flag to NPC actors when they are created.
Hooks are a powerful feature in Foundry VTT that enable module developers to extend the platform's core functionality. By using Hooks, developers can modify and enhance Foundry VTT without modifying its source code directly.