Skip to content

Commit

Permalink
Merge pull request #32 from kandashi/0.1.21
Browse files Browse the repository at this point in the history
some fixes
  • Loading branch information
kandashi authored Jan 14, 2021
2 parents 9fa7429 + 90fcbcc commit fafc46e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 44 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Active-Auras",
"description": "Active-Auras",
"author": "Kandashi",
"version": "0.1.2",
"version": "0.1.21",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9",
"packs": [
Expand Down
63 changes: 20 additions & 43 deletions src/aura.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Hooks.on("ready", () => {
const FormInactive = game.i18n.format("ACTIVEAURAS.FORM_Inactive");
const FormHidden = game.i18n.format("ACTIVEAURAS.FORM_Hidden");
const FormTargetsName = game.i18n.format("ACTIVEAURAS.FORM_TargetsName");
const FormTargetsNone =game.i18n.format("ACTIVEAURAS.FORM_TargetsNone");
const FormTargetsNone = game.i18n.format("ACTIVEAURAS.FORM_TargetsNone");
const FormTargetsEnemy = game.i18n.format("ACTIVEAURAS.FORM_TargetsEnemy");
const FormTargetsAllies = game.i18n.format("ACTIVEAURAS.FORM_TargetsAllies");
const FormTargetsAll = game.i18n.format("ACTIVEAURAS.FORM_TargetsAll");
Expand Down Expand Up @@ -79,22 +79,19 @@ Hooks.on("ready", () => {
*/
Hooks.on("createToken", (scene, token) => {
newToken = canvas.tokens.get(token._id)
CollateAuras(canvas, true, false)
setTimeout(() => {
CollateAuras(canvas, true, false)
}, 20)
});

/**
* @todo
* Filter for aura effects on deleted token and remove from canvas tokens
*/
Hooks.on("preDeleteToken", async (scene, token) => {
if (token.actorLink) {
let auraActor = false
for (let testEffect of actor.effects) {
if (testEffect.data.flags?.ActiveAuras?.applied) await testEffect.delete()
if (testEffect.data.flags?.ActiveAuras?.isAura) auraActor = true
}
if (auraActor) CollateAuras(scene, false, true)
}
setTimeout(() => {
CollateAuras(canvas, false, true)
}, 20)

});

Expand All @@ -104,35 +101,14 @@ Hooks.on("ready", () => {
Hooks.on("updateToken", (scene, token, update, flags, id) => {
if (("y" in update || "x" in update))
MainAura(token,)
if("hidden" in update )
CollateAuras(scene, true, true)
if ((update?.actorData?.effects) || ("hidden" in update)) {
setTimeout(() => {
CollateAuras(canvas, true, true)
}, 20)
}
});


/**
* On addition/removal of active effect from unlinked actor, if aura update canvas.tokens
* @todo
*/
Hooks.on("preUpdateToken", (scene, token, update) => {
if (!(update?.actorData?.effects)) return;

let removed = token.actorData.effects.filter(x => !update.actorData.effects.includes(x));
let added = update.actorData.effects.filter(x => !token.actorData.effects.includes(x));
if (removed.length > 0) {
let isAura = removed[0].flags?.ActiveAuras?.isAura;
let applyStatus = removed[0].flags?.ActiveAuras?.applied;
if (isAura && !applyStatus) {
CollateAuras(scene, false, true)
}
}
if (added.length > 0) {
let isAura = added[0].flags?.ActiveAuras?.isAura;
let applyStatus = added[0].flags?.ActiveAuras?.applied;
if (isAura && !applyStatus)
CollateAuras(scene, true, false)
}
})

/**
* @todo
*/
Expand Down Expand Up @@ -194,7 +170,7 @@ Hooks.on("ready", () => {
for (let testEffect of testToken?.actor?.effects.entries) {
if (testEffect.getFlag('ActiveAuras', 'isAura')) {
if (testEffect.getFlag('ActiveAuras', 'hidden') && testToken.data.hidden) continue;
let newEffect = duplicate(testEffect)
let newEffect = { data: testEffect.data, parentActorLink: testEffect.parent.data.token.actorLink, parentActorId: testEffect.parent._id, tokenId: testToken.id }
for (let change of newEffect.data.changes) {
if (typeof change.value === "string" && change.key !== "macro.execute") {
if (change.value.includes("@")) {
Expand Down Expand Up @@ -317,8 +293,9 @@ Hooks.on("ready", () => {
MapObject = map.get(MapKey);
let auraToken;
let auraRadius = auraEffect.data.flags?.ActiveAuras?.radius
if (auraEffect.parent.token.actorLink) {
let auraTokenArray = game.actors.get(auraEffect.parent._id).getActiveTokens()
//{data: testEffect.data, parentActorLink :testEffect.parent.data.token.actorLink, parentActorId : testEffect.parent._id, tokenId: testToken.id}
if (auraEffect.parentActorLink) {
let auraTokenArray = game.actors.get(auraEffect.parentActorId).getActiveTokens()
if (auraTokenArray.length > 1) {
auraToken = auraTokenArray.reduce(FindClosestToken, auraTokenArray[0])
function FindClosestToken(tokenA, tokenB) {
Expand All @@ -327,8 +304,8 @@ Hooks.on("ready", () => {
}
else auraToken = auraTokenArray[0]
}
else if (auraEffect.parent.token) {
auraToken = auraEffect.parent.token
else if (auraEffect.tokenId) {
auraToken = canvas.tokens.get(auraEffect.tokenId)
}
if (auraToken.id === canvasToken.id) continue;
if (auraTargets === "Allies" && (auraToken.data.disposition !== canvasToken.data.disposition)) continue;
Expand Down Expand Up @@ -382,7 +359,7 @@ Hooks.on("ready", () => {
async function CreateActiveEffect(token, effectData) {
if (token.actor.effects.entries.find(e => e.data.label === effectData.label)) return
await token.actor.createEmbeddedEntity("ActiveEffect", effectData);
console.log(game.i18n.format("ACTIVEAURAS.ApplyLog", {effectDataLabel: effectData.label, tokenName : token.name}))
console.log(game.i18n.format("ACTIVEAURAS.ApplyLog", { effectDataLabel: effectData.label, tokenName: token.name }))
}

/**
Expand All @@ -394,7 +371,7 @@ Hooks.on("ready", () => {
for (let tokenEffects of token.actor.effects) {
if (tokenEffects.data.label === effectLabel && tokenEffects.data.flags?.ActiveAuras.applied === true) {
tokenEffects.delete()
console.log(game.i18n.format("ACTIVEAURAS.RemoveLog", {effectDataLabel: effectData.label, tokenName : token.name}))
console.log(game.i18n.format("ACTIVEAURAS.RemoveLog", { effectDataLabel: effectLabel, tokenName: token.name }))

}
}
Expand Down

0 comments on commit fafc46e

Please sign in to comment.