Skip to content

Commit

Permalink
more options included. Resolve #4
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-roger committed Sep 27, 2022
1 parent f104861 commit 66f7615
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 20 deletions.
98 changes: 98 additions & 0 deletions scripts/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { MODULE, MODULE_DIR } from "./const.js"; //import the const variables
import { elevation } from "./flying-tokens.js"

export const movement = {
filterType: "images",
filterId: MODULE,
time: 100,
nbImage: 1,
alphaImg: 1,
alphaChr: 0.0,
blend: 4,
ampX: 0.005,
ampY: 0.005,
animated: {
time:
{
active: true,
speed: 0.0010,
animType: "move"
}
}
}
export const noShadow = {
filterType: "zapshadow",
filterId: MODULE,
alphaTolerance: 0.5,
rank: 2
}
export const wind = {
filterType: "transform",
filterId: MODULE,
twRadiusPercent: 10,
padding: 150,
animated:
{
twRotation:
{
animType: "sinOscillation",
val1: -(0.05 * elevation),
val2: +(0.05 * elevation),
loopDuration: 5000,
}
}
}
export const shadow = {
filterType: "shadow",
filterId: MODULE,
rotation: 35,
blur: 2,
quality: 5,
distance: elevation / 0.7,
alpha: Math.min(1 / ((elevation) / 50), 0.8),
padding: elevation * 2,
shadowOnly: false,
color: 0x000000,
zOrder: 6000,
animated:
{
blur:
{
active: true,
loopDuration: 5000,
animType: "syncCosOscillation",
val1: 2,
val2: 4
},
rotation:
{
active: true,
loopDuration: 5000,
animType: "syncSinOscillation",
val1: 33,
val2: 33 + (elevation * 0.1)
}
}
}
export const bounce = {
filterType: "transform",
filterId: MODULE,
padding: 50,
animated:
{
translationX:
{
animType: "sinOscillation",
val1: -0.005,
val2: +0.005,
loopDuration: 9600,
},
translationY:
{
animType: "cosOscillation",
val1: -0.005,
val2: +0.005,
loopDuration: 1400,
}
}
}
49 changes: 31 additions & 18 deletions scripts/flying-tokens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { MODULE, MODULE_DIR } from "./const.js"; //import the const variables
import { chatMessage } from "./util.js"
import { registerSettings, cacheSettings, enableFT, enableForAll, scaleFT, enableZoom, chatOutput, notificationOutput } from "./settings.js" //import settings
import { registerSettings, cacheSettings, enableFT, enableForAll, scaleFT, enableZoom, chatOutput, notificationOutput, optMovement, optNoShadow, optWind } from "./settings.js" //import settings
import { FlyingHud } from "./flying-hud.js"
// import { movement, noShadow, wind, shadow, bounce } from "./filters.js"

//Compatibility with v9
let fvttVersion
Expand All @@ -18,9 +19,9 @@ Hooks.once('ready', async function () {
console.log(" ====================================== 🐦 Flying Tokens ======================================= ")
console.log(" ==================================== FoundryVTT Version:", fvttVersion, " ==================================== ")
//compatibility with v9
if (fvttVersion < 10) {
// if (fvttVersion < 10) {

}
// }
});

Hooks.on("preUpdateToken", async (token, updateData) => {
Expand Down Expand Up @@ -75,12 +76,12 @@ export async function fly(token, elevation) {
}

async function tokenScale(token, elevation) {
let originalScale = token.getFlag(MODULE, "scale");
if (elevation == 0) {
let originalScale = token.getFlag(MODULE, "scale");
await token.update({ scale: originalScale })
return 0
}
let scale = Math.pow(elevation, 0.28)
let scale = originalScale + Math.pow(elevation, 0.28)
scale = Math.round((scale + Number.EPSILON) * 100) / 100 //rounding with 2 floats
if (scale <= 1) scale += 1
else if (scale > 10) scale = 10
Expand All @@ -102,7 +103,7 @@ async function flyZoom(token, elevation, minZoom = 3) {

async function flyingFX(token, elevation) {
let canvasToken = canvas.tokens.get(token.id)
const flyingFXParams = [{
const movement = {
filterType: "images",
filterId: MODULE,
time: 100,
Expand All @@ -120,12 +121,14 @@ async function flyingFX(token, elevation) {
animType: "move"
}
}
}, {
}
const noShadow = {
filterType: "zapshadow",
filterId: MODULE,
alphaTolerance: 0.5,
rank: 2
}, {
}
const wind = {
filterType: "transform",
filterId: MODULE,
twRadiusPercent: 10,
Expand All @@ -135,19 +138,20 @@ async function flyingFX(token, elevation) {
twRotation:
{
animType: "sinOscillation",
val1: -(0.05 * elevation),
val2: +(0.05 * elevation),
val1: -(2 * Math.pow(elevation, 0.28)),
val2: +(2 * Math.pow(elevation, 0.28)),
loopDuration: 5000,
}
}
}, {
}
const shadow = {
filterType: "shadow",
filterId: MODULE,
rotation: 35,
blur: 2,
quality: 5,
distance: elevation / 0.7,
alpha: Math.min(1 / ((elevation) / 50), 0.8),
alpha: Math.min(1 / ((elevation) / 60), 0.8),
padding: elevation * 2,
shadowOnly: false,
color: 0x000000,
Expand All @@ -168,10 +172,11 @@ async function flyingFX(token, elevation) {
loopDuration: 5000,
animType: "syncSinOscillation",
val1: 33,
val2: 33 + (elevation * 0.05)
val2: 33+(3 * Math.pow(elevation, 0.28))
}
}
}, {
}
const bounce = {
filterType: "transform",
filterId: MODULE,
padding: 50,
Expand All @@ -192,12 +197,20 @@ async function flyingFX(token, elevation) {
loopDuration: 1400,
}
}
}]
}
let flyingFXParams = []

if (optNoShadow)
flyingFXParams.push(noShadow, shadow)
if (optWind)
flyingFXParams.push(wind)
if (optMovement)
flyingFXParams.push(bounce, movement)

let isFlying = token.getFlag(MODULE, "flying")
await canvasToken.TMFXdeleteFilters(MODULE)
if (isFlying) {
if (isFlying)
await TokenMagic.addUpdateFilters(canvasToken, flyingFXParams);
}
}

export async function land(token) {
Expand All @@ -210,4 +223,4 @@ export async function land(token) {
ui.notifications.info(token.actor.name + ' <b> has landed</b>.')
if (chatOutput)
await chatMessage(`<img src='${token.actor.img}' width='32' style='border:none'> ${token.actor.name} <b> has landed</b>.`)
}
}
47 changes: 45 additions & 2 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export let chatOutput = true;
export let notificationOutput = false;
export let scaleFT = true;
export let enableZoom = false;

export let optMovement = true;
export let optNoShadow = true;
export let optWind = true;

export function registerSettings() {
game.settings.register(MODULE, 'enableFT', {
Expand Down Expand Up @@ -86,6 +88,45 @@ export function registerSettings() {
cacheSettings();
},
});

game.settings.register(MODULE, 'optMovement', {
name: 'Enable Movement Effect.',
hint: `This setting will only affect tokens flying after the change, to apply to a token already flying you must land and fly again.`,
scope: 'world',
config: true,
type: Boolean,
default: true,
restricted: true,
onChange: () => {
cacheSettings();
},
});

game.settings.register(MODULE, 'optNoShadow', {
name: 'Enable Shadow remove',
hint: `Flying Tokens auto remove the shadow drawing from the token, uncheck this option if you want to disable this behavior. This setting will only affect tokens flying after the change, to apply to a token already flying you must land and fly again.`,
scope: 'world',
config: true,
type: Boolean,
default: true,
restricted: true,
onChange: () => {
cacheSettings();
},
});

game.settings.register(MODULE, 'optWind', {
name: 'Enable wind effect',
hint: `Uncheck this to remove the small twist effect from the center of the token while it is flying. This setting will only affect tokens flying after the change, to apply to a token already flying you must land and fly again.`,
scope: 'world',
config: true,
type: Boolean,
default: true,
restricted: true,
onChange: () => {
cacheSettings();
},
});
}

// function that get the settings options and assign to the variables
Expand All @@ -96,5 +137,7 @@ export function cacheSettings() {
notificationOutput = game.settings.get(MODULE, 'notificationOutput');
scaleFT = game.settings.get(MODULE, 'scaleFT');
enableZoom = game.settings.get(MODULE, 'enableZoom');

optMovement = game.settings.get(MODULE, 'optMovement');
optNoShadow = game.settings.get(MODULE, 'optNoShadow');
optWind = game.settings.get(MODULE, 'optWind');
}

0 comments on commit 66f7615

Please sign in to comment.