Created
May 3, 2023 14:32
-
-
Save diwako/1aa7a5dcc9352fc7b109bc386acc10b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let tokens = await Tagger.getByTag("light"); | |
if (tokens.length === 0) return; | |
let sceneId = canvas.scene._id; | |
let duration = 2000; | |
let intervall = 1000; | |
let moveToken = async function (token) { | |
if (!token) return; | |
await token.update({ | |
light: { | |
color: | |
"#" + ((Math.random() * 0xffffff) << 0).toString(16).padStart(6, "0"), | |
}, | |
}); | |
new Sequence() | |
.animation() | |
.on(token) | |
.teleportTo({ x: 0, y: token.y }) | |
.wait(500) | |
.animation() | |
.on(token) | |
.moveTowards({ x: 4700, y: token.y }) | |
.duration(duration) | |
.waitUntilFinished() | |
.animation() | |
.on(token) | |
.teleportTo({ x: 0, y: token.y }) | |
.play(); | |
}; | |
let theLoop = async function () { | |
if (sceneId != canvas.scene._id) { | |
console.log("This it the end!"); | |
return; | |
} | |
let tokens = await Tagger.getByTag("light"); | |
tokens = tokens | |
.map((value) => ({ value, sort: Math.random() })) | |
.sort((a, b) => a.sort - b.sort) | |
.map(({ value }) => value); | |
for (const token of tokens) { | |
// for in threw errors... | |
setTimeout( | |
moveToken, | |
(tokens.indexOf(token) / (tokens.length - 1)) * duration, | |
token | |
); | |
} | |
setTimeout(theLoop, duration + 1000 * tokens.length); | |
}; | |
theLoop(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment