EndlesNights/dnd4eBeta

V11: Change to Measured Templates breaks Libwrapper Overrides

Closed this issue · 3 comments

Following error at startup:


This is *not* a libWrapper bug.

Find information about this system here: https://github.com/EndlesNights/dnd4eBeta

Ask the community for support:
- FoundryVTT Discord's #modules-troubleshooting channel: https://discord.gg/foundryvtt
- FoundryVTT Reddit: https://www.reddit.com/r/FoundryVTT

== Technical Details:
Detected by libWrapper.
Package ID= system:dnd4e
Error= Can't wrap 'MeasuredTemplate.prototype._getCircleShape', target does not exist or could not be found.

[Detected 2 packages: lib-wrapper, system:dnd4e]
    at new 🎁constructor (libWrapper-wrapper.js:111:11)
    at libWrapper-api.js:82:18
    at de (libWrapper-api.js:155:9)
    at 🎁register [as register] (libWrapper-api.js:525:14)
    at Object.fn (dnd4eBeta.js:283:13)
    at #call (foundry.js:730:20)
    at Hooks.callAll (foundry.js:687:17)
    at Game.initialize (foundry.js:8529:11)
    at 🎁call_wrapped [as call_wrapped] (libWrapper-wrapper.js:507:22)
    at 🎁libWrapperInit (libWrapper-api.js:805:11)```

``` 	libWrapper.register(
		'dnd4e',
		'MeasuredTemplate.prototype._getCircleShape',
		AbilityTemplate._getCircleSquareShape
	);

Is the offending code.

https://github.com/tc39/proposal-class-fields/blob/main/PRIVATE_SYNTAX_FAQ.md

Foundy.js line 52402

  static #getCircleShape(distance) {
    return new PIXI.Circle(0, 0, distance);
  }

Think they have gone a bit more miliant with stopping us overriding!

I think we need to override computeShape: (line 52351)

  /**
   * Compute the geometry for the template using its document data.
   * Subclasses can override this method to take control over how different shapes are rendered.
   * @returns {PIXI.Circle|PIXI.Rectangle|PIXI.Polygon}
   * @protected
   */
  _computeShape() {
    let {angle, width, t} = this.document;
    const {angle: direction, distance} = this.ray;
    width *= canvas.dimensions.distancePixels;
    switch ( t ) {
      case "circle":
        return MeasuredTemplate.#getCircleShape(distance);
      case "cone":
        return MeasuredTemplate.#getConeShape(direction, angle, distance);
      case "rect":
        return MeasuredTemplate.#getRectShape(direction, distance);
      case "ray":
        return MeasuredTemplate.#getRayShape(direction, distance, width);
    }
  }

So I tried putting an override of computeShape in our override of the shape class, but was not able to fix the issue.

I was able to fix the issue by wrapping computeShape, and more or less combining it with the old getCircleShape into a single if slightly messier method. Currently thrown into the v11 branch.