ruipin/fvtt-lib-wrapper

How to reference game system defined classes

Closed this issue · 4 comments

How do I wrap a game system specific class's method. I would like to wrap ActorSheet5e _prepareArmorClassAttribution.
I tried going through CONFIG.Actor.sheetclasses;

CONFIG.Actor.sheetClasses.character["dnd5e.ActorSheet5eCharacter"].cls.prototype._prepareArmorClassAttribution

which points to the correct method, but libwrapper rejects the string

I was not aware that some classes are hidden behind arrays that contain ..

By default, you can access arrays just by the standard dot-notation, e.g. A["abc"] would be equivalent to A.abc. However, if the array index contains a dot, libWrapper will think those correspond to two different indexes. For example, A["abc.def"] is not equivalent to A.abc.def, as that would correspond to A["abc"]["def"]. This is why the above does not work.

I will look into adding support for actual array notation ASAP.

v1.8.0.0 adds support for string Array indexes. Make sure to check the documentation for details, specifically fdf6960#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R289-R293

The path can contain string array indexing. For example, 'CONFIG.Actor.sheetClasses.character["dnd5e.ActorSheet5eCharacter"].cls.prototype._onLongRest' is a valid path.
It is important to note that indexing in libWrapper does not work exactly like in JavaScript:
  - The index must be a single string, quoted using the ' or " characters. It does not support e.g. numbers or objects.
  - Quotes i.e. ' and " can be escaped with a preceding '\'.
  - The character '\' can be escaped with a preceding '\'.

Closing. Feel free to reopen if you encounter any issues, or this didn't answer your question.

Wow that was fast. Many thanks that's great.

And works perfectly