Skip to content

Refactor Hooks

Ryan Walder requested to merge ryanw/refactor-hooks into master

Intent

As per #970 (closed) this MR splits the current hook files into atomic hooks.

  • Refactor src/modules/system/hooks.js to use a loop to load hooks
    • Removes the need to both declare the import and then export the imported function manually
    • Does limit us to using default exports for all hooks but we were following this pattern anyway
  • Make each hook a default export (remove uneeded function names)
  • Move all hooks into a folder structure that resembles other directory hierarchies
    • hooks/actor
    • hooks/actor/sheet
    • hooks/chat
    • hooks/item
    • etc.
  • Split overloaded hooks (multiple actions per hook) into single function hooks
  • Some re-formatting of comments

New file layout:

src/modules/hooks/
├── actor
│   ├── sheet
│   │   ├── persist-section-views.js
│   │   ├── resize-name.js
│   │   └── resize-type-tag.js
│   ├── check-emp-and-luck.js
│   ├── set-default-image.js
│   ├── sync-black-ice-with-program.js
│   ├── sync-tracked-armor.js
│   ├── update-role-from-item.js
│   └── update-role-on-item-delete.js
├── chat
│   ├── add-glyphs.js
│   ├── hide-blind-rolls.js
│   └── parse-red-command.js
├── external
│   ├── babele.js
│   ├── drag-ruler.js
│   └── popout.js
├── foundry
│   ├── ui
│   │   ├── item-folder-upgraded-display.js
│   │   ├── pause-animation.js
│   │   └── theme.js
│   └── delete-folder.js
├── hotbar
│   └── generate-item-macro.js
├── item
│   ├── role
│   │   └── update-sub-roles.js
│   ├── sheet
│   └── set-default-image.js
└── token
    ├── add-dv-token-hud.js
    ├── close-unlinked-sheet-on-delete.js
    └── warn-on-moving-locked-container.js

  • This is meant for a hotfix
  • This is meant for the next release (see milestone)
  • This needs more reviewers than normal; there may be controversy or high complexity
  • This intentionally introduces regressions that will be addressed later
  • There is/will be documentation changes on the wiki
  • Please do not send commits here without coordinating closely with the owner
  • This is a Build System change

Related Issues

Steps to Test

  1. Read the Diffs

AND

  1. Read each hook
  2. Understand what it's meant to do
    • The comment/docstring should give you this information if it doesn't that should be considered a bug
  3. In Foundry do the thing that would tigger the Hook
  4. Make sure the hook fires (trace logs)
  5. Make sure the hook does what it's supposed to do

Future Work

hotbar.js/hotbar/generate-item-macro.js really should be refactored/split but it's a beast so I'm not doing it right now.

Edited by Ryan Walder

Merge request reports