Skip to content

Commit

Permalink
Merge pull request #2 from kandashi/0.0.22
Browse files Browse the repository at this point in the history
0.0.22
  • Loading branch information
kandashi authored Jan 17, 2021
2 parents 63a8fe8 + 831204e commit 704c1df
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Combat-Focus",
"title": "Combat Focus",
"description": "Auto focus to current combatant",
"version": "0.0.21",
"version": "0.0.22",
"authors": [
{
"name": "Kandashi",
Expand Down
95 changes: 48 additions & 47 deletions src/combatFocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,62 @@ Hooks.on('init', () => {
default: false,
config: true,
});
})

Hooks.on("updateCombat", async (combat, changed, options, userId) => {

})
Hooks.on("updateCombat", async (combat, changed, options, userId) => {
if (!("turn" in changed)) {
return;
return;
}

const firstGm = game.users.find((u) => u.isGM && u.active);
if (firstGm && game.user === firstGm) {

if (game.combats.get(combat.id).data.combatants.length == 0) return;
if (game.combats.get(combat.id).data.combatants.length == 0) return;


const nextTurn = combat.turns[changed.turn];
const previousTurn = combat.turns[changed.turn - 1 > -1 ? changed.turn - 1 : combat.turns.length - 1]

let nextTokenId = null;
if (getProperty(nextTurn, "tokenId")) {
nextTokenId = nextTurn.tokenId;
}
else {
nextTokenId = getProperty(nextTurn, token._id);
}

let currentToken = canvas.tokens.get(nextTokenId);
let previousToken = canvas.tokens.get(previousTurn.tokenId)

if (!currentToken.actor) {
return;
}


const nextTurn = combat.turns[changed.turn];
const previousTurn = combat.turns[changed.turn - 1 > -1 ? changed.turn - 1 : combat.turns.length -1]

let nextTokenId = null;
if (getProperty(nextTurn, "tokenId")) {
nextTokenId = nextTurn.tokenId;
}
else {
nextTokenId = getProperty(nextTurn, token._id);
}

let currentToken = canvas.tokens.get(nextTokenId);
let previousToken = canvas.tokens.get(previousTurn.tokenId)

if (!currentToken.actor) {
return;
}

const combatFocus = game.settings.get('Combat-Focus', 'combatFocus')
const closeAll = game.settings.get('Combat-Focus', 'close-all')
if(combatFocus !== "0") {
await sleep(5)
await currentToken.control()
canvas.animatePan({x: currentToken.center.x, y: currentToken.center.y, duration: 250});
let sheet = await currentToken.actor.sheet.render(true)
let rightPos = window.innerWidth - sheet.position.width - 310;
await sleep(5);
if(combatFocus === "1"){
sheet.setPosition({ left: 107, top: 46});
if(closeAll) await ui.windows.filter(i => i.actor).close(true)
else await previousToken.actor.sheet.close(true)
}
if(combatFocus === "2"){
sheet.setPosition({ left: rightPos, top: 46});
if(closeAll) await ui.windows.filter(i => i.actor).close(true)
else await previousToken.actor.sheet.close(true)
}
let currentWindows = Object.values(ui.windows)
if (combatFocus !== "0") {
await sleep(5)
await currentToken.control()
canvas.animatePan({ x: currentToken.center.x, y: currentToken.center.y, duration: 250 });
let sheet = await currentToken.actor.sheet.render(true)
let rightPos = window.innerWidth - sheet.position.width - 310;
await sleep(5);
if (combatFocus === "1") {
sheet.setPosition({ left: 107, top: 46 });
if (closeAll) for (let window of currentWindows) if (window.actor && window.actor.id !== currentToken.actor.id) window.close(true)
else await previousToken.actor.sheet.close(true)
}
if (combatFocus === "2") {
sheet.setPosition({ left: rightPos, top: 46 });
if (closeAll) for (let window of currentWindows) if (window.actor && window.actor.id !== currentToken.actor.id) window.close(true)
else await previousToken.actor.sheet.close(true)
}

async function sleep(millis) {
return new Promise(r => setTimeout(r, millis));
}
async function sleep(millis) {
return new Promise(r => setTimeout(r, millis));
}
}
}
}
});

0 comments on commit 704c1df

Please sign in to comment.