Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reference game system defined classes #46

Closed
tposney opened this issue Jul 29, 2021 · 4 comments
Closed

How to reference game system defined classes #46

tposney opened this issue Jul 29, 2021 · 4 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@tposney
Copy link

tposney commented Jul 29, 2021

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

@tposney tposney added the question Further information is requested label Jul 29, 2021
@tposney tposney changed the title How to reference system defined classes How to reference game system defined classes Jul 29, 2021
@ruipin
Copy link
Owner

ruipin commented Jul 29, 2021

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.

@ruipin ruipin added the enhancement New feature or request label Jul 29, 2021
@ruipin
Copy link
Owner

ruipin commented Jul 29, 2021

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.

@ruipin ruipin closed this as completed Jul 29, 2021
@tposney
Copy link
Author

tposney commented Jul 30, 2021

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

@tposney
Copy link
Author

tposney commented Jul 30, 2021

And works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants