-
Notifications
You must be signed in to change notification settings - Fork 26
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
Decouple block type from block variant #43
Conversation
f499a7e
to
4d7445a
Compare
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.
Great! Much better than what we had before, thanks for working together on this!
Again, my only concern is that having the type NodePath
instead of Node
doesn't really make sense. When we say something is of Node
type, we mean that it has some specified properties and methods. The properties and methods of Node
are completely different to the ones in the NodePath
type, which is really just a String
path that points to a node (of any class) relative to the root. But for now, I suppose TYPE_NODE_PATH
can correspond to anything that is a Node
.
I'd love to hear some other opinions on this too!! Is it worth integrating Godot's type system with ours? Or should we define the types ourselves (i.e. with Strings)?
For the original custom NODE, is it Godot's |
You can easily get a node from a node path. Think it in another way: how are we going to persist a node in a resource? Try creating a new resource and then add
Yes! Other opinions welcome! |
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.
I think this makes sense. It is sad to have to enumerate all the built-in variant types by hand. It is weird that Variant.Type
does not behave as a dict (which has a find_key
method) while user-defined enum
s do.
closest_snap_point = null | ||
for snap_point in snap_points: | ||
if not snap_point is SnapPoint: | ||
push_error('Warning: a node in group "snap_point"snap is not of class SnapPoint.') |
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.
I don't think you mean to include the literal "snap_point"snap
string in the message here?
push_error('Warning: a node in group "snap_point"snap is not of class SnapPoint.') | ||
continue | ||
if snap_point.block == null: | ||
push_error("Warning: a snap point does not reference it's parent block.") |
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.
push_error("Warning: a snap point does not reference it's parent block.") | |
push_error("Warning: a snap point does not reference its parent block.") |
But can we be more specific about which snap point is problematic?
# HACK: make signals work with new entry nodes. NONE instead of STRING type allows | ||
# plain text input for function name. Should revamp signals later | ||
b.block_format = "On signal {signal: NONE}" | ||
b.block_format = "On signal {signal: NIL}" |
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.
The "HACK" comment here refers to "NONE" but you're changing it to NIL here.
Yeah, I don't think we need to do this mapping at all in the future. We should embrace "the resource way" and get rid of this custom serializing. |
And use Variant.Type enum for the Value block variant. This means we stick to GDScript variants for the values represented by Value blocks: - A constant like "viewport width" - A property like "rotation" - A parameter like A in "A + B" - The resulting value of "A + B" The slots that can contain Value blocks also have a matching variant type now. Unfortunately there is no way to convert the native Variant.Type enum to string, so still we need dictionaries to go back and forth the string formatting. Previously there was a custom NODE type, although unused. This is now replaced by NODE_PATH, which is the same thing that Godot does in the PackedScene resource when exporting a property of type Node. Also: improve readability of drag manager and use a constant for the minimum slot distance. Update addons/block_code/ui/blocks/utilities/snap_point/snap_point.gd Co-authored-by: Will Thompson <[email protected]>
I'm merging this as it's a big refactor. Sorry everyone, I can help to resolve conflicts in your work in progress. |
@manuq Well we wouldn't really be persisting a |
I think yes, we should be persisting the node path and gettng the node at runtime. In the same way as PackedScene does.
I don't know what kind of blocks are you thinking, but for sure the BlockType enum can be extended to have "BlockType.ELEFANT" for example. The BlockType.VALUE is meant for representing Variants. Maybe this will be more clear once we stop doing our own serialization/deserialization and use Resources all around.
Yes, for sure, but not for persisting. Variants can be serialized to text, be serialized as binary and stored to disk, transferred via network, etc. |
I guess I'm just not understanding why we need our So I guess I'm saying I see no benefit to having For now I think it's okay if we just keep every |
And use Variant.Type enum for the Value block variant.
This means we stick to GDScript variants for the values represented by Value blocks:
The slots that can contain Value blocks also have a matching variant type now.
Unfortunately there is no way to convert the native Variant.Type enum to string, so still we need dictionaries to go back and forth the string formatting.
Previously there was a custom NODE type, although unused. This is now replaced by NODE_PATH, which is the same thing that Godot does in the PackedScene resource when exporting a property of type Node.
Also: improve readability of drag manager and use a constant for the minimum slot distance.