Skip to content

Commit

Permalink
Merge pull request #101 from kandashi/0.1.04
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
kandashi authored Jun 22, 2021
2 parents 5df7a22 + 8586f4e commit 208cdeb
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 24 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ This module can:
- You can now set token specific markers by setting a flag on the token
- token.setflag("Next-Up", "markerImage"/"markerRatio", "path to image"/ratio)

### Target Clearing
- You can set for targets to be cleared for each user at the end of a turn


### Start Turn Audio Cue
- You can set an audio cue to play for the players assigned character on their turn
- This can be set individually by the flag Next-Up.audioPath


## Licensing

Expand Down
105 changes: 81 additions & 24 deletions src/nextUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Hooks.on('init', () => {
"0": "Center",
"1": "Top Left",
"2": "Top Right",
"3": "Bottom Left",
"4": "Bottom Right",
},
default: "0",
config: true,
Expand Down Expand Up @@ -176,12 +178,34 @@ Hooks.on('init', () => {
"none": "None",
"npc": "NPCs Only",
"pc": "PCs only",
"all" : "All"
"all": "All"
},
default: true,
default: "All",
config: true,
});

game.settings.register("Next-Up", "clearTargets", {
name: 'Auto Clear User Targets',
scope: 'client',
type: Boolean,
default: false,
config: true,
});
game.settings.register("Next-Up", "audioCue", {
name: 'Turn Start Audio Cue',
scope: 'world',
type: Boolean,
default: false,
config: true
});
game.settings.register("Next-Up", "audioPath", {
name: 'Audio Cue Path',
scope: 'world',
type: String,
default: "",
config: true,
filePicker: true,
onChange: debouncedReload,
});
libWrapper.register('Next-Up', 'TokenLayer.prototype.tearDown', newTearDown, 'WRAPPER')
})

Expand All @@ -194,12 +218,19 @@ function newTearDown(wrapped, ...args) {
}



function newRefresh(wrapped, ...args) {
TweenMax.killTweensOf(this.children)
return wrapped(...args)
}


Hooks.once('ready', () => {

Hooks.on("createCombatant", (combatant) => {
NextUP.createTurnMarker(combatant.data.tokenId)
})
Hooks.on("preDeleteToken", (_scene, token) => {
Hooks.on("preDeleteToken", (token) => {
if (token.actorId === "") return;
NextUP.clearMarker(token._id)
})
Expand All @@ -215,18 +246,18 @@ Hooks.once('ready', () => {

Hooks.on("updateCombat", NextUP.handleCombatUpdate)

Hooks.on("updateToken", (_scene, token, update) => {
Hooks.on("preUpdateToken", (token, update) => {
if ("height" in update || "width" in update) {
const removeToken = canvas.tokens.get(token._id)
const marker = removeToken.children.find(i => i.NUMaker)
if (marker) {
NextUP.clearMarker(token._id)
NextUP.createTurnMarker(token, canvas.grid)
}
}
let markerToken = token.object?.children.find(i => i.NUMaker)
TweenMax.killTweensOf(token.object?.children);
Hooks.once("updateToken", async (token, update) => {
await NextUP.createTurnMarker(token.id, canvas.grid);
if (markerToken.NUMaker) NextUP.AddTurnMaker(token.object, canvas.grid)
})
}
})

Hooks.on("renderActorSheet", NextUP.addPinButton)
Hooks.on("renderActorSheet", NextUP.addPinButton)
})

Hooks.on("canvasReady", async () => {
Expand Down Expand Up @@ -270,6 +301,22 @@ class NextUP {
if (playerPanEnable && playerPan && (nextToken.isVisible || game.user === firstGm)) {
canvas.animatePan({ x: nextToken.center.x, y: nextToken.center.y, duration: 250 });
}
if (game.settings.get("Next-Up", "clearTargets")) {
game.user.updateTokenTargets()
}
if (game.settings.get("Next-Up", "audioCue")) {
if (nextToken.actor.id === game.user.character?.id) NextUP.audioCue()
}
}

static audioCue() {
const data = {
src: game.user.character.getFlag("Next-Up", "audioPath") || game.settings.get("Next-Up", "audioPath"),
volume: 0.5,
autoplay: true,
loop: false,
}
AudioHelper.play(data, false)
}

static async cycleSheets(currentToken, previousToken) {
Expand All @@ -281,17 +328,17 @@ class NextUP {

switch (autoControl) {
case "none": break;
case "npc" : if(currentToken.actor.type === "npc") await currentToken.control()
break;
case "pc" : if(currentToken.actor.type === "character") await currentToken.control()
break;
case "all" : await currentToken.control()
break;
case "npc": if (currentToken.actor.type === "npc") await currentToken.control()
break;
case "pc": if (currentToken.actor.type === "character") await currentToken.control()
break;
case "all": await currentToken.control()
break;

}
if (game.user.isGM) {


const currentWindows = Object.values(ui.windows);

let currentSheet = currentWindows.filter(i => i.token?.id === currentToken.id);
Expand All @@ -300,12 +347,18 @@ class NextUP {
if (currentSheet.length === 0)
Hooks.once("renderActorSheet", async (sheet) => {
let rightPos = window.innerWidth - sheet.position.width - 310;
let topPos = window.innerHeight - sheet.position.height - 80
let sheetPinned = sheet.pinned === true ? true : false;
switch (combatFocusPostion) {
case "0": break;
case "1": if (!sheetPinned) await sheet.setPosition({ left: 107, top: 46 });
break;
case "2": if (!sheetPinned) await sheet.setPosition({ left: rightPos, top: 46 });
break;
case "3": if (!sheetPinned) await sheet.setPosition({ left: 107, top: topPos });
break;
case "4": if (!sheetPinned) await sheet.setPosition({ left: rightPos, top: topPos });
break;
}
if (game.settings.get("Next-Up", "popout")) {
await PopoutModule.singleton.onPopoutClicked("1", sheet)
Expand Down Expand Up @@ -453,12 +506,14 @@ class NextUP {
if (token.data.hidden && !game.user.isGM) return;
let markerTexture = await loadTexture(token.data.img)
const textureSize = grid.size * token.data.height * token.data.scale
const offset = (textureSize - (grid.size * token.data.height)) / 2
const offsetX = (textureSize - (canvas.grid.w * token.data.width)) / 2
const offsetY = (textureSize - (canvas.grid.h * token.data.height)) / 2
let sprite = new PIXI.Sprite(markerTexture)
sprite.height = textureSize
sprite.width = textureSize
let startMarker = canvas.background.addChild(sprite)
startMarker.transform.position.set(token.data.x - offset, token.data.y - offset)
startMarker.position.x = token.data.x - offsetX
startMarker.position.y = token.data.y - offsetY
startMarker.isShadow = true
startMarker.tint = 9410203
startMarker.alpha = 0.7
Expand All @@ -471,12 +526,14 @@ class NextUP {
let startImage = token.actor.getFlag("Next-Up", "startMarkerImage") || NUStartImage
let startMarkerTexture = await loadTexture(startImage)
const textureSize = grid.size * token.data.height * ratio
const offset = (textureSize - (grid.size * token.data.height)) / 2
const offsetX = (textureSize - (canvas.grid.w * token.data.width)) / 2
const offsetY = (textureSize - (canvas.grid.h * token.data.height)) / 2
let sprite = new PIXI.Sprite(startMarkerTexture)
sprite.height = textureSize
sprite.width = textureSize
let startMarker = canvas.background.addChild(sprite)
startMarker.transform.position.set(token.data.x - offset, token.data.y - offset)
startMarker.position.x = token.data.x - offsetX
startMarker.position.y = token.data.y - offsetY
startMarker.isShadow = true
startMarker.alpha = 0.7
}
Expand Down

0 comments on commit 208cdeb

Please sign in to comment.