Rotating Gears Macros - grimmash/tors_tomb_of_the_nine_gods GitHub Wiki

Dependencies

The macros below, so far, all require a few mods to work:

Vehicles and Mechanisms: rotate tiles and walls

Multilevel Tokens: dependency for V&M (i think this is the case)

Sequencer: Helps automate some macros

Further documentation that will help you understand these macros is on a blog post I wrote.

Dialog Based Macro

A really slick macro with a dialog box and configurable sounds and animation styles. Mostly Masterhawk fixing my Sequencer Macro and then I added some configs for fun. This is included in the module now, in the Tor TotNG Macros compendium. You may need to figure out the drawing identities (e.g. mMa1oXBgiu4NZtcq). One way to do this is to use the Perfect Vision module and look at a drawings info in the Lighting tab.

REQUIRES A SOUND FILE at this time. Planning on splitting out two versions or handling a missing sound file in future.

//Sound File
// Replace with the path from within your Foundry Data directory
let sound_file = "Audio/Sounds/gears_of_hate_2_15s.mp3"

//Animation Style - See https://easings.net/
let easing_func = "easeInOutCubic"

// Cog Drawings
let cog1d = canvas.drawings.get("mMa1oXBgiu4NZtcq");
let cog2d = canvas.drawings.get("zEwVmZ4ByRE5uDYm");
let cog3d = canvas.drawings.get("zU6rNZriEQNvRWA3");
// Configuration 1 Cog Rotation Values
let con1cog1rot = 198;
let con1cog2rot = 140;
let con1cog3rot = 232;
// Configuration 2 Cog Rotation Values
let con2cog1rot = 284;
let con2cog2rot = 72;
let con2cog3rot = 288;
// Configuration 3 Cog Rotation Values
let con3cog1rot = 0;
let con3cog2rot = 0;
let con3cog3rot = 0;
// Configuration 4 Cog Rotation Values
let con4cog1rot = 80;
let con4cog2rot = 292;
let con4cog3rot = 97;
// Configuration 5 Cog Rotation Values
let con5cog1rot = 160;
let con5cog2rot = 225;
let con5cog3rot = 130;

// We determine the current configuration based on the initial rotation of Cog 2
let cog2IR = cog2d.document.data.rotation;
// Since there are 5 rotations, we give a range of 72 to determine the best estimate of the current configuration
function currentconfig(cog2IR){
	let ccnum = 0;
	if ((cog2IR < 108) && (cog2IR > 36)){
		ccnum = 2;}
	else if ((cog2IR < 180) && (cog2IR > 108)){
		ccnum = 1;}
	else if ((cog2IR < 252) && (cog2IR > 180)){
		ccnum = 5;}
	else if ((cog2IR < 324) && (cog2IR > 252)){
		ccnum = 4;}
	else{
		ccnum = 3;}
	return ccnum;
}

/*
Config 1
From Config 1: Nothing
From Config 2: Cog 2 Clockwise
From Config 3: Cog 2 Clockwise
From Config 4: Cog 2 Counterclockwise
From Config 5: Cog 2 Counterclockwise
*/
async function config1(){
	// If Configuration 2 or 3
	if((currentconfig(cog2IR) == 2) || (currentconfig(cog2IR) == 3)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(-360 + con1cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(con1cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(-360 + con1cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 4 or 5
	else if((currentconfig(cog2IR) == 4) || (currentconfig(cog2IR) == 5)){
		new Sequence()
		    .sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(con1cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(-360 + con1cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(con1cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 1
	else{
		return;
	}
}

/*
Config 2
From Config 1: Cog 2 Counterclockwise
From Config 2: Nothing
From Config 3: Cog 2 Clockwise
From Config 4: Cog 2 Clockwise
From Config 5: Cog 2 Counterclockwise
*/
async function config2(){
	// If Configuration 3 or 4
	if((currentconfig(cog2IR) == 3) || (currentconfig(cog2IR) == 4)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(-360 + con2cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(con2cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(-360 + con2cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 1 or 5
	else if((currentconfig(cog2IR) == 1) || (currentconfig(cog2IR) == 5)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(con2cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(-360 + con2cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(con2cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 2
	else{
		return;
	}
}

/*
Config 3
From Config 1: Cog 2 Counterclockwise
From Config 2: Cog 2 Counterclockwise
From Config 3: Nothing
From Config 4: Cog 2 Clockwise
From Config 5: Cog 2 Clockwise
*/
async function config3(){
	// If Configuration 4 or 5
	if((currentconfig(cog2IR) == 4) || (currentconfig(cog2IR) == 5)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(-360 + con3cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(con3cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(-360 + con3cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 1 or 2
	else if((currentconfig(cog2IR) == 1) || (currentconfig(cog2IR) == 2)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(con3cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(-360 + con3cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(con3cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 3
	else{
		return;
	}
}

/*
Config 4
From Config 1: Cog 2 Clockwise
From Config 2: Cog 2 Counterclockwise
From Config 3: Cog 2 Counterclockwise
From Config 4: Nothing
From Config 5: Cog 2 Clockwise
*/
async function config4(){
	// If Configuration 1 or 5
	if((currentconfig(cog2IR) == 1) || (currentconfig(cog2IR) == 5)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(-360 + con4cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(con4cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(-360 + con4cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 2 or 3
	else if((currentconfig(cog2IR) == 2) || (currentconfig(cog2IR) == 3)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(con4cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(-360 + con4cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(con4cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 4
	else{
		return;
	}
}

/*
Config 5
From Config 1: Cog 2 Clockwise
From Config 2: Cog 2 Clockwise
From Config 3: Cog 2 Counterclockwise
From Config 4: Cog 2 Counterclockwise
From Config 5: Nothing
*/
async function config5(){
	// If Configuration 1 or 2
	if((currentconfig(cog2IR) == 1) || (currentconfig(cog2IR) == 2)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(-360 + con5cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(con5cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(-360 + con5cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 3 or 4
	else if((currentconfig(cog2IR) == 3) || (currentconfig(cog2IR) == 4)){
		new Sequence()
			.sound()
			    .file(sound_file)
			.animation()
				.on(cog1d)
				.rotateIn(con5cog1rot, 2000,{ease: easing_func})
			.animation()
				.on(cog2d)
				.rotateIn(-360 + con5cog2rot, 2000,{ease: easing_func})
			.animation()
				.on(cog3d)
				.rotateIn(con5cog3rot, 2000,{ease: easing_func})
			.play();
	}
	// If Configuration 5
	else{
		return;
	}
}

let d = new Dialog({
	title: `Gears of Hate Config`,
	content: `Pick the new configuration.`,
	buttons: {
		one: {
			label: `1`,
			callback: () => {
				config1();
				d.render(true);
			}
		},
		two: {
			label: `2`,
			callback: () => {
				config2();
				d.render(true);
			}
		},
		three: {
			label: `3`,
			callback: () => {
				config3();
				d.render(true);
			}
		},
		four: {
			label: `4`,
			callback: () => {
				config4();
				d.render(true);
			}
		},
		five: {
			label: `5`,
			callback: () => {
				config5();
				d.render(true);
			}
		},
	},
});
d.render(true)

Simple Sequencer Macro

One working example of the rotating gears macro using the Sequencer Module:

let token1 = canvas.tokens.placeables.find(t => t.data.name === "TorGear1"); 
let token2 = canvas.tokens.placeables.find(t => t.data.name === "TorGear2"); 
let token3 = canvas.tokens.placeables.find(t => t.data.name === "TorGear3");

new Sequence()
    .sound("Audio/Sounds/gears_of_hate_2_15s.mp3")
    .animation()
        .on(token1)
        .rotateIn(token1.data.rotation + 72, 2000,{ease: "easeInOutCubic",delay: -1000})
    .animation()
        .on(token2)
        .rotateIn(token2.data.rotation - 72, 2000,{ease: "easeInOutCubic",delay: -250})
    .animation()
        .on(token3)
        .rotateIn(token3.data.rotation + 72, 2000,{ease: "easeInOutCubic",delay: -250})
    .play();

Tile Target Sequencer Macro

Another version that targets tiles directly, you'll need to figure out your tile names:

let token1 = canvas.drawings.get("mMa1oXBgiu4NZtcq")
let token2 = canvas.drawings.get("zEwVmZ4ByRE5uDYm")
let token3 = canvas.drawings.get("zU6rNZriEQNvRWA3")

new Sequence()
   .animation()
     .on(token1)
     .rotateIn(218, 2000,{ease: "linear"})
   .animation()
     .on(token2)
     .rotateIn(142, 2000,{ease: "linear"})
   .animation()
     .on(token3)
     .rotateIn(233, 2000,{ease: "linear"})
   .play();

v10 Potential Fix

From Masterhawk on v10: I'm currently using V10 right now and have the Tomb Working. Until vehicles and mechanisms gets updated though, you have to use this pull request (also attached as a zip) https://github.com/grandseiken/foundryvtt-vehicles-and-mechanisms/pull/18 since the dev hasn't updated it yet (all he needs to do is accepted that PR) and the rotating gears macro wants this line

let cog2IR = cog2d.document.data.rotation;

changed to let cog2IR = cog2d.document.rotation;