Skip to content

Commit

Permalink
Adding removal of targets and animations on token delete. Addresses i…
Browse files Browse the repository at this point in the history
…ssue eadorin#23
  • Loading branch information
nationwide13 authored and nationwide13 committed Feb 1, 2021
1 parent 64e2f28 commit 81d0d1d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions target-enhancements.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class TargetEnhancements {
static neutral_text = new PIXI.Text('Neutral Unit',{fontFamily : 'Signika', fontSize: 24, fill : 0xff1010, align : 'center'});
static hostile_text = new PIXI.Text('Hostile Unit',{fontFamily : 'Signika', fontSize: 24, fill : 0xFF0000, align : 'center'});

// Collection of running tickers to be used when a token is deleted
static tickerFunctions = {};

static async ready() {
// TODO register game settings
ready = true;
Expand Down Expand Up @@ -358,8 +361,8 @@ class TargetEnhancements {

// only redraw if not already existing
if (token.target.children.length <= 0) {
let indicator = new TargetIndicator(token);
indicator.create(selectedIndicator);
TargetEnhancements.tickerFunctions[token.data._id] = new TargetIndicator(token);
TargetEnhancements.tickerFunctions[token.data._id].create(selectedIndicator);
}
}

Expand Down Expand Up @@ -754,6 +757,20 @@ Hooks.on("controlToken",TargetEnhancements.controlTokenEventHandler);
Hooks.on("clearTokenTargets",TargetEnhancements.clearTokenTargetsHandler);
Hooks.on("getSceneControlButtons",TargetEnhancements.getSceneControlButtonsHandler);

/*
* This adds handling to untarget and remove any animations
* The tokenDelete event is called after a token is destroyed which is too late to handle un-targeting
*/
const onDelete = Token.prototype._onDelete;
Token.prototype._onDelete = function(options, userId) {
if (TargetEnhancements.tickerFunctions[this.data._id]) {
TargetEnhancements.tickerFunctions[this.data._id].destroy();
delete TargetEnhancements.tickerFunctions[this.data._id];
}
this.targeted.forEach((user) => user.targets.forEach((t) => t.setTarget(false, {user: user, releaseOthers: true, groupSelection:false })))
return onDelete.apply(this, options, userId);
}


/**
* Bugs
Expand Down

0 comments on commit 81d0d1d

Please sign in to comment.