Skip to content

Commit

Permalink
Testing token hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 27, 2023
1 parent fad06a9 commit 0549add
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/Token.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* globals
game
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
"use strict";

export const PATCHES = {};
PATCHES.BASIC = {};
PATCHES.AUTOTARGET = {};

// ---- NOTE: Hooks ----- //
Expand All @@ -27,4 +29,40 @@ function controlTokenHook(object, controlled) {
else if ( user.lastSelected === object ) user._lastDeselected = object;
}

/**
* Hook preUpdateToken
*/
function preUpdateTokenHook(tokenD, changes, _options, _userId) {
const token = tokenD.object;
console.debug(`preUpdateToken hook ${changes.x}, ${changes.y}, ${changes.elevation} at elevation ${token.document?.elevation} with elevationD ${tokenD.elevation}`, changes);
console.debug(`preUpdateToken hook moving ${tokenD.x},${tokenD.y} --> ${changes.x ? changes.x : tokenD.x},${changes.y ? changes.y : tokenD.y}`);
}

/**
* Hook updateToken
*/
function updateTokenHook(tokenD, changed, _options, _userId) {
const token = tokenD.object;
console.debug(`updateToken hook ${changed.x}, ${changed.y}, ${changed.elevation} at elevation ${token.document?.elevation} with elevationD ${tokenD.elevation}`, changed);
console.debug(`updateToken hook moving ${tokenD.x},${tokenD.y} --> ${changed.x ? changed.x : tokenD.x},${changed.y ? changed.y : tokenD.y}`);

}

/**
* Hook Token refresh
*/
function refreshTokenHook(token, flags) {
if ( !flags.refreshPosition ) return;
// TODO: refreshElevation flag?
console.debug(`refreshToken for ${token.name} at ${token.position.x},${token.position.y}. Token is ${token._original ? "Clone" : "Original"}. Token is ${token._animation ? "" : "not "}animating.`);
if ( token._original ) {
// clone
}

if ( token._animation ) {
// animating
}
}

PATCHES.AUTOTARGET.HOOKS = { controlToken: controlTokenHook };
PATCHES.BASIC.HOOKS = { preUpdateToken: preUpdateTokenHook, updateToken: updateTokenHook, refreshToken: refreshTokenHook };

0 comments on commit 0549add

Please sign in to comment.