fantasycalendar / FoundryVTT-Sequencer

This module implements a basic pipeline that can be used for managing the flow of a set of functions, effects, sounds, and macros.
Other
41 stars 19 forks source link

[BUG] - `.opacity()` changes only once until scene "re-renders" #170

Closed InnilToo closed 1 year ago

InnilToo commented 1 year ago

Describe the bug .opacity() breaks until the scene is re-rendered (I think). Basically, if I have a macro that contains a sequence with .opacity(), a token update, and then another sequence with .opacity only the first .opacity() happens. Example macro below. This is similar to #167.

const use = await item.use();
if (!use) return;

await new Sequence()
  .effect()
  .atLocation(token)
  .wait(750)
  .animation()
  .on(token)
  .opacity(0.0)
  .play({ remote: false });

await token.document.update(
  { x: 2500, y: 2500 },
  { animate: false }
);

await new Sequence()
  .effect()
  .atLocation(token)
  .wait(1500)
  .animation()
  .on(token)
  .opacity(1.0)
  .play({ remote: false });

To Reproduce Steps to reproduce the behavior:

  1. Run a macro with a sequence that changes token .opacity()
  2. Move the token with the same macro.
  3. The same macro contains another sequence that changes .opacity()
  4. Token retains the same opacity.
  5. Move a token or press ALT or otherwise for some change on the scene to make the token recognize the 2nd .opacity().

Expected behavior The opacity of the token changes with each sequence.

Setup:

Active modules:

Additional context Tried on a completely fresh world with the modules' default settings (except Item Macro hook).

Haxxer commented 1 year ago

What's the purpose of the .effect() in the macro?

Haxxer commented 1 year ago

Besides, you're not utilizing .waitUntilFinished() on the .animation() - does that alleviate the problem?

InnilToo commented 1 year ago

Without the .effect() the console started screaming: image I did initially use .waitUntilFinished() but it seemed to have not made any difference being or not being there.

Haxxer commented 1 year ago

That's because you are using .atLocation() on the (now nonexistent) effect. I highly recommend reading documentation on Sequencer basics in the wiki. I will take a look and see if there's something I can do to mitigate the bug.

InnilToo commented 1 year ago

Frankly, I have very little idea what I am doing. I tried to reduce the script as much as possible to figure out where the problem could be and to provide as much detail as I can. I managed to make it even shorter now.

const use = await item.use();
if (!use) return;

await new Sequence()
  .animation()
  .on(token)
  .opacity(0.0)
  .play({ remote: false });

await token.document.update(
  { x: 2500, y: 2500 },
  { animate: false }
);

await new Sequence()
  .wait(1500)
  .animation()
  .on(token)
  .opacity(1.0)
  .play({ remote: false });

If I remove the .wait(1500) then it doesn't even have a chance to hide. This worked on the previous versions, that's why I am reporting it as an issue. If it's a user please let me know.

Haxxer commented 1 year ago

It appears that even core Foundry has this issue:

await token.document.update(
  { alpha: 0.0 }
);

await new Promise(resolve => setTimeout(resolve, 1000));

await token.document.update(
  { x: token.document.x + 100 }
);

await new Promise(resolve => setTimeout(resolve, 1000));

await token.document.update(
  { alpha: 1.0 }
);

I ran a script that sets the alpha of a token to 0, waits 1 second, moves the token, then sets it back to 1 alpha, and I ran this with no modules installed and this does the same thing. That means that something is fundamentally broken in Foundry itself.

InnilToo commented 1 year ago

Thank you. Do you wish to report this or should I make an issue?

Haxxer commented 1 year ago

Already done: https://discord.com/channels/170995199584108546/1065764070680186930/1112419032595972156

InnilToo commented 1 year ago

This has been addressed in v11 - Build 300. Issue https://github.com/foundryvtt/foundryvtt/issues/9510. Thank you for being so helpful!