diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..ac1becab --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +charset = utf-8 + +[*.gd] +indent_style = tab +max_line_length = 200 diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 73011e50..00000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,5 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: Create Internal Task - url: https://phabricator.endlessm.com/tag/baby_godot/ - about: Endless OS Foundation employees, please use this tag on Phabricator diff --git a/.github/ISSUE_TEMPLATE/public.yml b/.github/ISSUE_TEMPLATE/issue.yml similarity index 63% rename from .github/ISSUE_TEMPLATE/public.yml rename to .github/ISSUE_TEMPLATE/issue.yml index fd95efb4..d7c86765 100644 --- a/.github/ISSUE_TEMPLATE/public.yml +++ b/.github/ISSUE_TEMPLATE/issue.yml @@ -1,9 +1,9 @@ -name: Report Public Issue +name: Report Issue description: Report an issue with using the Godot Block Coding plugin body: - type: markdown attributes: - value: Thanks for taking the time to report an issue! If you're an employee of Endless OS Foundation, please track internal tasks [on Phabricator](https://phabricator.endlessm.com/tag/baby_godot/) instead. + value: Thanks for taking the time to report an issue! - type: textarea id: what-happened attributes: @@ -20,17 +20,31 @@ body: description: Can it be reliably reproduced, and if so, how? placeholder: | 1. Add a BlockCode child node - 2. Drag blocks X, Y, and Z to the editor + 2. Drag blocks X, Y, and Z to the editor 3. ... validations: required: true + - type: input + id: v + attributes: + label: Block Coding Plugin Version + description: What version of the plugin are you using? You can check in **Project** → **Project Settings** → **Plugins**. + placeholder: v0.0.0 + + - type: input + id: godot + attributes: + label: Godot Engine Version + description: What version of Godot are you using? You can copy it by clicking the version in **Help** → **About Godot…**. + placeholder: v0.0.0.stable + - type: input id: os attributes: label: Operating System description: What specific OS and version are you seeing the problem on? - placeholder: e.g. Windows 11, Fedora Silverblue 39, Ubuntu 22.04, etc. + placeholder: Windows 11, Fedora Silverblue 39, Ubuntu 22.04, etc. - type: textarea id: logs diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index a88a41a4..1ca97690 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -6,13 +6,20 @@ on: branches: - main +# Cancel any ongoing previous run if a PR is updated +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: pre-commit: name: Linting and Formatting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 - uses: actions/setup-python@v5 + with: + python-version: '3.11' - name: set PY run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - uses: actions/cache@v4 @@ -23,18 +30,23 @@ jobs: tests: name: Tests + strategy: + matrix: + godot-version: + - 4.3.0 + - 4.4.0-dev7 runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Setup Godot - uses: chickensoft-games/setup-godot@v2.0.1 + uses: chickensoft-games/setup-godot@v2.3.0 with: - version: 4.2.2 + version: ${{ matrix.godot-version }} use-dotnet: false - name: Initialize Godot run: | godot --path . --headless --import - name: Run tests run: | - godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit + godot --path . --headless -s addons/gut/gut_cmdln.gd -gexit diff --git a/.github/workflows/godot-asset-library.yaml b/.github/workflows/godot-asset-library.yaml index 69c291b7..e5941831 100644 --- a/.github/workflows/godot-asset-library.yaml +++ b/.github/workflows/godot-asset-library.yaml @@ -11,9 +11,9 @@ jobs: name: Push new release steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Push to Godot Asset Library - uses: wjt/godot-asset-lib-action@9cce3792b504bec69eb06b852b008d095e372f56 + uses: deep-entertainment/godot-asset-lib-action@v0.6.0 with: username: ${{ secrets.GODOT_ASSET_LIBRARY_USERNAME }} password: ${{ secrets.GODOT_ASSET_LIBRARY_PASSWORD }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f5954e68..0b6a47d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,17 +2,15 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - repo: https://github.com/Scony/godot-gdscript-toolkit - # Use this commit from the master branch until the next stable release with - # - rev: f836958a4487e31e3c5ab35c57c7a2128b7e2303 + rev: 4.3.3 hooks: - id: gdformat args: [--line-length=200] -files: ^(addons/block_code/(?!lib/).*|tests/.*)$ +files: ^(addons/block_code/(?!lib/|locale/).*|tests/.*)$ diff --git a/.tx/config b/.tx/config new file mode 100644 index 00000000..71af3289 --- /dev/null +++ b/.tx/config @@ -0,0 +1,8 @@ +[main] +host = https://www.transifex.com + +[o:endless-os:p:godot-block-coding:r:all] +source_file = addons/block_code/locale/godot_block_coding.pot +source_lang = en +file_filter = addons/block_code/locale/.po +type = PO diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..0818b135 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +tech AT endlessos DOT org. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/addons/block_code/README.md b/addons/block_code/README.md index 9fdf4771..3073ad88 100644 --- a/addons/block_code/README.md +++ b/addons/block_code/README.md @@ -5,23 +5,25 @@ Experimental plugin by [Endless OS Foundation](https://endlessos.org) that intro [![Godot asset](https://img.shields.io/badge/Asset_Library-Block_Coding-blue?logo=godot-engine)](https://godotengine.org/asset-library/asset/3095) [![Latest release](https://img.shields.io/github/v/release/endlessm/godot-block-coding?label=Release&logo=github)](https://github.com/endlessm/godot-block-coding/releases) +[![Youtube video](https://i.ibb.co/B2Y11n5/Bildschirmfoto-20241213-173815.png)](https://www.youtube.com/watch?v=WlUN7Zz0Djg) + ## Background Our aim is to reduce the learning curve faced by learners who are on the early part of their journey towards becoming game developers. Learners within our target audience understand game concepts, but have never used Godot (or any other game engine) before, and do not have programming experience. Ordinarily, such learners are faced with the challenge of learning their way around Godot's powerful, complex editor UI, combined with the additional challenge of learning to code for the first time as they navigate the ins and outs of GDScript. With this project, we aim to reduce the height of the mountain that such learners have to climb. Specifically, we aim to eliminate the requirement of learners having to simultaneously learn to code while building their first games. Instead of writing GDScript to implement games, this plugin enables learners use block coding. Tools like [Scratch](https://scratch.mit.edu/), [Blockly](https://developers.google.com/blockly), and [MakeCode](https://www.microsoft.com/en-us/makecode) have demonstrated that block coding can be much more accessible and intuitive to beginners than textual programming—we are bringing those concepts into Godot to help learners become familiar with some aspects of Godot itself while simplifying the creation of their first games. -### Constraints - -In order to be learner-friendly, we have to implement blocks at a suitable level of abstraction. For example, in GDScript you would typically move a sprite around the screen by examining input events and adjusting a sprite's movement vector accordingly—but we do not wish to express this level of detail in blocks. Instead, we lean much more towards the kinds of blocks you can find in MakeCode Arcade, such as having a single block for "move mySprite with buttons". - -Expressing an appropriate layer of abstraction is perhaps the most challenging aspect of this project, and will likely place limits upon what can be achieved with this tool. We do not aim to express the full power of Godot & GDScript with this block coding plugin, but rather, our objective is to provide a gentler introduction to Godot for learners, such that they can get familiar with other aspects of the Godot Editor and learn programming concepts while creating basic games. We envision that learners would use block coding as a stepping stone and then later progress onto learning GDScript. +In order to be learner-friendly, we implement blocks at a suitable level of abstraction. For example, we have blocks that allow the user to trivially connect keyboard and gamepad input to the movement of a particular game element, and to make the score show up on-screen. That abstraction does place limits on what can be achieved with this tool, while still allowing us to provide a gentler introduction to Godot for learners, such that they can get familiar with other aspects of the Godot Editor and learn programming concepts while creating basic games. We envision that learners would use block coding as a stepping stone and then later progress onto learning GDScript. That said, we are in no way opposed to having this project grow to be able to create more complex games, as long as it does not negatively affect the experience for early stage learners. +See our [pedagogy and audience documentation](docs/PEDAGOGY.md) for more info. + ## Getting Started -1. Install the plugin through the Godot AssetLib searching for the name +1. Make sure you have Godot 4.3 or a newer version installed. + +2. Install the plugin through the Godot AssetLib searching for the name Block Coding. You can also download it from the online [Asset Library](https://godotengine.org/asset-library/asset/3095) and import it through AssetLib. Alternatively, you can clone the git repository and @@ -30,13 +32,9 @@ That said, we are in no way opposed to having this project grow to be able to cr project, reload the project once after opening it for the first time to resolve any errors. This is a Godot issue.* -2. Make sure to enable the plugin in **Project** → **Project Settings** → **Plugins**. +3. Make sure to enable the plugin in **Project** → **Project Settings** → **Plugins**. -3. You're ready to get started! Open a scene, and add a **BlockCode** child node to any node in the scene using the **Add Child Node** menu dialog. - -4. The **Block Code** editor will open in a new tab. Drag blocks from the picker and snap them together to create a script. You can switch to other Block Code scripts by selecting the respective BlockCode node in the scene tree. - -5. **Run** the scene to see your Block Code scripts in action. Block Code scripts are attached to the BlockCode node's parent, and are saved to the scene. +You're ready to get started! You can continue reading our [user documentation](docs/USAGE.md). If you clone the plugin's git repository and open it in Godot, you will be presented with a block-built Pong game as an example. @@ -50,9 +48,76 @@ We will now seek feedback from learners, educators and game makers, as well as r - Should this be a plugin or an extension? - Should blocks generate GDScript or be dynamically executed? -## Feedback - -Please share feedback in the [Godot Forum Block Coding thread](https://forum.godotengine.org/t/block-coding-high-level-block-based-visual-programming/68941). +There is no language or data format stability implemented or expected in these early stages. If you upgrade the block coding plugin within an existing project, expect any existing block scripts to stop working and need reimplementing from scratch. For now, you probably want to avoid updating the plugin within your project if it's meeting your needs, or only doing that very sporadically. We will consider offering stability guarantees in future stages of development. + +## Feedback & Discussion + +Please join our [Discussion Board](https://github.com/endlessm/godot-block-coding/discussions) to provide feedback, share ideas, and ask questions about building your games with Block Coding. + +## Localization + +The plugin supports translations through Godot's [gettext][godot-gettext] +support. We welcome contributions to make the plugin work better in your +language! However, please note that translations in the Godot editor **will +only work with Godot 4.4 or newer**. + +The gettext PO files are located in the `addons/block_code/locale` directory. +See the Godot [documentation][godot-gettext] for instructions on working with +PO files. You can also join our project on [Transifex][transifex-project] to +collaborate with others translating the Block Coding content. + +[godot-gettext]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html +[transifex-project]: https://explore.transifex.com/endless-os/godot-block-coding/ + +For developers, a few things need to be done to keep the translatable strings +up to date. + +* If files are added or removed, the list of translatable files needs to be + updated. This can be done by using the **Add** dialog in the [POT + Generation][pot-generation] tab. Or you can use the **Project → Tools → + Update BlockCode translated files** menu item in the editor. From the command + line, the POT file can be regenerated with the `scripts/update-pot-files.sh` + shell script. + +* If translatable strings have changed, the POT file needs to be updated. This + can be done by using the **Generate POT** dialog in the [POT + Generation][pot-generation] tab. Or you can use the **Project → Tools → + Regenerate BlockCode POT file** menu item in the editor. From the command + line, the POT file can be regenerated with the `scripts/regenerate-pot.sh` + shell script. + +* If the POT file has changed, the PO message files need to be updated. This + can be done using the gettext `msgmerge` tool with the + `scripts/merge-messages.sh` shell script. + +[pot-generation]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html#automatic-generation-using-the-editor + +Strings added in scene files or block definition resources will usually be +extracted for localization and translated in the editor automatically. Strings +in scripts need more consideration. + +* `Object`s or `Node`s that are not descendents of the Block Coding panel need + to have their translation domain set with the `set_block_translation_domain` + helper function. This should usually be done in the object's `_init` method + to make sure the translation domain is set before that object or any of its + descendents (which inherit the translation domain by default) try to use + localized strings. + +* Usually [`tr`][object-tr] and [`tr_n`][object-tr-n] (or [`atr`][node-atr] and + [`atr_n`][node-atr-n] for `Node`s) should be used to mark translatable + strings. These will eventually call the domain's + [`translate`][domain-translate] or + [`translate_plural`][domain-translate-plural] methods, but the `tr` methods + respect translation settings on the object instances. The only time the + `translate` methods should be called directly is within a static context when + an object instance isn't available. + +[object-tr]: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-tr +[object-tr-n]: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-tr-n +[node-atr]: https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-atr +[node-atr-n]: https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-atr-n +[domain-translate]: https://docs.godotengine.org/en/latest/classes/class_translationdomain.html#class-translationdomain-method-translate +[domain-translate-plural]: https://docs.godotengine.org/en/latest/classes/class_translationdomain.html#class-translationdomain-method-translate-plural ## Development @@ -77,16 +142,36 @@ This plugin uses the [Godot Unit Test](https://gut.readthedocs.io/en/latest/) (G Tests can also be run from the command line using the GUT command line script: ``` -godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit +godot --path . --headless -s addons/gut/gut_cmdln.gd -gexit ``` -A few options are of note here. `--path` instructs Godot to use the project in -the current directory. `--headless` instructs Godot to run without a display or -sound. `--script` instructs Godot to run the GUT command line script instead of -running the main scene. `-gexit` is an option for the GUT command line script -that instructs GUT to exit after the tests complete. +A few options are of note here: + +- `--path` instructs Godot to use the project in the current directory. +- `--headless` instructs Godot to run without a display or sound. +- `-s` instructs Godot to run the GUT command line script instead of + running the main scene. Due to a [bug in + GUT](https://github.com/bitwes/Gut/issues/667), the long form `--script` + cannot be used. +- `-gexit` is an option for the GUT command line script that instructs GUT to + exit after the tests complete. There are several other GUT command line options for running specific tests. For example, `-gtest=path/to/test_script_1.gd,path/to/test_script_2.gd` can be used to run specific test scripts. A specific test function can be specified with `-gunit_test_name=test_to_run`. + +### Using the Development Version of the Plugin + +1. If your project already has the BlockCode plugin installed: + 1. Ensure you have committed your project to Git, including the `addons/block_code` directory. + At this stage of development, **block code programs written for an older plugin version will + likely not work with a newer version of the plugin**, so it is essential that you take a + snapshot of your project before changing the plugin version. + 2. Under *Project* → *Project Settings…* → *Plugins*, disable the BlockCode plugin + 3. In the *FileSystem* sidebar, delete the `res://addons/block_code` directory +2. Download + [a development snapshot](https://github.com/endlessm/godot-block-coding/archive/main.zip) +3. Under *AssetLib*, click *Import…*, and browse to the `main.zip` file you just downloaded +4. Check the *☑ Ignore assert root* option, and click *Install* +5. Under *Project* → *Project Settings…* → *Plugins*, enable the BlockCode plugin diff --git a/addons/block_code/block_code_node/block_code.gd b/addons/block_code/block_code_node/block_code.gd index 8c2b867f..07e7cdeb 100644 --- a/addons/block_code/block_code_node/block_code.gd +++ b/addons/block_code/block_code_node/block_code.gd @@ -3,8 +3,14 @@ class_name BlockCode extends Node -@export var block_script: BlockScriptData = null -static var plugin +const TxUtils := preload("res://addons/block_code/translation/utils.gd") + +@export var block_script: BlockScriptSerialization = null: + set = _set_block_script + + +func _init(): + TxUtils.set_block_translation_domain(self) func _ready(): @@ -26,14 +32,21 @@ func _enter_tree(): # Create script if block_script == null: - var new_bsd: BlockScriptData = load("res://addons/block_code/ui/bsd_templates/default_bsd.tres").duplicate(true) - new_bsd.script_inherits = _get_custom_or_native_class(get_parent()) - new_bsd.generated_script = new_bsd.generated_script.replace("INHERIT_DEFAULT", new_bsd.script_inherits) - block_script = new_bsd + var new_block_script: BlockScriptSerialization = load("res://addons/block_code/serialization/default_block_script.tres").duplicate(true) + new_block_script.script_inherits = _get_custom_or_native_class(get_parent()) + new_block_script.generated_script = new_block_script.generated_script.replace("INHERIT_DEFAULT", new_block_script.script_inherits) + block_script = new_block_script + - if plugin == null: - plugin = ClassDB.instantiate("EditorPlugin") - plugin.add_inspector_plugin(load("res://addons/block_code/inspector_plugin/block_script_inspector.gd").new()) +func _set_block_script(value): + if value == null: + # Wipe out the bidirectional link between this block code node and the + # block script + if block_script: + block_script.block_code_node = null + else: + value.block_code_node = self + block_script = value func _update_parent_script(): @@ -67,6 +80,16 @@ func _update_parent_script(): func _get_configuration_warnings(): var warnings = [] + if self.owner == null: + warnings.append("A BlockCode must not be a root node.") + if get_parent() is BlockCode: + warnings.append("The parent must not be a BlockCode.") + if get_parent().script: + var parent_script_name: StringName = get_parent().script.get_global_name() + if not (parent_script_name and block_script and parent_script_name == block_script.script_inherits): + warnings.append("This BlockCode will override the existing script in the parent node.") + if get_parent().find_children("*", "BlockCode", false).size() > 1: + warnings.append("The parent should only contain one BlockCode.") if block_script and _get_custom_or_native_class(get_parent()) != block_script.script_inherits: var warning = "The parent is not a %s. Create a new BlockCode node and reattach." % block_script.script_inherits warnings.append(warning) diff --git a/addons/block_code/block_code_node/block_code.gd.uid b/addons/block_code/block_code_node/block_code.gd.uid new file mode 100644 index 00000000..f194ab11 --- /dev/null +++ b/addons/block_code/block_code_node/block_code.gd.uid @@ -0,0 +1 @@ +uid://cumxsbxj56dmk diff --git a/addons/block_code/block_code_plugin.gd b/addons/block_code/block_code_plugin.gd index 7173e096..ff960f1c 100644 --- a/addons/block_code/block_code_plugin.gd +++ b/addons/block_code/block_code_plugin.gd @@ -1,61 +1,62 @@ @tool -class_name BlockCodePlugin extends EditorPlugin -const MainPanel := preload("res://addons/block_code/ui/main_panel.tscn") -static var main_panel +const MainPanelScene := preload("res://addons/block_code/ui/main_panel.tscn") +const MainPanel = preload("res://addons/block_code/ui/main_panel.gd") +const Types = preload("res://addons/block_code/types/types.gd") +const TxUtils := preload("res://addons/block_code/translation/utils.gd") +const ScriptWindow := preload("res://addons/block_code/ui/script_window/script_window.tscn") + +static var main_panel: MainPanel +static var block_code_button: Button + +const BlockInspectorPlugin := preload("res://addons/block_code/inspector_plugin/block_script_inspector.gd") +var block_inspector_plugin: BlockInspectorPlugin + +const BlockTranslationParserPlugin := preload("res://addons/block_code/translation/parser.gd") +var _tx_parser_plugin: BlockTranslationParserPlugin var editor_inspector: EditorInspector +var _selected_block_code: BlockCode + var old_feature_profile: String = "" const DISABLED_CLASSES := [ - "BlockScriptData", - "DragManager", - "InstructionTree", - "Types", "Block", "ControlBlock", "ParameterBlock", "StatementBlock", - "DragDropArea", "SnapPoint", - "NodeBlockCanvas", - "SerializedBlockTreeNodeArray", - "SerializedBlockTreeNode", - "SerializedBlock", - "PackedSceneTreeNodeArray", - "PackedSceneTreeNode", - "BlockCanvas", - "NodeCanvas", - "NodeClass", - "NodeClassList", - "NodeData", - "NodePreview", - "NodeList", + "BlockScriptSerialization", "CategoryFactory", - "BlockCategoryDisplay", - "BlockCategory", - "Picker", - "TitleBar", - "MainPanel", - "BlockCodePlugin", - "BlockCategoryButton" ] +func _init(): + TxUtils.load_translations() + TxUtils.set_block_translation_domain(self) + + func _enter_tree(): Types.init_cast_graph() editor_inspector = EditorInterface.get_inspector() - main_panel = MainPanel.instantiate() + main_panel = MainPanelScene.instantiate() + main_panel.script_window_requested.connect(script_window_requested) main_panel.undo_redo = get_undo_redo() + block_code_button = add_control_to_bottom_panel(main_panel, _get_plugin_name()) + block_inspector_plugin = BlockInspectorPlugin.new() + add_inspector_plugin(block_inspector_plugin) + + if not _tx_parser_plugin: + _tx_parser_plugin = BlockTranslationParserPlugin.new() + add_translation_parser_plugin(_tx_parser_plugin) - # Add the main panel to the editor's main viewport. - EditorInterface.get_editor_main_screen().add_child(main_panel) - # Hide the main panel. Very much required. - _make_visible(false) + # Custom Project->Tools menu items. + add_tool_menu_item(tr("Regenerate %s POT file") % "BlockCode", TxUtils.regenerate_pot_file) + add_tool_menu_item(tr("Update %s translated files") % "BlockCode", TxUtils.update_pot_files) # Remove unwanted class nodes from create node old_feature_profile = EditorInterface.get_current_feature_profile() @@ -74,9 +75,27 @@ func _enter_tree(): EditorInterface.set_current_feature_profile("block_code") +func script_window_requested(script: String): + var script_window = ScriptWindow.instantiate() + script_window.script_content = script + EditorInterface.popup_dialog(script_window) + await script_window.close_requested + + script_window.queue_free() + script_window = null + + func _exit_tree(): + remove_translation_parser_plugin(_tx_parser_plugin) + remove_inspector_plugin(block_inspector_plugin) + + if block_code_button: + remove_control_from_bottom_panel(main_panel) + block_code_button = null + if main_panel: main_panel.queue_free() + main_panel = null var editor_paths: EditorPaths = EditorInterface.get_editor_paths() if editor_paths: @@ -89,28 +108,90 @@ func _exit_tree(): func _ready(): - connect("scene_changed", _on_scene_changed) editor_inspector.connect("edited_object_changed", _on_editor_inspector_edited_object_changed) - _on_scene_changed(EditorInterface.get_edited_scene_root()) _on_editor_inspector_edited_object_changed() -func _on_scene_changed(scene_root: Node): - BlockCodePlugin.main_panel.switch_scene(scene_root) +func _on_editor_inspector_edited_object_changed(): + var edited_object = editor_inspector.get_edited_object() + var block_code_node = edited_object as BlockCode + if block_code_node: + # If a block code node was explicitly selected, activate the + # Block Code panel. + make_bottom_panel_item_visible(main_panel) + else: + # Find the first block code child. + block_code_node = list_block_code_nodes_for_node(edited_object as Node).pop_front() + select_block_code_node(block_code_node) + + +func select_block_code_node(block_code: BlockCode): + # Skip duplicate selection unless new node is null. That happens when any + # non-BlockCode node is selected and that needs to be passed through to the + # main panel. + if block_code and block_code == _selected_block_code: + return + + if not is_block_code_editable(block_code): + block_code = null + + if is_instance_valid(_selected_block_code): + _selected_block_code.tree_entered.disconnect(_on_selected_block_code_changed) + _selected_block_code.tree_exited.disconnect(_on_selected_block_code_changed) + _selected_block_code.property_list_changed.disconnect(_on_selected_block_code_changed) + editor_inspector.property_edited.disconnect(_on_editor_inspector_property_edited) + + _selected_block_code = block_code + + if is_instance_valid(_selected_block_code): + _selected_block_code.tree_entered.connect(_on_selected_block_code_changed) + _selected_block_code.tree_exited.connect(_on_selected_block_code_changed) + _selected_block_code.property_list_changed.connect(_on_selected_block_code_changed) + editor_inspector.property_edited.connect(_on_editor_inspector_property_edited) + + _refresh_block_code_node() + + +func _refresh_block_code_node(): + if main_panel: + main_panel.switch_block_code_node(_selected_block_code) -func _on_editor_inspector_edited_object_changed(): - var block_code: BlockCode = editor_inspector.get_edited_object() as BlockCode - BlockCodePlugin.main_panel.switch_script(block_code) +func _on_selected_block_code_changed(): + if _selected_block_code: + _refresh_block_code_node() -func _has_main_screen(): - return true +func _on_editor_inspector_property_edited(property: String): + if _selected_block_code: + _refresh_block_code_node() -func _make_visible(visible): - if main_panel: - main_panel.visible = visible +static func is_block_code_editable(block_code: BlockCode) -> bool: + if not block_code: + return false + + # A BlockCode node can be edited if it belongs to the edited scene, or it + # is an editable instance. + + var scene_node = EditorInterface.get_edited_scene_root() + + return block_code == scene_node or block_code.owner == scene_node or scene_node.is_editable_instance(block_code.owner) + + +static func node_has_block_code(node: Node, recursive: bool = false) -> bool: + return list_block_code_nodes_for_node(node, recursive).size() > 0 + + +static func list_block_code_nodes_for_node(node: Node, recursive: bool = false) -> Array[BlockCode]: + var result: Array[BlockCode] = [] + + if node is BlockCode: + result.append(node) + elif node: + result.append_array(node.find_children("*", "BlockCode", recursive)) + + return result func _get_plugin_name(): diff --git a/addons/block_code/block_code_plugin.gd.uid b/addons/block_code/block_code_plugin.gd.uid new file mode 100644 index 00000000..0be7dba6 --- /dev/null +++ b/addons/block_code/block_code_plugin.gd.uid @@ -0,0 +1 @@ +uid://bx7wld2cftncr diff --git a/addons/block_code/block_script_data/block_script_data.gd b/addons/block_code/block_script_data/block_script_data.gd deleted file mode 100644 index 6696c8a0..00000000 --- a/addons/block_code/block_script_data/block_script_data.gd +++ /dev/null @@ -1,12 +0,0 @@ -class_name BlockScriptData -extends Resource - -@export var script_inherits: String -@export var block_trees: SerializedBlockTreeNodeArray -@export var generated_script: String - - -func _init(p_script_inherits: String = "", p_block_trees: SerializedBlockTreeNodeArray = null, p_generated_script: String = ""): - script_inherits = p_script_inherits - block_trees = p_block_trees - generated_script = p_generated_script diff --git a/addons/block_code/blocks/communication/add_node_to_group.tres b/addons/block_code/blocks/communication/add_node_to_group.tres new file mode 100644 index 00000000..00c2bf7f --- /dev/null +++ b/addons/block_code/blocks/communication/add_node_to_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bpvefei72nh3a"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_5qal7"] +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_auf06"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="1_p83c7"] + +[sub_resource type="Resource" id="Resource_sus0f"] +script = ExtResource("1_auf06") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_5qal7") +name = &"add_node_to_group" +target_node_class = "" +description = "Add the node into the group" +category = "Communication | Groups" +type = 2 +variant_type = 0 +display_template = "add {node: OBJECT} to group {group: STRING}" +code_template = "{node}.add_to_group({group})" +defaults = { +"group": SubResource("Resource_sus0f") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_p83c7") diff --git a/addons/block_code/blocks/communication/add_to_group.tres b/addons/block_code/blocks/communication/add_to_group.tres new file mode 100644 index 00000000..d5cfc713 --- /dev/null +++ b/addons/block_code/blocks/communication/add_to_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bvrmau8atjx1x"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_aom4j"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_bcm71"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="2_42ixf"] + +[sub_resource type="Resource" id="Resource_fk0wa"] +script = ExtResource("1_aom4j") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_bcm71") +name = &"add_to_group" +target_node_class = "" +description = "Add this node into the group" +category = "Communication | Groups" +type = 2 +variant_type = 0 +display_template = "add to group {group: STRING}" +code_template = "add_to_group({group})" +defaults = { +"group": SubResource("Resource_fk0wa") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("2_42ixf") diff --git a/addons/block_code/blocks/communication/area2d_on_entered.tres b/addons/block_code/blocks/communication/area2d_on_entered.tres new file mode 100644 index 00000000..66e926cf --- /dev/null +++ b/addons/block_code/blocks/communication/area2d_on_entered.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://de4k7t7uqws1j"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_xotf5"] + +[resource] +script = ExtResource("1_xotf5") +name = &"area2d_on_entered" +target_node_class = "Area2D" +description = "" +category = "Communication | Methods" +type = 1 +variant_type = 0 +display_template = "when this node collides with [something: OBJECT]" +code_template = "func _on_body_entered(something: Node2D):" +defaults = {} +signal_name = "body_entered" +scope = "" diff --git a/addons/block_code/blocks/communication/area2d_on_exited.tres b/addons/block_code/blocks/communication/area2d_on_exited.tres new file mode 100644 index 00000000..1af61a60 --- /dev/null +++ b/addons/block_code/blocks/communication/area2d_on_exited.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b36nq4mau6lu6"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_21qth"] + +[resource] +script = ExtResource("1_21qth") +name = &"area2d_on_exited" +target_node_class = "Area2D" +description = "" +category = "Communication | Methods" +type = 1 +variant_type = 0 +display_template = "when this node stops colliding with [something: OBJECT]" +code_template = "func _on_body_exited(something: Node2D):" +defaults = {} +signal_name = "body_exited" +scope = "" diff --git a/addons/block_code/blocks/communication/call_method_group.tres b/addons/block_code/blocks/communication/call_method_group.tres new file mode 100644 index 00000000..b0dc5d19 --- /dev/null +++ b/addons/block_code/blocks/communication/call_method_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://c15vtdfihdxb8"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_3nuts"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_mlm68"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="1_of577"] + +[sub_resource type="Resource" id="Resource_f4ctg"] +script = ExtResource("1_3nuts") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_mlm68") +name = &"call_method_group" +target_node_class = "" +description = "Calls the method/function on each member of the given group" +category = "Communication | Methods" +type = 2 +variant_type = 0 +display_template = "call method {method_name: STRING} in group {group: STRING}" +code_template = "get_tree().call_group({group}, {method_name})" +defaults = { +"group": SubResource("Resource_f4ctg") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_of577") diff --git a/addons/block_code/blocks/communication/call_method_node.tres b/addons/block_code/blocks/communication/call_method_node.tres new file mode 100644 index 00000000..3937dddb --- /dev/null +++ b/addons/block_code/blocks/communication/call_method_node.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c04j5flmimjvf"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_pg363"] + +[resource] +script = ExtResource("1_pg363") +name = &"call_method_node" +target_node_class = "" +description = "Calls the method/function of the given node" +category = "Communication | Methods" +type = 2 +variant_type = 0 +display_template = "call method {method_name: STRING} on node {node: OBJECT}" +code_template = "{node}.call({method_name})" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/communication/define_method.tres b/addons/block_code/blocks/communication/define_method.tres new file mode 100644 index 00000000..6ae8ca06 --- /dev/null +++ b/addons/block_code/blocks/communication/define_method.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://7r2b2griss3i"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_6e473"] + +[resource] +script = ExtResource("1_6e473") +name = &"define_method" +target_node_class = "" +description = "Define a method/function with following statements" +category = "Communication | Methods" +type = 1 +variant_type = 0 +display_template = "define method {method_name: STRING_NAME}" +code_template = "func {method_name}():" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/communication/get_node.gd b/addons/block_code/blocks/communication/get_node.gd new file mode 100644 index 00000000..61638da4 --- /dev/null +++ b/addons/block_code/blocks/communication/get_node.gd @@ -0,0 +1,33 @@ +@tool +extends BlockExtension + +const OptionData = preload("res://addons/block_code/code_generation/option_data.gd") +const Util = preload("res://addons/block_code/ui/util.gd") + + +func _find_paths(paths: Array[NodePath], node: Node, path_root: Node, block_parent: Node): + # Add any non-BlockCode nodes that aren't the parent of the current + # BlockCode node. + if not node is BlockCode: + var node_path: NodePath = Util.node_scene_path(node, block_parent, path_root) + if not node_path in [^"", ^"."]: + paths.append(node_path) + + for child in node.get_children(): + _find_paths(paths, child, path_root, block_parent) + + +func get_defaults_for_node(context_node: Node) -> Dictionary: + # The default paths are only needed in the editor. + if not Engine.is_editor_hint(): + return {} + + var scene_root: Node = EditorInterface.get_edited_scene_root() + var path_root: Node = scene_root.get_parent() + var paths: Array[NodePath] + _find_paths(paths, scene_root, path_root, context_node) + + if not paths: + return {} + + return {"path": OptionData.new(paths)} diff --git a/addons/block_code/blocks/communication/get_node.gd.uid b/addons/block_code/blocks/communication/get_node.gd.uid new file mode 100644 index 00000000..b08b5b23 --- /dev/null +++ b/addons/block_code/blocks/communication/get_node.gd.uid @@ -0,0 +1 @@ +uid://cscfelhxcapk3 diff --git a/addons/block_code/blocks/communication/get_node.tres b/addons/block_code/blocks/communication/get_node.tres new file mode 100644 index 00000000..62652213 --- /dev/null +++ b/addons/block_code/blocks/communication/get_node.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://canpdkahokjqs"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_bk47y"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_d60g7"] +[ext_resource type="Script" uid="uid://cscfelhxcapk3" path="res://addons/block_code/blocks/communication/get_node.gd" id="1_we5wl"] + +[sub_resource type="Resource" id="Resource_esr4a"] +script = ExtResource("1_bk47y") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_d60g7") +name = &"get_node" +target_node_class = "" +description = "Get the node at the given path" +category = "Communication | Nodes" +type = 3 +variant_type = 24 +display_template = "{path: NIL}" +code_template = "get_node(\"{path}\")" +defaults = { +"path": SubResource("Resource_esr4a") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_we5wl") diff --git a/addons/block_code/blocks/communication/groups.gd b/addons/block_code/blocks/communication/groups.gd new file mode 100644 index 00000000..c217d71a --- /dev/null +++ b/addons/block_code/blocks/communication/groups.gd @@ -0,0 +1,70 @@ +@tool +## Common BlockExtension for scene group options. +extends BlockExtension + +const OptionData = preload("res://addons/block_code/code_generation/option_data.gd") + + +# Global groups are just project settings in the global_group group. +# ProjectSettings doesn't offer an API to get the project groups or to get all +# settings. Fortunately, settings are simply implemented as properties on the +# ProjectSettings object. +static func _add_global_groups(groups: Dictionary): + for prop in ProjectSettings.get_property_list(): + var name: String = prop["name"] + var parts := name.split("/", false, 1) + if parts[0] == "global_group": + groups[parts[1]] = null + + +# Add all the groups in a node and its children, ignoring internal _ prefixed +# groups. +static func _add_node_groups(groups: Dictionary, node: Node): + for group in node.get_groups(): + if not group.begins_with("_"): + groups[String(group)] = null + + for child in node.get_children(): + _add_node_groups(groups, child) + + +func _get_edited_scene_groups() -> Array[String]: + var groups: Dictionary + _add_global_groups(groups) + + var root := context_node.get_tree().edited_scene_root + _add_node_groups(groups, root) + + var sorted_groups: Array[String] + sorted_groups.assign(groups.keys()) + sorted_groups.sort() + return sorted_groups + + +func _init(): + # FIXME: Only global group changes are monitored. Scene local groups should + # also be monitored, but godot does not have any reasonable API to do that. + ProjectSettings.settings_changed.connect(_on_project_settings_changed) + + +func _context_node_changed(): + # If the context node changed, the scene local groups need to be updated. + changed.emit() + + +func get_defaults() -> Dictionary: + if not context_node: + return {} + + # The default groups are only needed in the editor. + if not context_node.is_part_of_edited_scene(): + return {} + + var groups: Array[String] = _get_edited_scene_groups() + return {"group": OptionData.new(groups)} + + +func _on_project_settings_changed(): + # FIXME: The global groups should be cached and compared so that the + # defaults are only changed when the global groups actually change. + changed.emit() diff --git a/addons/block_code/blocks/communication/groups.gd.uid b/addons/block_code/blocks/communication/groups.gd.uid new file mode 100644 index 00000000..e39b79d2 --- /dev/null +++ b/addons/block_code/blocks/communication/groups.gd.uid @@ -0,0 +1 @@ +uid://cumj4bsraukca diff --git a/addons/block_code/blocks/communication/is_in_group.tres b/addons/block_code/blocks/communication/is_in_group.tres new file mode 100644 index 00000000..f4dd5499 --- /dev/null +++ b/addons/block_code/blocks/communication/is_in_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://q4cnstftvsiu"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_cla3i"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_tjyq5"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="2_o165d"] + +[sub_resource type="Resource" id="Resource_d0v0d"] +script = ExtResource("1_cla3i") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_tjyq5") +name = &"is_in_group" +target_node_class = "" +description = "Is this node in the group" +category = "Communication | Groups" +type = 3 +variant_type = 1 +display_template = "is in group {group: STRING}" +code_template = "is_in_group({group})" +defaults = { +"group": SubResource("Resource_d0v0d") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("2_o165d") diff --git a/addons/block_code/blocks/communication/is_node_in_group.tres b/addons/block_code/blocks/communication/is_node_in_group.tres new file mode 100644 index 00000000..a10fe700 --- /dev/null +++ b/addons/block_code/blocks/communication/is_node_in_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://bbtdxeey74x67"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_5krrs"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="1_r4prw"] +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_y4j0k"] + +[sub_resource type="Resource" id="Resource_o38ym"] +script = ExtResource("1_y4j0k") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_5krrs") +name = &"is_node_in_group" +target_node_class = "" +description = "Is the node in the group" +category = "Communication | Groups" +type = 3 +variant_type = 1 +display_template = "{node: OBJECT} is in group {group: STRING}" +code_template = "{node}.is_in_group({group})" +defaults = { +"group": SubResource("Resource_o38ym") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_r4prw") diff --git a/addons/block_code/blocks/communication/remove_from_group.tres b/addons/block_code/blocks/communication/remove_from_group.tres new file mode 100644 index 00000000..64dd8d3d --- /dev/null +++ b/addons/block_code/blocks/communication/remove_from_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://dgenw5wyqorvq"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_cdwef"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="1_i50fw"] +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_mnxp7"] + +[sub_resource type="Resource" id="Resource_45b71"] +script = ExtResource("1_mnxp7") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_cdwef") +name = &"remove_from_group" +target_node_class = "" +description = "Remove this node from the group" +category = "Communication | Groups" +type = 2 +variant_type = 0 +display_template = "remove from group {group: STRING}" +code_template = "remove_from_group({group})" +defaults = { +"group": SubResource("Resource_45b71") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_i50fw") diff --git a/addons/block_code/blocks/communication/remove_node_from_group.tres b/addons/block_code/blocks/communication/remove_node_from_group.tres new file mode 100644 index 00000000..afc4a9cf --- /dev/null +++ b/addons/block_code/blocks/communication/remove_node_from_group.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://b2dwk77hnri8y"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_clwhe"] +[ext_resource type="Script" uid="uid://cumj4bsraukca" path="res://addons/block_code/blocks/communication/groups.gd" id="1_h3lhb"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_pec24"] + +[sub_resource type="Resource" id="Resource_03rge"] +script = ExtResource("1_clwhe") +selected = 0 +items = [] + +[resource] +script = ExtResource("1_pec24") +name = &"remove_node_from_group" +target_node_class = "" +description = "Remove the node from the group" +category = "Communication | Groups" +type = 2 +variant_type = 0 +display_template = "remove {node: OBJECT} from group {group: NIL}" +code_template = "{node}.remove_from_group(\\\"{group}\\\")" +defaults = { +"group": SubResource("Resource_03rge") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("1_h3lhb") diff --git a/addons/block_code/blocks/communication/rigidbody2d_on_entered.tres b/addons/block_code/blocks/communication/rigidbody2d_on_entered.tres new file mode 100644 index 00000000..9ffcfaf6 --- /dev/null +++ b/addons/block_code/blocks/communication/rigidbody2d_on_entered.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dl1xd1jit2mlp"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_v2421"] + +[resource] +script = ExtResource("1_v2421") +name = &"rigidbody2d_on_entered" +target_node_class = "RigidBody2D" +description = "" +category = "Communication | Methods" +type = 1 +variant_type = 0 +display_template = "when this node collides with [something: OBJECT]" +code_template = "func _on_body_entered(something: Node2D):" +defaults = {} +signal_name = "body_entered" +scope = "" diff --git a/addons/block_code/blocks/communication/rigidbody2d_on_exited.tres b/addons/block_code/blocks/communication/rigidbody2d_on_exited.tres new file mode 100644 index 00000000..89638d96 --- /dev/null +++ b/addons/block_code/blocks/communication/rigidbody2d_on_exited.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c15ymi1kxb570"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_sahiu"] + +[resource] +script = ExtResource("1_sahiu") +name = &"rigidbody2d_on_exited" +target_node_class = "RigidBody2D" +description = "" +category = "Communication | Methods" +type = 1 +variant_type = 0 +display_template = "when this node stops colliding with [something: OBJECT]" +code_template = "func _on_body_exited(something: Node2D):" +defaults = {} +signal_name = "body_exited" +scope = "" diff --git a/addons/block_code/blocks/communication/switch_scene.tres b/addons/block_code/blocks/communication/switch_scene.tres new file mode 100644 index 00000000..cf1bfe7e --- /dev/null +++ b/addons/block_code/blocks/communication/switch_scene.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dnc2555wnobks"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rnqd5"] + +[resource] +script = ExtResource("1_rnqd5") +name = &"switch_scene" +target_node_class = "" +description = "Stop playing the current scene, and switch to a different one. You might use this to switch to a new level." +category = "Communication | Methods" +type = 2 +variant_type = 0 +display_template = "switch the scene to {file_path: STRING}" +code_template = "get_tree().change_scene_to_file({file_path}) +" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/animationplayer_is_playing.tres b/addons/block_code/blocks/graphics/animationplayer_is_playing.tres new file mode 100644 index 00000000..15e9bdfd --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_is_playing.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://mg4y3o0rsqd5"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_xr50b"] + +[resource] +script = ExtResource("1_xr50b") +name = &"animationplayer_is_playing" +target_node_class = "AnimationPlayer" +description = "Check if an animation is currently playing." +category = "Graphics | Animation" +type = 3 +variant_type = 1 +display_template = "is playing" +code_template = "is_playing()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/animationplayer_pause.tres b/addons/block_code/blocks/graphics/animationplayer_pause.tres new file mode 100644 index 00000000..894f7793 --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_pause.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://clopo7gmje5a"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_2enqv"] + +[resource] +script = ExtResource("1_2enqv") +name = &"animationplayer_pause" +target_node_class = "AnimationPlayer" +description = "Pause the currently playing animation." +category = "Graphics | Animation" +type = 2 +variant_type = 0 +display_template = "pause" +code_template = "pause()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/animationplayer_play.gd b/addons/block_code/blocks/graphics/animationplayer_play.gd new file mode 100644 index 00000000..3d3389bc --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_play.gd @@ -0,0 +1,28 @@ +@tool +extends BlockExtension + +const OptionData = preload("res://addons/block_code/code_generation/option_data.gd") + + +func get_defaults() -> Dictionary: + var animation_player = context_node as AnimationPlayer + + if not animation_player: + return {} + + var animation_list = animation_player.get_animation_list() + + return {"animation": OptionData.new(animation_list)} + + +func _context_node_changed(): + var animation_player = context_node as AnimationPlayer + + if not animation_player: + return + + animation_player.animation_list_changed.connect(_on_animation_list_changed) + + +func _on_animation_list_changed(): + _emit_changed() diff --git a/addons/block_code/blocks/graphics/animationplayer_play.gd.uid b/addons/block_code/blocks/graphics/animationplayer_play.gd.uid new file mode 100644 index 00000000..5b979254 --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_play.gd.uid @@ -0,0 +1 @@ +uid://c38ngxebcyrg6 diff --git a/addons/block_code/blocks/graphics/animationplayer_play.tres b/addons/block_code/blocks/graphics/animationplayer_play.tres new file mode 100644 index 00000000..1f1cfc9d --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_play.tres @@ -0,0 +1,45 @@ +[gd_resource type="Resource" load_steps=7 format=3 uid="uid://c5e1byehtxwc0"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_emeuv"] +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_xu43h"] +[ext_resource type="Script" uid="uid://c38ngxebcyrg6" path="res://addons/block_code/blocks/graphics/animationplayer_play.gd" id="2_7ymgi"] + +[sub_resource type="Resource" id="Resource_qpxn2"] +script = ExtResource("1_xu43h") +selected = 0 +items = [] + +[sub_resource type="Resource" id="Resource_vnp2w"] +script = ExtResource("1_xu43h") +selected = 0 +items = ["forward", "backwards"] + +[sub_resource type="Resource" id="Resource_17pec"] +script = ExtResource("1_xu43h") +selected = 0 +items = ["until done", "in the background"] + +[resource] +script = ExtResource("1_emeuv") +name = &"animationplayer_play" +target_node_class = "AnimationPlayer" +description = "Play the animation." +category = "Graphics | Animation" +type = 2 +variant_type = 0 +display_template = "play {animation: STRING} | {direction: NIL} {wait_mode: NIL}" +code_template = "if {direction} == \"forward\": + play({animation}) +else: + play_backwards({animation}) +if {wait_mode} == \"until done\": + await animation_finished +" +defaults = { +"animation": SubResource("Resource_qpxn2"), +"direction": SubResource("Resource_vnp2w"), +"wait_mode": SubResource("Resource_17pec") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("2_7ymgi") diff --git a/addons/block_code/blocks/graphics/animationplayer_stop.tres b/addons/block_code/blocks/graphics/animationplayer_stop.tres new file mode 100644 index 00000000..72e62c8f --- /dev/null +++ b/addons/block_code/blocks/graphics/animationplayer_stop.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b4v00oxoxbfet"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_wp8gr"] + +[resource] +script = ExtResource("1_wp8gr") +name = &"animationplayer_stop" +target_node_class = "AnimationPlayer" +description = "Stop the currently playing animation." +category = "Graphics | Animation" +type = 2 +variant_type = 0 +display_template = "stop" +code_template = "stop()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/viewport_center.tres b/addons/block_code/blocks/graphics/viewport_center.tres new file mode 100644 index 00000000..fe0a557f --- /dev/null +++ b/addons/block_code/blocks/graphics/viewport_center.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://1536itmdu8yo"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rc1so"] + +[resource] +script = ExtResource("1_rc1so") +name = &"viewport_center" +target_node_class = "" +description = "Coordinates of the middle of the viewable screen when playing." +category = "Graphics | Viewport" +type = 3 +variant_type = 5 +display_template = "viewport center" +code_template = "(func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return -transform.origin / scale + get_viewport_rect().size / scale / 2).call()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/viewport_height.tres b/addons/block_code/blocks/graphics/viewport_height.tres new file mode 100644 index 00000000..70ba7c0e --- /dev/null +++ b/addons/block_code/blocks/graphics/viewport_height.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bdm4yr68mdf4d"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_1debb"] + +[resource] +script = ExtResource("1_1debb") +name = &"viewport_height" +target_node_class = "" +description = "How tall the viewable screen is when playing." +category = "Graphics | Viewport" +type = 3 +variant_type = 3 +display_template = "viewport height" +code_template = "(func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return -transform.origin.y / scale.y + get_viewport_rect().size.y / scale.y).call()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/graphics/viewport_width.tres b/addons/block_code/blocks/graphics/viewport_width.tres new file mode 100644 index 00000000..6600a238 --- /dev/null +++ b/addons/block_code/blocks/graphics/viewport_width.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bt78ajp56ga24"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_ll4rh"] + +[resource] +script = ExtResource("1_ll4rh") +name = &"viewport_width" +target_node_class = "" +description = "How wide the viewable screen is when playing." +category = "Graphics | Viewport" +type = 3 +variant_type = 3 +display_template = "viewport width" +code_template = "(func (): var transform: Transform2D = get_viewport_transform(); var scale: Vector2 = transform.get_scale(); return -transform.origin.x / scale.x + get_viewport_rect().size.x / scale.x).call()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/input/characterbody2d_is_on_floor.tres b/addons/block_code/blocks/input/characterbody2d_is_on_floor.tres new file mode 100644 index 00000000..9dd9dd5d --- /dev/null +++ b/addons/block_code/blocks/input/characterbody2d_is_on_floor.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cbpicqif1ddro"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_btxic"] + +[resource] +script = ExtResource("1_btxic") +name = &"characterbody2d_is_on_floor" +target_node_class = "CharacterBody2D" +description = "True if the character is on the floor." +category = "Physics | Velocity" +type = 3 +variant_type = 1 +display_template = "is on floor" +code_template = "is_on_floor()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/input/characterbody2d_move.tres b/addons/block_code/blocks/input/characterbody2d_move.tres new file mode 100644 index 00000000..f5dc9a1a --- /dev/null +++ b/addons/block_code/blocks/input/characterbody2d_move.tres @@ -0,0 +1,31 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cu3ru61vg6bx5"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_btxic"] + +[resource] +script = ExtResource("1_btxic") +name = &"characterbody2d_move" +target_node_class = "CharacterBody2D" +description = "Move the character up, down, left, and right with the keyboard using the given keys. The speed of movement can be adjusted separately for x (left and right) and y (up and down)." +category = "Input" +type = 2 +variant_type = 0 +display_template = "move with keys {up: STRING} {down: STRING} {left: STRING} {right: STRING} at speed {speed: VECTOR2}" +code_template = "var dir = Vector2() +dir.x += float(Input.is_key_pressed(OS.find_keycode_from_string({right}))) +dir.x -= float(Input.is_key_pressed(OS.find_keycode_from_string({left}))) +dir.y += float(Input.is_key_pressed(OS.find_keycode_from_string({down}))) +dir.y -= float(Input.is_key_pressed(OS.find_keycode_from_string({up}))) +dir = dir.normalized() +velocity = dir*{speed} +move_and_slide() +" +defaults = { +"down": "S", +"left": "A", +"right": "D", +"speed": Vector2(100, 100), +"up": "W" +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/input/is_input_actioned.gd b/addons/block_code/blocks/input/is_input_actioned.gd new file mode 100644 index 00000000..cc28a015 --- /dev/null +++ b/addons/block_code/blocks/input/is_input_actioned.gd @@ -0,0 +1,35 @@ +@tool +extends BlockExtension + +const OptionData = preload("res://addons/block_code/code_generation/option_data.gd") + + +func get_defaults() -> Dictionary: + var inputmap_actions = _get_inputmap_actions() + return {"action_name": OptionData.new(inputmap_actions)} + + +static func _get_inputmap_actions() -> Array[StringName]: + var inputmap_actions: Array[StringName] + + var editor_input_actions: Dictionary = {} + var editor_input_action_deadzones: Dictionary = {} + if Engine.is_editor_hint(): + var actions := InputMap.get_actions() + for action in actions: + if action.begins_with("spatial_editor"): + var events := InputMap.action_get_events(action) + editor_input_actions[action] = events + editor_input_action_deadzones[action] = InputMap.action_get_deadzone(action) + + InputMap.load_from_project_settings() + + inputmap_actions = InputMap.get_actions() + + if Engine.is_editor_hint(): + for action in editor_input_actions.keys(): + InputMap.add_action(action, editor_input_action_deadzones[action]) + for event in editor_input_actions[action]: + InputMap.action_add_event(action, event) + + return inputmap_actions diff --git a/addons/block_code/blocks/input/is_input_actioned.gd.uid b/addons/block_code/blocks/input/is_input_actioned.gd.uid new file mode 100644 index 00000000..406cdc00 --- /dev/null +++ b/addons/block_code/blocks/input/is_input_actioned.gd.uid @@ -0,0 +1 @@ +uid://cg3sepbbe45ey diff --git a/addons/block_code/blocks/input/is_input_actioned.tres b/addons/block_code/blocks/input/is_input_actioned.tres new file mode 100644 index 00000000..7acfc62e --- /dev/null +++ b/addons/block_code/blocks/input/is_input_actioned.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=5 format=3 uid="uid://86j17le5e58u"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_d8i05"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rprh7"] +[ext_resource type="Script" uid="uid://cg3sepbbe45ey" path="res://addons/block_code/blocks/input/is_input_actioned.gd" id="2_h11b7"] + +[sub_resource type="Resource" id="Resource_ai5in"] +script = ExtResource("1_d8i05") +selected = 0 +items = ["pressed", "just_pressed", "just_released"] + +[resource] +script = ExtResource("1_rprh7") +name = &"is_input_actioned" +target_node_class = "" +description = "True if the specified input action has been pressed or released." +category = "Input" +type = 3 +variant_type = 1 +display_template = "action {action_name: STRING_NAME} is {action: NIL}" +code_template = "Input.is_action_{{action}}('{{action_name}}')" +defaults = { +"action": SubResource("Resource_ai5in") +} +signal_name = "" +is_advanced = false +extension_script = ExtResource("2_h11b7") diff --git a/addons/block_code/blocks/input/mouse_position.tres b/addons/block_code/blocks/input/mouse_position.tres new file mode 100644 index 00000000..39fb46ee --- /dev/null +++ b/addons/block_code/blocks/input/mouse_position.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dwrdne76nxk7t"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_7vl3n"] + +[resource] +script = ExtResource("1_7vl3n") +name = &"mouse_position" +target_node_class = "CanvasItem" +description = "The coordinates of the mouse position." +category = "Input" +type = 3 +variant_type = 5 +display_template = "mouse position" +code_template = "get_global_mouse_position()" +defaults = {} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/lifecycle/physics_process.tres b/addons/block_code/blocks/lifecycle/physics_process.tres new file mode 100644 index 00000000..315c4b55 --- /dev/null +++ b/addons/block_code/blocks/lifecycle/physics_process.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://3l8wefwlme2v"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_pmina"] + +[resource] +script = ExtResource("1_pmina") +name = &"physics_process" +target_node_class = "" +description = "Attached blocks will be executed before each physics step" +category = "Lifecycle" +type = 1 +variant_type = 0 +display_template = "every physics step" +code_template = "func _physics_process(delta):" +defaults = {} +signal_name = "" +scope = "" +is_advanced = true diff --git a/addons/block_code/blocks/lifecycle/process.tres b/addons/block_code/blocks/lifecycle/process.tres new file mode 100644 index 00000000..67f1a8e6 --- /dev/null +++ b/addons/block_code/blocks/lifecycle/process.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://chioedvp50013"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_pmina"] + +[resource] +script = ExtResource("1_pmina") +name = &"process" +target_node_class = "" +description = "Attached blocks will be executed during the processing step of the main loop" +category = "Lifecycle" +type = 1 +variant_type = 0 +display_template = "every frame" +code_template = "func _process(delta):" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/lifecycle/queue_free.tres b/addons/block_code/blocks/lifecycle/queue_free.tres new file mode 100644 index 00000000..6dbe8107 --- /dev/null +++ b/addons/block_code/blocks/lifecycle/queue_free.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://4hj5b3xaiuy8"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_75fle"] + +[resource] +script = ExtResource("1_75fle") +name = &"queue_free" +target_node_class = "" +description = "Queues this node to be deleted at the end of the current frame" +category = "Lifecycle" +type = 2 +variant_type = 0 +display_template = "remove" +code_template = "queue_free()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/lifecycle/queue_free_node.tres b/addons/block_code/blocks/lifecycle/queue_free_node.tres new file mode 100644 index 00000000..4c393087 --- /dev/null +++ b/addons/block_code/blocks/lifecycle/queue_free_node.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://d31lkxkm5lww7"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_75fle"] + +[resource] +script = ExtResource("1_75fle") +name = &"queue_free_node" +target_node_class = "" +description = "Queues the given node to be deleted at the end of the current frame" +category = "Lifecycle" +type = 2 +variant_type = 0 +display_template = "remove {node: OBJECT}" +code_template = "{node}.queue_free()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/lifecycle/ready.tres b/addons/block_code/blocks/lifecycle/ready.tres new file mode 100644 index 00000000..55a2cf20 --- /dev/null +++ b/addons/block_code/blocks/lifecycle/ready.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dgwfoepoejlom"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_vk0xk"] + +[resource] +script = ExtResource("1_vk0xk") +name = &"ready" +target_node_class = "" +description = "Attached blocks will be executed once when the node is \"ready\"" +category = "Lifecycle" +type = 1 +variant_type = 0 +display_template = "when starting" +code_template = "func _ready():" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/log/breakpoint.tres b/addons/block_code/blocks/log/breakpoint.tres new file mode 100644 index 00000000..d0a8a854 --- /dev/null +++ b/addons/block_code/blocks/log/breakpoint.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bddy0d4xdv20c"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_xva04"] + +[resource] +script = ExtResource("1_xva04") +name = &"breakpoint" +target_node_class = "" +description = "Pause execution and show the current line of code in the debugger." +category = "Log" +type = 2 +variant_type = 0 +display_template = "breakpoint" +code_template = "breakpoint" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/log/concat.tres b/addons/block_code/blocks/log/concat.tres new file mode 100644 index 00000000..744bd5a7 --- /dev/null +++ b/addons/block_code/blocks/log/concat.tres @@ -0,0 +1,15 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cb6ux0amdhhlw"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_lstbo"] + +[resource] +script = ExtResource("1_lstbo") +name = &"concat" +description = "" +category = "Log" +type = 3 +variant_type = 4 +display_template = "{string1: STRING} + {string2: STRING}" +code_template = "{string1} + {string2}" +defaults = {} +signal_name = "" diff --git a/addons/block_code/blocks/log/print.tres b/addons/block_code/blocks/log/print.tres new file mode 100644 index 00000000..bc6c82f0 --- /dev/null +++ b/addons/block_code/blocks/log/print.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://barxsapb8tl0r"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_0lih2"] + +[resource] +script = ExtResource("1_0lih2") +name = &"print" +target_node_class = "" +description = "Print the text to output" +category = "Log" +type = 2 +variant_type = 0 +display_template = "log text {text: STRING}" +code_template = "print({text})" +defaults = { +"text": "Hello" +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/log/to_string.tres b/addons/block_code/blocks/log/to_string.tres new file mode 100644 index 00000000..73931305 --- /dev/null +++ b/addons/block_code/blocks/log/to_string.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=4 format=3 uid="uid://bfugvntm6mdjm"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_i1nej"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="2_xs7a8"] + +[sub_resource type="Resource" id="Resource_ie4sg"] +script = ExtResource("1_i1nej") +selected = 0 +items = ["0", "true", "Vector2(0, 0)", "Vector3(0, 0, 0)", "Color(0, 0, 0, 1)", "Object(Object, \"script\": null)"] + +[resource] +script = ExtResource("2_xs7a8") +name = &"to_string" +target_node_class = "" +description = "Converts [i]parameter[/i] to a [b]String[/b]" +category = "Log" +type = 3 +variant_type = 4 +display_template = "{parameter: NIL} to string" +code_template = "str({{parameter}})" +defaults = { +"parameter": SubResource("Resource_ie4sg") +} +signal_name = "" +is_advanced = true diff --git a/addons/block_code/blocks/logic/and.tres b/addons/block_code/blocks/logic/and.tres new file mode 100644 index 00000000..c333138f --- /dev/null +++ b/addons/block_code/blocks/logic/and.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://d0g11cp3ff81i"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="2_lxlcw"] + +[resource] +script = ExtResource("2_lxlcw") +name = &"and" +description = "" +category = "Logic | Boolean" +type = 3 +variant_type = 1 +display_template = "{bool1: BOOL} and {bool2: BOOL}" +code_template = "{bool1} and {bool2}" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/logic/compare.tres b/addons/block_code/blocks/logic/compare.tres new file mode 100644 index 00000000..5fbeb31c --- /dev/null +++ b/addons/block_code/blocks/logic/compare.tres @@ -0,0 +1,27 @@ +[gd_resource type="Resource" load_steps=4 format=3 uid="uid://pr5wnn3ltkbo"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_hcv2h"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_wp40r"] + +[sub_resource type="Resource" id="Resource_ie4sg"] +script = ExtResource("1_hcv2h") +selected = 0 +items = ["==", ">", "<", ">=", "<=", "!="] + +[resource] +script = ExtResource("1_wp40r") +name = &"compare" +target_node_class = "" +description = "" +category = "Logic | Comparison" +type = 3 +variant_type = 1 +display_template = "{float1: FLOAT} {op: NIL} {float2: FLOAT}" +code_template = "{float1} {{op}} {float2}" +defaults = { +"float1": 1.0, +"float2": 1.0, +"op": SubResource("Resource_ie4sg") +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/logic/else.tres b/addons/block_code/blocks/logic/else.tres new file mode 100644 index 00000000..3d55ede7 --- /dev/null +++ b/addons/block_code/blocks/logic/else.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dpgx8j3veifgl"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_x816c"] + +[resource] +script = ExtResource("1_x816c") +name = &"else" +target_node_class = "" +description = "" +category = "Logic | Conditionals" +type = 4 +variant_type = 0 +display_template = "else" +code_template = "else:" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/logic/else_if.tres b/addons/block_code/blocks/logic/else_if.tres new file mode 100644 index 00000000..becb43cb --- /dev/null +++ b/addons/block_code/blocks/logic/else_if.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://by53vmmn3wtny"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_kgjks"] + +[resource] +script = ExtResource("1_kgjks") +name = &"else_if" +target_node_class = "" +description = "" +category = "Logic | Conditionals" +type = 4 +variant_type = 0 +display_template = "else if {condition: BOOL}" +code_template = "elif {condition}:" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/logic/if.tres b/addons/block_code/blocks/logic/if.tres new file mode 100644 index 00000000..a44dd6ca --- /dev/null +++ b/addons/block_code/blocks/logic/if.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cxvoo3jassq8c"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_c6ly3"] + +[resource] +script = ExtResource("1_c6ly3") +name = &"if" +target_node_class = "" +description = "" +category = "Logic | Conditionals" +type = 4 +variant_type = 0 +display_template = "if {condition: BOOL}" +code_template = "if {condition}:" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/logic/not.tres b/addons/block_code/blocks/logic/not.tres new file mode 100644 index 00000000..7be70bad --- /dev/null +++ b/addons/block_code/blocks/logic/not.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://d6asv53q6ok8"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_6igv6"] + +[resource] +script = ExtResource("1_6igv6") +name = &"not" +target_node_class = "" +description = "" +category = "Logic | Boolean" +type = 3 +variant_type = 1 +display_template = "not {bool: BOOL}" +code_template = "not {bool}" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/logic/or.tres b/addons/block_code/blocks/logic/or.tres new file mode 100644 index 00000000..c7b0f909 --- /dev/null +++ b/addons/block_code/blocks/logic/or.tres @@ -0,0 +1,16 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cyu2tntoqf85m"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_oets3"] + +[resource] +script = ExtResource("1_oets3") +name = &"or" +description = "" +category = "Logic | Boolean" +type = 3 +variant_type = 1 +display_template = "{bool1: BOOL} or {bool2: BOOL}" +code_template = "{bool1} or {bool2}" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/loops/await_scene_ready.tres b/addons/block_code/blocks/loops/await_scene_ready.tres new file mode 100644 index 00000000..e418f926 --- /dev/null +++ b/addons/block_code/blocks/loops/await_scene_ready.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bkdmiqavhqrph"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_qy2t4"] + +[resource] +script = ExtResource("1_qy2t4") +name = &"await_scene_ready" +target_node_class = "" +description = "" +category = "Loops" +type = 2 +variant_type = 0 +display_template = "wait for the scene to be ready" +code_template = "if not get_tree().root.is_node_ready(): + await get_tree().root.ready" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/loops/break.tres b/addons/block_code/blocks/loops/break.tres new file mode 100644 index 00000000..5ebf4816 --- /dev/null +++ b/addons/block_code/blocks/loops/break.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dwteydig4c6hi"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_4rhsl"] + +[resource] +script = ExtResource("1_4rhsl") +name = &"break" +target_node_class = "" +description = "" +category = "Loops" +type = 2 +variant_type = 0 +display_template = "break" +code_template = "break" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/loops/continue.tres b/addons/block_code/blocks/loops/continue.tres new file mode 100644 index 00000000..ee8d5afa --- /dev/null +++ b/addons/block_code/blocks/loops/continue.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://srm0bee85n0d"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_junev"] + +[resource] +script = ExtResource("1_junev") +name = &"continue" +target_node_class = "" +description = "" +category = "Loops" +type = 2 +variant_type = 0 +display_template = "continue" +code_template = "continue" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/loops/for.tres b/addons/block_code/blocks/loops/for.tres new file mode 100644 index 00000000..656f67de --- /dev/null +++ b/addons/block_code/blocks/loops/for.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://0g4njflvemaa"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_u01bi"] + +[resource] +script = ExtResource("1_u01bi") +name = &"for" +target_node_class = "" +description = "Run the connected blocks [i]number[/i] times" +category = "Loops" +type = 4 +variant_type = 0 +display_template = "repeat {number: INT}" +code_template = "for __i in {number}:" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/loops/while.tres b/addons/block_code/blocks/loops/while.tres new file mode 100644 index 00000000..8b68cbfb --- /dev/null +++ b/addons/block_code/blocks/loops/while.tres @@ -0,0 +1,19 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ccnjk5s5qb2xe"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_fxxh0"] + +[resource] +script = ExtResource("1_fxxh0") +name = &"while" +target_node_class = "" +description = "Run the connected blocks as long as [i]condition[/i] is true. + +Hint: snap a [b]Comparison[/b] block into the condition." +category = "Loops" +type = 4 +variant_type = 0 +display_template = "while {condition: BOOL}" +code_template = "while {condition}:" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/add.tres b/addons/block_code/blocks/math/add.tres new file mode 100644 index 00000000..336e1afc --- /dev/null +++ b/addons/block_code/blocks/math/add.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://coy3o7q0x0y60"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rks7c"] + +[resource] +script = ExtResource("1_rks7c") +name = &"add" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{a: FLOAT} + {b: FLOAT}" +code_template = "{a} + {b}" +defaults = { +"a": 1.0, +"b": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/cos.tres b/addons/block_code/blocks/math/cos.tres new file mode 100644 index 00000000..1f0bb4a8 --- /dev/null +++ b/addons/block_code/blocks/math/cos.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c6g6ljp46lfrj"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_lxbvo"] + +[resource] +script = ExtResource("1_lxbvo") +name = &"cos" +description = "Calculate the cosine of [i]angle[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "cos {angle: FLOAT}" +code_template = "cos(deg_to_rad({angle}))" +defaults = { +"angle": 0.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/divide.tres b/addons/block_code/blocks/math/divide.tres new file mode 100644 index 00000000..0d6f00a5 --- /dev/null +++ b/addons/block_code/blocks/math/divide.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dwk6c70c4ta0"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rhh7v"] + +[resource] +script = ExtResource("1_rhh7v") +name = &"divide" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{a: FLOAT} / {b: FLOAT}" +code_template = "{a} / {b}" +defaults = { +"a": 1.0, +"b": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/multiply.tres b/addons/block_code/blocks/math/multiply.tres new file mode 100644 index 00000000..1e29b3bb --- /dev/null +++ b/addons/block_code/blocks/math/multiply.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://yipjitb3p66q"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_c5vny"] + +[resource] +script = ExtResource("1_c5vny") +name = &"multiply" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{a: FLOAT} * {b: FLOAT}" +code_template = "{a} * {b}" +defaults = { +"a": 1.0, +"b": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/pow.tres b/addons/block_code/blocks/math/pow.tres new file mode 100644 index 00000000..a21f3eff --- /dev/null +++ b/addons/block_code/blocks/math/pow.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bib11ow5t44to"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_cx5g5"] + +[resource] +script = ExtResource("1_cx5g5") +name = &"pow" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{base: FLOAT} ^ {exp: FLOAT}" +code_template = "pow({base}, {exp})" +defaults = { +"base": 1.0, +"exp": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/randf_range.tres b/addons/block_code/blocks/math/randf_range.tres new file mode 100644 index 00000000..a25e6b54 --- /dev/null +++ b/addons/block_code/blocks/math/randf_range.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://u35glf576fue"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_03jps"] + +[resource] +script = ExtResource("1_03jps") +name = &"randf_range" +target_node_class = "" +description = "Generate a random floating point number between [i]from[/i] and [i]to[/i] inclusively" +category = "Math" +type = 3 +variant_type = 3 +display_template = "random floating point number between {from: FLOAT} and {to: FLOAT}" +code_template = "randf_range({from}, {to})" +defaults = { +"from": -1.0, +"to": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/randi_range.tres b/addons/block_code/blocks/math/randi_range.tres new file mode 100644 index 00000000..f9c8f963 --- /dev/null +++ b/addons/block_code/blocks/math/randi_range.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b3b1dyarh2hmo"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_hk574"] + +[resource] +script = ExtResource("1_hk574") +name = &"randi_range" +target_node_class = "" +description = "Generate a random signed 32-bits integer number between [i]from[/i] and [i]to[/i] inclusively. [i]from[/i] and [i]to[/i] can be a negative or positive number" +category = "Math" +type = 3 +variant_type = 2 +display_template = "random integer number between {from: INT} and {to: INT}" +code_template = "randi_range({from}, {to})" +defaults = { +"from": 0, +"to": 100 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/sin.tres b/addons/block_code/blocks/math/sin.tres new file mode 100644 index 00000000..fca5fca4 --- /dev/null +++ b/addons/block_code/blocks/math/sin.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://b1r7f06rfci6o"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_dlr47"] + +[resource] +script = ExtResource("1_dlr47") +name = &"sin" +description = "Calculate the sine of [i]angle[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "sin {angle: FLOAT}" +code_template = "sin(deg_to_rad({angle}))" +defaults = { +"angle": 0.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/subtract.tres b/addons/block_code/blocks/math/subtract.tres new file mode 100644 index 00000000..1284f408 --- /dev/null +++ b/addons/block_code/blocks/math/subtract.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dkt135xfcklya"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_n0dmm"] + +[resource] +script = ExtResource("1_n0dmm") +name = &"subtract" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{a: FLOAT} - {b: FLOAT}" +code_template = "{a} - {b}" +defaults = { +"a": 1.0, +"b": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/tan.tres b/addons/block_code/blocks/math/tan.tres new file mode 100644 index 00000000..2c6b5cd6 --- /dev/null +++ b/addons/block_code/blocks/math/tan.tres @@ -0,0 +1,18 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://blpo01pjjheqb"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_e2566"] + +[resource] +script = ExtResource("1_e2566") +name = &"tan" +description = "Calculate the tangent of [i]angle[/i]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "tan {angle: FLOAT}" +code_template = "tan(deg_to_rad({angle}))" +defaults = { +"angle": 0.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/vector2_xy.tres b/addons/block_code/blocks/math/vector2_xy.tres new file mode 100644 index 00000000..32846064 --- /dev/null +++ b/addons/block_code/blocks/math/vector2_xy.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=4 format=3 uid="uid://bpdjqy6oidfo4"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_p8v57"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="2_207xo"] + +[sub_resource type="Resource" id="Resource_ie4sg"] +script = ExtResource("1_p8v57") +selected = 0 +items = ["x", "y"] + +[resource] +script = ExtResource("2_207xo") +name = &"vector2_xy" +target_node_class = "" +description = "Gives the x or y of a [b]Vector2[/b]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{xy: NIL} of {vector2: VECTOR2}" +code_template = "{vector2}.{{xy}}" +defaults = { +"xy": SubResource("Resource_ie4sg") +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/math/vector3_multiply.tres b/addons/block_code/blocks/math/vector3_multiply.tres new file mode 100644 index 00000000..65b8ff55 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_multiply.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ctl30ew7wtnlj"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_bxnpg"] + +[resource] +script = ExtResource("1_bxnpg") +name = &"vector3_multiply" +target_node_class = "" +description = "Multiplies a Vector3 with a number. Use this, for example, to get a point some distance away along an angle." +category = "Math" +type = 3 +variant_type = 9 +display_template = "multiply {vector: VECTOR3} by {number: FLOAT}" +code_template = "{vector} * {number}" +defaults = { +"number": 1.0, +"vector": Vector3(1, 1, 1) +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/math/vector3_xyz.tres b/addons/block_code/blocks/math/vector3_xyz.tres new file mode 100644 index 00000000..01374a87 --- /dev/null +++ b/addons/block_code/blocks/math/vector3_xyz.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=4 format=3 uid="uid://s72tgtbci1ui"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_0wc0o"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="2_e6ohf"] + +[sub_resource type="Resource" id="Resource_ie4sg"] +script = ExtResource("1_0wc0o") +selected = 0 +items = ["x", "y", "z"] + +[resource] +script = ExtResource("2_e6ohf") +name = &"vector3_xyz" +target_node_class = "" +description = "Gives the x, y, or z of a [b]Vector3[/b]" +category = "Math" +type = 3 +variant_type = 3 +display_template = "{xyz: NIL} of {vector3: VECTOR3}" +code_template = "{vector3}.{{xyz}}" +defaults = { +"xyz": SubResource("Resource_ie4sg") +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/math/vector_from_angle.tres b/addons/block_code/blocks/math/vector_from_angle.tres new file mode 100644 index 00000000..fce91df3 --- /dev/null +++ b/addons/block_code/blocks/math/vector_from_angle.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c7a6wnxegkfd5"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_1p1ve"] + +[resource] +script = ExtResource("1_1p1ve") +name = &"from_angle" +target_node_class = "" +description = "Creates a unit Vector2 rotated to the given angle in radians." +category = "Math" +type = 3 +variant_type = 5 +display_template = "vector from {angle: FLOAT}" +code_template = "Vector2.from_angle({angle})" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/math/vector_multiply.tres b/addons/block_code/blocks/math/vector_multiply.tres new file mode 100644 index 00000000..8c82607d --- /dev/null +++ b/addons/block_code/blocks/math/vector_multiply.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bff7cwmpisihj"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_52jwf"] + +[resource] +script = ExtResource("1_52jwf") +name = &"vector_multiply" +target_node_class = "" +description = "Multiplies a vector with a number. Use this, for example, to get a point some distance away along an angle." +category = "Math" +type = 3 +variant_type = 5 +display_template = "multiply {vector: VECTOR2} by {number: FLOAT}" +code_template = "{vector} * {number}" +defaults = { +"number": 1.0, +"vector": Vector2(1, 1) +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/physics/characterbody2d_move_and_slide.tres b/addons/block_code/blocks/physics/characterbody2d_move_and_slide.tres new file mode 100644 index 00000000..1e6a2121 --- /dev/null +++ b/addons/block_code/blocks/physics/characterbody2d_move_and_slide.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cp6ak6wea8ogh"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_e3r2r"] + +[resource] +script = ExtResource("1_e3r2r") +name = &"characterbody2d_move_and_slide" +target_node_class = "CharacterBody2D" +description = "" +category = "Physics | Velocity" +type = 2 +variant_type = 0 +display_template = "move and slide" +code_template = "move_and_slide()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/sounds/audiostreamplayer_play.tres b/addons/block_code/blocks/sounds/audiostreamplayer_play.tres new file mode 100644 index 00000000..92fab524 --- /dev/null +++ b/addons/block_code/blocks/sounds/audiostreamplayer_play.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bxjjml7u3rokv"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_vyl5w"] + +[resource] +script = ExtResource("1_vyl5w") +name = &"audiostreamplayer_play" +target_node_class = "AudioStreamPlayer" +description = "Play the audio stream" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "play" +code_template = "play()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/sounds/audiostreamplayer_stop.tres b/addons/block_code/blocks/sounds/audiostreamplayer_stop.tres new file mode 100644 index 00000000..c0ea7c8e --- /dev/null +++ b/addons/block_code/blocks/sounds/audiostreamplayer_stop.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ib16grbtduab"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_db4g2"] + +[resource] +script = ExtResource("1_db4g2") +name = &"audiostreamplayer_stop" +target_node_class = "AudioStreamPlayer" +description = "Stop the audio stream" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "stop" +code_template = "stop()" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/sounds/load_sound.tres b/addons/block_code/blocks/sounds/load_sound.tres new file mode 100644 index 00000000..8f036665 --- /dev/null +++ b/addons/block_code/blocks/sounds/load_sound.tres @@ -0,0 +1,21 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://coefocdmytg0j"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_4w4si"] + +[resource] +script = ExtResource("1_4w4si") +name = &"load_sound" +target_node_class = "" +description = "Load a resource file as the audio stream" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "load file {file_path: STRING} as sound {name: STRING}" +code_template = "var __sound = AudioStreamPlayer.new() +__sound.name = {name} +__sound.set_stream(load({file_path})) +add_child(__sound) +" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/sounds/pause_continue_sound.tres b/addons/block_code/blocks/sounds/pause_continue_sound.tres new file mode 100644 index 00000000..946c5b94 --- /dev/null +++ b/addons/block_code/blocks/sounds/pause_continue_sound.tres @@ -0,0 +1,30 @@ +[gd_resource type="Resource" load_steps=4 format=3 uid="uid://wpdspamg3f6g"] + +[ext_resource type="Script" uid="uid://bkapmk0btnk7y" path="res://addons/block_code/code_generation/option_data.gd" id="1_ilhdq"] +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_q04gm"] + +[sub_resource type="Resource" id="Resource_lalgp"] +script = ExtResource("1_ilhdq") +selected = 0 +items = ["pause", "continue"] + +[resource] +script = ExtResource("1_q04gm") +name = &"pause_continue_sound" +target_node_class = "" +description = "Pause/Continue the audio stream" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "{pause: NIL} the sound {name: STRING}" +code_template = "var __sound_node = get_node({name}) +if {pause} == \"pause\": + __sound_node.stream_paused = true +else: + __sound_node.stream_paused = false +" +defaults = { +"pause": SubResource("Resource_lalgp") +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/blocks/sounds/play_sound.tres b/addons/block_code/blocks/sounds/play_sound.tres new file mode 100644 index 00000000..06d6a34a --- /dev/null +++ b/addons/block_code/blocks/sounds/play_sound.tres @@ -0,0 +1,24 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://dt022ilveapt5"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_llfp1"] + +[resource] +script = ExtResource("1_llfp1") +name = &"play_sound" +target_node_class = "" +description = "Play the audio stream with volume and pitch" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "play the sound {name: STRING} | with volume {db: FLOAT} dB and pitch scale {pitch: FLOAT}" +code_template = "var __sound_node = get_node({name}) +__sound_node.volume_db = {db} +__sound_node.pitch_scale = {pitch} +__sound_node.play() +" +defaults = { +"db": 0.0, +"pitch": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/sounds/stop_sound.tres b/addons/block_code/blocks/sounds/stop_sound.tres new file mode 100644 index 00000000..91532df8 --- /dev/null +++ b/addons/block_code/blocks/sounds/stop_sound.tres @@ -0,0 +1,22 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://csg40u5awp1sy"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_rfujh"] + +[resource] +script = ExtResource("1_rfujh") +name = &"stop_sound" +target_node_class = "" +description = "Stop the audio stream" +category = "Sounds" +type = 2 +variant_type = 0 +display_template = "stop the sound {name: STRING}" +code_template = "var __sound_node = get_node({name}) +__sound_node.stop() +" +defaults = { +"db": 0.0, +"pitch": 1.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/spawn/cpuparticles2d_finished.tres b/addons/block_code/blocks/spawn/cpuparticles2d_finished.tres new file mode 100644 index 00000000..7758be63 --- /dev/null +++ b/addons/block_code/blocks/spawn/cpuparticles2d_finished.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://c188gpgf4rpns"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_pmpup"] + +[resource] +script = ExtResource("1_pmpup") +name = &"cpuparticles2d_finished" +target_node_class = "CPUParticles2D" +description = "Emitted when all active particles have finished processing." +category = "Lifecycle | Spawn" +type = 1 +variant_type = 0 +display_template = "when particles are finished" +code_template = "func _on_finished():" +defaults = {} +signal_name = "finished" +scope = "" diff --git a/addons/block_code/blocks/transform/rigidbody2d_physics_position.tres b/addons/block_code/blocks/transform/rigidbody2d_physics_position.tres new file mode 100644 index 00000000..10039930 --- /dev/null +++ b/addons/block_code/blocks/transform/rigidbody2d_physics_position.tres @@ -0,0 +1,22 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ses5486g56q"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_72i54"] + +[resource] +script = ExtResource("1_72i54") +name = &"rigidbody2d_physics_position" +target_node_class = "RigidBody2D" +description = "" +category = "Transform | Position" +type = 2 +variant_type = 0 +display_template = "set physics position {position: VECTOR2}" +code_template = "PhysicsServer2D.body_set_state( + get_rid(), + PhysicsServer2D.BODY_STATE_TRANSFORM, + Transform2D.IDENTITY.translated({position}) +) +" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/ui/label_set_text.tres b/addons/block_code/blocks/ui/label_set_text.tres new file mode 100644 index 00000000..1a4f82ca --- /dev/null +++ b/addons/block_code/blocks/ui/label_set_text.tres @@ -0,0 +1,17 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ciqkywxdk4uht"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_bofov"] + +[resource] +script = ExtResource("1_bofov") +name = &"label_set_text" +target_node_class = "Label" +description = "Set the text for the label." +category = "UI" +type = 2 +variant_type = 0 +display_template = "set text to {text: STRING}" +code_template = "text = {text}" +defaults = {} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/variables/vector2.tres b/addons/block_code/blocks/variables/vector2.tres new file mode 100644 index 00000000..c11e43bd --- /dev/null +++ b/addons/block_code/blocks/variables/vector2.tres @@ -0,0 +1,20 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ddj24k1fp0s82"] + +[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_ilw3v"] + +[resource] +script = ExtResource("1_ilw3v") +name = &"vector2" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 5 +display_template = "vector2 x: {x: FLOAT} y: {y: FLOAT}" +code_template = "Vector2({x}, {y})" +defaults = { +"x": 0.0, +"y": 0.0 +} +signal_name = "" +scope = "" diff --git a/addons/block_code/blocks/variables/vector3.tres b/addons/block_code/blocks/variables/vector3.tres new file mode 100644 index 00000000..a4633e61 --- /dev/null +++ b/addons/block_code/blocks/variables/vector3.tres @@ -0,0 +1,21 @@ +[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ydahicas0yma"] + +[ext_resource type="Script" uid="uid://bau6qtv87fcdo" path="res://addons/block_code/code_generation/block_definition.gd" id="1_62jin"] + +[resource] +script = ExtResource("1_62jin") +name = &"vector3" +target_node_class = "" +description = "" +category = "Math" +type = 3 +variant_type = 9 +display_template = "vector3 x: {x: FLOAT} y: {y: FLOAT}: z: {z: FLOAT}" +code_template = "Vector3({x}, {y}, {z})" +defaults = { +"x": 0.0, +"y": 0.0, +"z": 0.0 +} +signal_name = "" +is_advanced = false diff --git a/addons/block_code/code_generation/ast_list.gd b/addons/block_code/code_generation/ast_list.gd new file mode 100644 index 00000000..aafb6caa --- /dev/null +++ b/addons/block_code/code_generation/ast_list.gd @@ -0,0 +1,37 @@ +extends RefCounted + +const Types = preload("res://addons/block_code/types/types.gd") +const BlockAST = preload("res://addons/block_code/code_generation/block_ast.gd") + +var array: Array[ASTPair] + + +class ASTPair: + var ast: BlockAST + var canvas_position: Vector2 + + func _init(p_ast: BlockAST, p_canvas_position: Vector2): + ast = p_ast + canvas_position = p_canvas_position + + +func _init(): + array = [] + + +func append(ast: BlockAST, canvas_position: Vector2): + array.append(ASTPair.new(ast, canvas_position)) + + +func clear(): + array.clear() + + +func get_top_level_nodes_of_type(block_type: Types.BlockType) -> Array[BlockAST]: + var asts: Array[BlockAST] = [] + + for ast_pair in array: + if ast_pair.ast.root.data.type == block_type: + asts.append(ast_pair.ast) + + return asts diff --git a/addons/block_code/code_generation/ast_list.gd.uid b/addons/block_code/code_generation/ast_list.gd.uid new file mode 100644 index 00000000..cda02b1d --- /dev/null +++ b/addons/block_code/code_generation/ast_list.gd.uid @@ -0,0 +1 @@ +uid://b052nx55audtf diff --git a/addons/block_code/code_generation/block_ast.gd b/addons/block_code/code_generation/block_ast.gd new file mode 100644 index 00000000..865e3047 --- /dev/null +++ b/addons/block_code/code_generation/block_ast.gd @@ -0,0 +1,141 @@ +extends RefCounted + +const BlockAST = preload("res://addons/block_code/code_generation/block_ast.gd") +const OptionData = preload("res://addons/block_code/code_generation/option_data.gd") +const Types = preload("res://addons/block_code/types/types.gd") + +var root: ASTNode + + +class IDHandler: + static var counts: Dictionary = {} + + static func reset(): + counts = {} + + static func get_unique_id(str: String) -> int: + if not counts.has(str): + counts[str] = 0 + + counts[str] += 1 + + return counts[str] + + static func make_unique(formatted_string: String) -> String: + var unique_string = formatted_string + var regex = RegEx.new() + regex.compile("\\b__[^\\s]+") + var ids: Dictionary = {} + for result in regex.search_all(formatted_string): + var result_string = result.get_string() + if not ids.has(result_string): + ids[result_string] = get_unique_id(result_string) + unique_string = unique_string.replace(result_string, result_string + "_%d" % ids[result_string]) + + return unique_string + + +class ASTNode: + var data #: BlockDefinition + var children: Array[ASTNode] + var arguments: Dictionary # String, ASTValueNode + + func _init(): + children = [] + arguments = {} + + func _get_code_block() -> String: + var code_block: String = BlockAST.format_code_template(data.code_template, arguments) + return IDHandler.make_unique(code_block) + + func get_code(depth: int) -> String: + var code: String = "" + + # append code block + var code_block := _get_code_block() + code_block = code_block.indent("\t".repeat(depth)) + + code += code_block + "\n" + + # fill empty entry and control blocks with pass + if children.is_empty() and (data.type == Types.BlockType.ENTRY || data.type == Types.BlockType.CONTROL): + code += "pass\n".indent("\t".repeat(depth + 1)) + + for child in children: + code += child.get_code(depth + 1) + + return code + + +class ASTValueNode: + var data #: BlockDefinition + var arguments: Dictionary # String, ASTValueNode + + func _init(): + arguments = {} + + func get_code() -> String: + var code: String = BlockAST.format_code_template(data.code_template, arguments) + return IDHandler.make_unique("(%s)" % code) + + +func get_code() -> String: + IDHandler.reset() + return root.get_code(0) + + +func _to_string(): + return to_string_recursive(root, 0) + + +func to_string_recursive(node: ASTNode, depth: int) -> String: + var string: String = "%s %s\n" % ["-".repeat(depth), node.data.display_template] + + for c in node.children: + string += to_string_recursive(c, depth + 1) + + return string + + +static func format_code_template(code_template: String, arguments: Dictionary) -> String: + for argument_name in arguments: + # Use parentheses to be safe + var argument_value: Variant = arguments[argument_name] + var code_string: String + var raw_string: String + + if argument_value is OptionData: + # Temporary hack: previously, the value was stored as an OptionData + # object with a list of items and a "selected" property. If we are + # using an older block script where that is the case, convert the + # value to the value of its selected item. + # See also, ParameterInput._update_option_input. + argument_value = argument_value.items[argument_value.selected] + + if argument_value is ASTValueNode: + code_string = argument_value.get_code() + raw_string = code_string + else: + code_string = BlockAST.raw_input_to_code_string(argument_value) + raw_string = str(argument_value) + + code_template = code_template.replace("{{%s}}" % argument_name, raw_string) + code_template = code_template.replace("{%s}" % argument_name, code_string) + + return code_template + + +static func raw_input_to_code_string(input) -> String: + match typeof(input): + TYPE_STRING: + return "'%s'" % input.c_escape() + TYPE_VECTOR2: + return "Vector2%s" % str(input) + TYPE_VECTOR3: + return "Vector3%s" % str(input) + TYPE_COLOR: + return "Color%s" % str(input) + _: + return "%s" % input + + return "" diff --git a/addons/block_code/code_generation/block_ast.gd.uid b/addons/block_code/code_generation/block_ast.gd.uid new file mode 100644 index 00000000..776c8b97 --- /dev/null +++ b/addons/block_code/code_generation/block_ast.gd.uid @@ -0,0 +1 @@ +uid://ds7sl2qhnam75 diff --git a/addons/block_code/code_generation/block_definition.gd b/addons/block_code/code_generation/block_definition.gd new file mode 100644 index 00000000..75273a73 --- /dev/null +++ b/addons/block_code/code_generation/block_definition.gd @@ -0,0 +1,294 @@ +@tool +extends Resource + +const Types = preload("res://addons/block_code/types/types.gd") +const VariableDefinition = preload("res://addons/block_code/code_generation/variable_definition.gd") + +const FORMAT_STRING_PATTERN = "\\[(?[^\\]]+)\\]|\\{const (?[^}]+)\\}|\\{(?!const )(?[^}]+)\\}|(?