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

BlockCanvas: Implement drag & drop the file from resource FileSystem #305

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

starnight
Copy link
Contributor

Dragging the files from resource FileSystem shows the files' type as
"files". So, allow the "files" type in _can_drop_data() and handle it in
_drop_data(). Then, implement getting the files' resource paths as
Variable blocks with _drop_files() in detail.

https://phabricator.endlessm.com/T35712

@starnight
Copy link
Contributor Author

This depends on #296. So, set it as draft now.

@starnight starnight marked this pull request as draft November 5, 2024 08:32
@starnight
Copy link
Contributor Author

Here is the demo video:

Screencast.From.2024-11-05.16-28-04.mp4

@starnight starnight force-pushed the T35712-drag-drop-resource-file branch from a5ce51c to c838758 Compare November 5, 2024 09:38
@starnight starnight force-pushed the T35712-drag-drop-resource-file branch from c838758 to d9f104a Compare November 19, 2024 11:24
Define the format "{const <parameter name>: <type>}" as constant
parameter value. And, it is a kind of in parameter value, but never
changes.

https://phabricator.endlessm.com/T35712
@starnight starnight force-pushed the T35712-drag-drop-resource-file branch from d9f104a to 714c31f Compare November 20, 2024 06:05
@starnight starnight marked this pull request as ready for review November 20, 2024 06:06
@starnight
Copy link
Contributor Author

starnight commented Nov 20, 2024

Here is the latest demo video:

Screencast.From.2024-11-19.19-40-13.mp4

Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving some nits. Good work!

addons/block_code/code_generation/blocks_catalog.gd Outdated Show resolved Hide resolved
if file_path == "":
return null

var file_name = file_path.get_file()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a chance that this string doesn't have a valid file? Eg. what would happen if the user removes the file from the filesystem? In that case what does get_file() return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_file() simply returns the file name part of the "string". Fixed in the new commit which checks with FileAccess.file_exists() and ResourceLoader.exists().

addons/block_code/ui/block_canvas/block_canvas.gd Outdated Show resolved Hide resolved
addons/block_code/code_generation/blocks_catalog.gd Outdated Show resolved Hide resolved
# const_parameter is a kind of in_parameter with default value, but never
# changes value.
var parameter_const := _append_input_parameter(parameter, id)
parameter_const.visible = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do exactly? I want to make sure the extra syntax is really worth it since it seems like the regular input parameter would work fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clears the in parameter's "visible" to avoid modify the value from users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if the in parameter shows up, it displays the full file path as a long text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Without the input parameter in the display:
    Screenshot From 2024-11-27 17-10-07
  • With the input parameter in the display:
    Screenshot From 2024-11-27 17-12-16

Have get_resource_block_definition() providing resource block's
definition. It uses constant parameter value with key "file_path" to
hold the resource file's path information.

https://phabricator.endlessm.com/T35712
… dock

Dragging the resources from the filesystem dock shows the object's type
as "files". So, allow the "files" type in _can_drop_data() and handle it
in _drop_data(). Then, implement getting the resource's file path as a
Variable block with _drop_files() in detail.

And, because Godot allows dragging multiple files at the same time, this
implemention parses the "files"' paths, then generates the corresponding
block definition with get_resource_block_definition() and sets default
"file_path" for each file's path.

Besides, to avoid the dropped blocks overlap with each others on the
canvas, each block biases its position a little bit automatically.

https://phabricator.endlessm.com/T35712
…ile blocks

Drag & drop resouce files as blocks into canvas has been implemented.
This commit focuses on serializing from the resource file blocks to AST
nodes and values.

The resource file's path is saved as in the arguments "file_path" feild.
So, pass the arguments, which may have "file_path" into
get_block_definition() to rebuild resource file's block definition.

https://phabricator.endlessm.com/T35712
@starnight starnight force-pushed the T35712-drag-drop-resource-file branch from 714c31f to 96a7da3 Compare November 27, 2024 09:06
Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@manuq manuq merged commit 2867d30 into main Dec 5, 2024
3 checks passed
@manuq manuq deleted the T35712-drag-drop-resource-file branch December 5, 2024 14:26
starnight added a commit that referenced this pull request Dec 9, 2024
Add how to drag & drop a resource file as getter block from the Resource
Filesystem dock.

This follows #305.

https://phabricator.endlessm.com/T35712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants