ironmonk88 / monks-combat-details

GNU General Public License v3.0
11 stars 7 forks source link

[BUG] ripper Carousel incompatibility #45

Open eryon opened 1 year ago

eryon commented 1 year ago

Describe the bug When used alongside ripper's Carousel Combat Tracker, the carousel visibility buttons don't work. lib-wrapper blames this Combat Details module.

To Reproduce Steps to reproduce the behavior:

  1. Enable both modules
  2. Load the world and see the attached warning in the console
  3. Setup an encounter with some enemies
  4. Set their visibility using the right-click option or through the encounters tab
  5. Try to toggle visibility using the dock or the encounters tab; it does not update the state in all places (just the one you click)

Expected behavior Visibility update should be reflected wherever it's shown. Specifically using the one in the dock should toggle the one in the encounter as well as the token visibility.

Screenshots If applicable, add screenshots to help explain your problem.

Please complete as much of the following information as possible:

Additional context Carousel tracker module -- https://wiki.theripper93.com/free/combat-tracker-dock

ironmonk88 commented 1 year ago

It looks like it's working correctly for me.

theripper93 commented 11 months ago

The issue is this beeing a mixed wrapper i think https://github.com/ironmonk88/monks-combat-details/blob/main/monks-combat-details.js#L174

You can use the same method i use to add extra condition while still keeping it a WRAPPER instead of MIXED https://github.com/theripper93/combat-tracker-dock/blob/master/scripts/config.js#L406

theripper93 commented 10 months ago

Even after the update this is still throwing unecessary compatibility errors

you can just change

            patchFunc("Combatant.prototype.visible", function (wrapped, ...args) {
                if (this.hidden) return this.isOwner;
                if ((setting('hide-enemies') && !this.combat.started) || (setting("hide-until-turn") && this.combat.started && getProperty(this, "flags.monks-combat-details.reveal" ) !== true)) {
                    if (this.combat && !game.user.isGM) {
                        let idx = this.combat.turns.findIndex(t => t.id == this.id);
                        return this.hasPlayerOwner || (this.combat.started && (this.combat.round > 1 || !setting("hide-until-turn") || this.combat.turn >= idx));
                    }
                }
                return wrapped(...args);
            }, "MIXED");

to

            patchFunc("Combatant.prototype.visible", function (wrapped, ...args) {
                if (this.hidden) return wrapped(...args);
                if ((setting('hide-enemies') && !this.combat.started) || (setting("hide-until-turn") && this.combat.started && getProperty(this, "flags.monks-combat-details.reveal" ) !== true)) {
                    if (this.combat && !game.user.isGM) {
                        let idx = this.combat.turns.findIndex(t => t.id == this.id);
                        return wrapped(...args) && (this.hasPlayerOwner || (this.combat.started && (this.combat.round > 1 || !setting("hide-until-turn") || this.combat.turn >= idx)));
                    }
                }
                return wrapped(...args);
            }, "WRAPPER");

and it should stop throwing warnings (the line is https://github.com/ironmonk88/monks-combat-details/blob/main/monks-combat-details.js#L196C1-L205C25 )


That said, if you want to simplify you don't even need to check for CCT, you can just substitute the whole block with this

patchFunc("Combatant.prototype.visible", function (wrapped, ...args) {
    function isVisible() {
        if (this.hidden) return this.isOwner;
        if ((setting("hide-enemies") && !this.combat.started) || (setting("hide-until-turn") && this.combat.started && getProperty(this, "flags.monks-combat-details.reveal") !== true)) {
            if (this.combat && !game.user.isGM) {
                let idx = this.combat.turns.findIndex((t) => t.id == this.id);
                return this.hasPlayerOwner || (this.combat.started && (this.combat.round > 1 || !setting("hide-until-turn") || this.combat.turn >= idx));
            }
        }
        return true;
    }
    return wrapped(...args) && isVisible.bind(this)();
}, "WRAPPER");