dev7355608 / vision-5e

Foundry VTT Module: Vision/Detection Modes for D&D 5e
https://foundryvtt.com/packages/vision-5e
MIT License
13 stars 12 forks source link

[Feature Request] use libWrapper to patch DetectionMode.prototype._canDetect #77

Closed Eligarf closed 7 months ago

Eligarf commented 7 months ago

I updated the Stealthy module to use DetectionMode.prototype._canDetect in order to clean up its general processing and be able to handle stealth vs hearing modes, but I've run into the problem where my solution works only on those servers where Stealthy happens to patch in the right order with vision-5e. I used libWrapper to patch that function, and it should be able to work perfectly fine regardless of which of our implementations runs first, but I see you directly assigning a new _canDetect function in patches.js, so if yours runs second, it will stomp mine.

The changes unfortunately seemed to work fine with vision-5e on both of my test worlds, so I published the changes to Stealthy this morning, and am now figuring out how to re-release the previous release over top of it for the time being, but any workarounds/suggestions would be appreciated.

dev7355608 commented 7 months ago

Most of Vision 5e's detection modes override _canDetect without calling the base _canDetect. If you wrap CONFIG.Canvas.detectionModes.basicSight.prototype._canDetect (in a setup hook so that it runs after Vision 5e replaces the detection modes) instead of DetectionMode.prototype._canDetect, I imagine it would work. Your previous implementation with testVisibility had the advantage that testVisibility is unlikely to be overridden the subclasses of DetectionMode completely.

You could also the patch following, then I can remove the compatibility code for Stealthy from Vision 5e completely. I see you removed Umbral Sight handling from Stealthy: I'll add the friendlyUmbralSight setting to Vision 5e. With detection modes should be affected by Stealthy is probably better handled by Stealthy than Vision 5e.

https://github.com/dev7355608/vision-5e/blob/a5a016dc2aced3711071145f40609f691ba11862/scripts/compatibility.mjs#L48-L109

Eligarf commented 7 months ago

I'll try to go the route that removes any need for you to have any Stealthy compatability code at all! Thanks for the pointers, and I'll update this when I think I've untangled you.

Eligarf commented 7 months ago

3.14.2 has been published now where I've hooked the specific detection modes that stealth might apply against if your module is enabled. I believe you should be able to remove that Stealthy compatibility code now. Thanks again.

Eligarf commented 7 months ago

One problem I'm running into now is I can't tell when darkvision is actually being used vs basic vision when I examine the visionSource object in my patch code. Foundry's native code has the id set to darkvision or basic when I patch DetectionMode.prototype._canDetect, but no such luck with your overrides. Is there some proper way I can now tell the difference when I patch your functions?

dev7355608 commented 7 months ago

With Vision 5e basicSight is always Darkvision (and just Darkvision: no Light Perception, which is a separate mode), no matter what the Vision Mode is set to: so you don't have to check the Vision Mode at all.

Eligarf commented 7 months ago

I see: basicSight = Darkvision, LightPerception = regular vision (old basic vision). Thanks, I can make this work.