Add property default and reset js bindings #5156
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Identify the Bug or Feature request
resolves #5152
The linked issue misdiagnoses the issue as
Token.setProperty
setting a value differently and not being identified as equalling the default to reset.Actually it's only the Edit Token dialog that resets properties that way.
The lack of functions for resetting properties and determining what the default is however prevents implementing this behaviour yourself, so this patch resolves it by adding required functions.
Description of the Change
This refactors the Token functions slightly to make the property default code and property evaluator reusable, and adds javascript bindings.
Possible Drawbacks
This allows evaluating the defaults even if there is a value set, and an obscure enough campaign might hide logic in there that is usually obscured by a non-default value being present in that property.
Documentation Notes
token.resetProperty(name) Function
• Introduced in version 1.17
Returns true if the property was reset, false if it was not e.g. because you don't own it.
Usage
See resetProperty() for MTScript equivalent.
token.getPropertyDefault(name) Function
• Introduced in version 1.17
Returns the text of the default value if it exists, null if it didn't or you don't own the token.
Usage
See getPropertyDefault() for MTScript equivalent.
token.getEvaluatedPropertyDefault(name) Function
• Introduced in version 1.17
Returns the value of the default's expression, evaluated in the context of the token if it exists, null if it didn't or you don't own the token.
Usage
See getPropertyDefault() and evalMacro() for MTScript equivalent.
Release Notes
Token.resetProperty
,Token.getPropertyDefault
andToken.getEvaluatedPropertyDefault
so JavaScript macros can reset properties if they match their default value.This change is