Giter VIP home page Giter VIP logo

Comments (4)

kelanel avatar kelanel commented on September 10, 2024

my only concern is tthat the existing code doesnt allow overwriting once set. So that would need to be added in logic wise to the macro.

from tokenmagic.

kelanel avatar kelanel commented on September 10, 2024

Here's my working best re-iteration:

let path1 = "/Images/Tokens/Custom/Disguises/" //change this to where you want to put disguises/forms to change

	  
	  // This macro contains a small tutorial : how to work with non-infinite loops and halfCosOscillation animType

// Click once to transform your token and again to revert to the original shape (thank to halfCosOscillation)

// There is 9 types of metamorphose
// 1 - Simple transition
// 2 - Dreamy
// 3 - Twist
// 4 - Water drop
// 5 - TV Noise
// 6 - Morphing
// 7 - Take off/Put on you disguise!
// 8 - Wind
// 9 - Hologram

// change the type here
let transitionType = 8;



// declare filter id (think to change the id for personal macros)
// each filterId should be unique to a player or gm to prevent collisions
// example : "brutusChthulhuPolymorph"
let polymorphFilterId = "myPolymorph";

// we put our code into an async function that will be called later
let polymorphFunc = async function () {

    for (const token of canvas.tokens.controlled) {
        let params;
        
        // Is the filter already activated on the placeable ? 
        if (token.TMFXhasFilterId(polymorphFilterId)) {
           
            // Yes. So we update the type in the general section and loops + active in the progress animated section, to activate the animation for just one loop.
            // "type" to allow you to change the animation type
            // "active" to say at Token Magic : "Hey filter! It's time to work again!"
            // "loops" so that Token Magic can know how many loops it needs to schedule for the animation.
            // Each animation loop decreases "loops" by one. When "loops" reach 0, "active" becomes "false" and the animation will be dormant again.
            // Thank to the halfCosOscillation, a loop brings the value of the property from val1 to val2. A second loop is needed to bring val2 to val1. This is useful for monitoring progress with back and forth movements.
            params =
                [{
                    filterType: "polymorph",
                    filterId: polymorphFilterId,
                    type: transitionType,
                    animated:
                    {
                        progress:
                        {
                            active: true,
                            loops: 1
                        }
                    }
                }];
			await token.TMFXaddUpdateFilters(params);
			let wait = async (ms) => new Promise((resolve)=> setTimeout(resolve, ms));
			await wait(1900)
			await TokenMagic.deleteFiltersOnSelected(polymorphFilterId)
        } else {
			let fp2 = new FilePicker({
				type: "image",
				current: path1,
				displayMode: "tiles",
				callback: path => {
					// change the target image here
					let targetImagePath = path;
					// No. So we create the entirety of the filter
					params =
					[{
						filterType: "polymorph",
						filterId: polymorphFilterId,
						type: transitionType,
						padding: 70,
						magnify: 1,
						imagePath: targetImagePath,
						animated:
						{
							progress:
							{
								active: true,
								animType: "halfCosOscillation",
								val1: 0,
								val2: 100,
								loops: 1,
								loopDuration: 1000
							}
						}
					}];
					token.TMFXaddUpdateFilters(params);	
					
				
			   
				},

        })
		fp2.browse();
			// all functions that add, update or delete filters are asynchronous
			// if you are in a loop AND/OR you chain these functions, it is MANDATORY to await them
			// otherwise, data persistence may not works.
			// this is the reason why we use an async function (we cant use await in a non-async function)
			// avoid awaiting in a forEach loop, use "for" or "for/of" loop.
		   
		}
	}

};

// polymorph async function call
polymorphFunc();

from tokenmagic.

Feu-Secret avatar Feu-Secret commented on September 10, 2024

Thanks for the file picking improvement.
@kelanel If you're Ok, I could add your macro to the TokenMagic compendium?

from tokenmagic.

Feu-Secret avatar Feu-Secret commented on September 10, 2024

Postponed.

from tokenmagic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.