p4535992 / conditional-visibility

a FoundryVTT module to hide tokens from some players, but not from others
MIT License
5 stars 8 forks source link

Still can't set back to visible in 0.3.4 #8

Closed azurespear closed 2 years ago

azurespear commented 2 years ago

I'm running the 0.3.4 version and the invisible function still has issue Still can't set back the token to be visible when set "Link Actor data". This time there is no error message in the console image

image

lucasmiranda2711 commented 2 years ago

I actually found why this issue is happening, it has to do with the document update trough the game emit, when it's updated it only considers one of the updated variables from the array because it's on the same id, to be more clear what's hapenning is:

if (effect.parent.isOwner) {
                    ConditionalVisibility.INSTANCE.actorUpdates.push({
                        _id: effect.parent.id,
                        [baseflag + status.visibilityId]: false,
                    });
                }
                if (Array.from(this.effectsByCondition().values()).filter((e) => effect.parent.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, e.visibilityId) ?? false).length == 1) {
                    if (effect.parent.isOwner) {
                         ConditionalVisibility.INSTANCE.actorUpdates.push({                   //we shouldn't add another item to our array with the same id
                             _id: effect.parent.id,
                             [baseflag + 'hasEffect']: false,
                         });
                    }

Instead I'd suggest we do something like:

if (effect.parent.isOwner) {
                if (Array.from(this.effectsByCondition().values()).filter((e) => effect.parent.getFlag(CONDITIONAL_VISIBILITY_MODULE_NAME, e.visibilityId) ?? false).length == 1) {
                    if (effect.parent.isOwner) {
                       ConditionalVisibility.INSTANCE.actorUpdates.push({
                        _id: effect.parent.id,
                        [baseflag + status.visibilityId]: false,[baseflag + 'hasEffect']: false    //adding the two conditions on the same push
                    });
                    }
                    setTimeout(() => {
                        effect.parent.getActiveTokens()?.forEach((e) => {
                            e.alpha = 1;
                            e.visible = true;
                            e.data.hidden = false;
                        });
                    }, 350);
                }
else{
                    ConditionalVisibility.INSTANCE.actorUpdates.push({
                        _id: effect.parent.id,
                        [baseflag + status.visibilityId]: false,
                    });
                }}
p4535992 commented 2 years ago

This issue is closed, because the new series 0.4.X is just to different, checkout the last version of the module.