-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fixed Tool.updateEnabledState behavior and related changes #3800
Conversation
The setTargetLayerType(0) call in the ScriptedTool constructor happened before the ScriptedTool instance was set as the prototype of the provided script object. If the provided updateEnabledState would then set the "this.enabled" property, it would override the Tool.enabled property instead of changing it and cause all further attempts to change the "this.enabled" property to not affect the Tool.enabled property. Fixed by making sure the prototype is set before a possible call to updateEnabledState happens. Closes mapeditor#3756
The only known way to trigger this would be to implement a scripted tool that sets "this.enabled" to false in the "activated" callback.
The argument passed to registerTool is not entirely the same as the Tool instance it returns. Most of its properties are optional and some properties are only available on the Tool instance. The functions in ToolDefinition now define the type of 'this' as Tool. See mapeditor#3756
This looks great! 😃 Thank you for implementing this! The type update made me realize I was setting
|
I changed it because I realized it would sometimes be var tool = tiled.registerTool(name, toolDefinition);
tool.map; // null And when closing the last map, it will also be That said, in most cases, there will be a map, and most functions will not need to check this variable because they can't be called while the
These functions were already present in the |
Ah, I see. That all makes sense. The most accurate type is the best; even if it's rarely The only alternative I could think of is that you could have types that extend from |
Hmm, right, I guess we could have something like: interface ActiveTool extends Tool {
/**
* Currently active tile map.
*/
readonly map: TileMap;
} And then use |
Needed because otherwise TS assumes the references will never be null.
See #3756