xaukael / card-tokens

Drag cards to the canvas
MIT License
0 stars 2 forks source link

Issue with World Script Activation of TokenMagic Effects #10

Open brunocalado opened 1 year ago

brunocalado commented 1 year ago

Description: I'm seeking assistance with getting the TokenMagic World Script to work properly. I've attached the code snippet that I'm currently using. The issue I'm experiencing is that the script only activates the effects after I interact with the card on the canvas. Ideally, the effects should be triggered immediately regardless of how I place the card. I have also attached a video demonstrating this behavior.

Script

// https://foundryvtt.wiki/en/basics/world-scripts

Hooks.on("createToken", async function addShadow(cardToken) {
  //Hooks.on('createToken', (cardToken) => {
  console.log("======================")
  console.log(cardToken);
  console.log("======================")

  // 
  if (!cardToken.actor.flags.world?.card) return;
  cardToken.updateSource({
    sight: {
      enabled: false // disable vision
    },
    displayName: 0
  });

  // TokenMagic
  await tokenMagicGlow(cardToken);

});

async function tokenMagicGlow(cardToken) {
  //await TokenMagic.deleteFilters(cardToken.object);

  let params = [{
      filterType: "glow",
      filterId: "superSpookyGlow",
      outerStrength: 4,
      innerStrength: 0,
      color: 0xdd1111,
      quality: 0.5,
      padding: 10,
      animated: {
        color: {
          active: true,
          loopDuration: 3000,
          animType: "colorOscillation",
          val1: 0xff1111,
          val2: 0x990000
        }
      }
    },
    {
      filterType: "shadow",
      filterId: "myShadow",
      rotation: 35,
      blur: 2,
      quality: 5,
      distance: 20,
      alpha: 0.7,
      padding: 10,
      shadowOnly: false,
      color: 0x000000,
      zOrder: 6000,
      animated: {
        blur: {
          active: true,
          loopDuration: 500,
          animType: "syncCosOscillation",
          val1: 2,
          val2: 4
        },
        rotation: {
          active: true,
          loopDuration: 100,
          animType: "syncSinOscillation",
          val1: 33,
          val2: 37
        }
      }
    }
  ];

  //await TokenMagic.addUpdateFilters(cardToken.object, params);  
  await TokenMagic.addFilters(cardToken.object, params);
  //await cardToken.object.TMFXaddUpdateFilters(params);

}

https://github.com/xaukael/card-tokens/assets/4999783/27337817-4a55-439a-bdb6-7aaf41876314

xaukael commented 1 year ago

This should be done in the preCreateToken hook.

brunocalado commented 1 year ago

This should be done in the preCreateToken hook. preCreateToken generates an error. createToken work as in the video. Thank you for your response. image

xaukael commented 1 year ago

cardToken.updateSource() would be used to set properties of the token in the preCreateToken hook. I do not know if such a thing is possible with TokenMagic. You may have to bypass the TokenMagic.addFilters function and do what it does in the hook, which I expect is adding flags in flags.tokenmagic or something like that.