-
-
Notifications
You must be signed in to change notification settings - Fork 238
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
Apply type hints to example scripts to avoid triggering any GDScript warnings or errors #1975
Apply type hints to example scripts to avoid triggering any GDScript warnings or errors #1975
Conversation
Thanks for your PR! Firstly (I don't have any strong feelings on this), but why make all implicit static typing explicit? The gdscript styleguide says: Include the type hint when the type is ambiguous, and omit the type hint when it's redundant. I'm only referring to places where I felt the type was already implied enough (e.g. Secondly, I'm not too happy about:
|
Thanks for the feedback! When I make edits, do you prefer I use amend commits so there is only one commit in the PR or have each round of changes be its own commit?
If it were code for my personal project, I'd totally agree with you on the implicit typing. However, my approach was to turn on all the errors I could in the project settings in order to accommodate users with a range of possible error settings.
I think I found a way around this using
That's fair, I can use a different approach for now. Are you okay with the way I gave the subsystems |
Feel free to add more commits, it's easier to follow your changes that way. We squash the PR into one commit when merging.
That makes sense. Feel free to continue doing it then. It's a bit annoying to deviate from the gdscript style guide there, but it would indeed be nice if people can use these scripts whatever error settings they have on.
Perfect!
Yeah sure you can give them names, although they might change a bit or we might remove them again later on, not sure yet. |
I've finished adding static types to the other examples and implemented your suggestions. Happy new year! |
Did a bit more thorough testing on my PR and realized that I broke a few things by replacing some uses of e.g. %Title.something with @onready var title : Label = %Title
#later
title.something because certain properties and overrides seem to be set before the |
if it worked before the refactor and now you need to create all those getters, I feel like the PR is not an improvement (at least in that area) I'm all in for adding types to variables, but I feel like the PR is growing a bit out of proportion. |
Congrats on getting the automated unit tests working! It seems like maybe there is a file I should add to my branch to make the CLI happy? |
Try rebasing/merging the latest changes from |
Thanks! Hopefully I did that correctly. |
58c5bfc
to
7aac8e1
Compare
Sorry for the duplicated commits. I tried rebasing and there were some merge conflicts, which I'm still kind of nooby at resolving. I think HEAD is where I want it nevertheless. |
7aac8e1
to
09b5d8d
Compare
Reverted all changes to Dialogic Subsystems as per suggestions of @CakeVR :) |
@@ -80,7 +80,7 @@ func _ready(): | |||
if Engine.is_editor_hint(): | |||
resized.connect(_update_debug_origin) | |||
|
|||
if !ProjectSettings.get_setting('dialogic/portraits/default_portrait', '').is_empty(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference here? I remember adding the is_empty
check before. Not sure why (or maybe I'm just not remembering correctly). @Jowan-Spooner do you recall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I forgot I made this change. It's completely irrelevant to the rest of the PR, so I'll revert it. It just came when I was playing around with the code to make sure I understood it well enough :)
addons/dialogic/Modules/DefaultLayoutParts/Base_Default/default_layout_base.gd
Show resolved
Hide resolved
@nlupugla left a couple comments. Overall I think it should be good. The code looks super ugly now, but I guess there's not much we can do about it. Waiting for @Jowan-Spooner approval before merging 👍 |
Thanks Emi! Really appreciate the review :) I'm sorry for butchering everyone's code with all the type hints, |
As Cake pointed out var inferred := 123 var explicit: int = 123 So I tried to enforce that on the layers.
@nlupugla It looks good overall. Why did you add static tpying to a bunch of dialogic-nodes and to some base scripts? Is that necessary? Those shouldn't be copied to the user directory I think... From my understanding this would only have to be on the layer scripts, wouldn't it? I would prefer to keep this aggressive static typing contained to where it's REALLY necessary. |
Totally agreed! I'll check again some time today that all the changes are necessary. Thanks for all the help and feedback :) |
I'm not certain but I would assume you could get rid of the changes in:
And also
|
func _on_textbox_new_text(): | ||
if DialogicUtil.autoload().Input.auto_skip.enabled: | ||
func _on_textbox_new_text() -> void: | ||
var input_system: Node = DialogicUtil.autoload().get(&'Input') | ||
var auto_skip: DialogicAutoAdvance = input_system.get(&'auto_skip') | ||
if auto_skip.get(&'enabled'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of pattern is my solution to avoid horrible lines like
((DialogicUtil.autoload().get(&'Input') as Object).get(&'auto_skip') as Object ).get(&'enabled')
It does mean that what used to be a one-liner: DialogicUtil.autoload().Input.auto_skip.enabled
is now three lines. If my solution is still too ugly, I can revert it for now and try to coordinate with the subsystem type PR.
…it will raise GDScript errors until the subsystems get types.
Thanks! Glad this is done for now. Hope the statically typed subsystems make it in soon. |
Awesome! Thanks for all the help and discussion :) |
…warnings or errors (dialogic-godot#1975) Adds static type hints to default style layers --------- Co-authored-by: Jowan-Spooner <raban-loeffler@posteo.de> Co-authored-by: Jowan-Spooner <42868150+Jowan-Spooner@users.noreply.github.com>
Previously, several of the scripts that users were meant to edit in a custom layer were not fully statically typed. This meant that a user with strict static typing set up in their project settings would be bombarded with errors upon opening these scripts. My goal is to statically type all of the user-facing scripts so that even a user with the strictest possible GDScript settings can edit the Dialogic example scripts without an issue. So far, I have typed the visual novel example. I will continue with the other example scenes, but I wanted to create this draft to make sure I'm on the right track and this work is appreciated.