Skip to content

Commit

Permalink
Merge branch 'endlessm:main' into add_duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
urbit-pilled authored Dec 17, 2024
2 parents 1d0735f + a9c7193 commit c1b942b
Show file tree
Hide file tree
Showing 147 changed files with 45,062 additions and 1,720 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8

[*.gd]
indent_style = tab
max_line_length = 200
5 changes: 0 additions & 5 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -20,7 +20,7 @@ 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
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ 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
Expand Down Expand Up @@ -42,4 +47,4 @@ jobs:
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
8 changes: 3 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# <https://github.com/Scony/godot-gdscript-toolkit/commit/e3c37fa54fb32ad99b0bceb2f17e7bc1ffd99806>
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/.*)$
8 changes: 8 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -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/<lang>.po
type = PO
88 changes: 82 additions & 6 deletions addons/block_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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.
Expand Down Expand Up @@ -62,10 +64,79 @@ We have some high level blocks for simplifying common game elements. Add a Simpl

Lean into animations! Godot's animations functionality goes beyond just simple animations of graphics. You can do so much by combining block coding with Godot's powerful animations editor.

If you want to access the node's property, you can drag the property from the Inspector dock and drop it into the block script as a getter block. And, if you want to modify the property's value, please press & hold Ctrl key when you drop the property, then it will be a setter block of the property in the block script.

You can also drag a file from the Resource Filesystem dock and drop it into the block script as a getter block. It will become a constant value block holding the file's resource full path.

## 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).

## 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

### pre-commit
Expand All @@ -89,14 +160,19 @@ 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
Expand Down
20 changes: 19 additions & 1 deletion addons/block_code/block_code_node/block_code.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
class_name BlockCode
extends Node

@export var block_script: BlockScriptSerialization = null
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():
Expand Down Expand Up @@ -31,6 +38,17 @@ func _enter_tree():
block_script = new_block_script


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():
if Engine.is_editor_hint():
push_error("Updating the parent script must happen in game.")
Expand Down
18 changes: 18 additions & 0 deletions addons/block_code/block_code_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends EditorPlugin
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
Expand All @@ -12,6 +13,9 @@ 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
Expand All @@ -29,6 +33,11 @@ const DISABLED_CLASSES := [
]


func _init():
TxUtils.load_translations()
TxUtils.set_block_translation_domain(self)


func _enter_tree():
Types.init_cast_graph()

Expand All @@ -41,6 +50,14 @@ func _enter_tree():
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)

# 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()

Expand Down Expand Up @@ -69,6 +86,7 @@ func script_window_requested(script: String):


func _exit_tree():
remove_translation_parser_plugin(_tx_parser_plugin)
remove_inspector_plugin(block_inspector_plugin)

if block_code_button:
Expand Down
18 changes: 18 additions & 0 deletions addons/block_code/blocks/communication/switch_scene.tres
Original file line number Diff line number Diff line change
@@ -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 = ""
5 changes: 4 additions & 1 deletion addons/block_code/code_generation/block_definition.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extends Resource

const Types = preload("res://addons/block_code/types/types.gd")

const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{(?<in_parameter>[^}]+)\\}|(?<label>[^\\{\\[]+)"
const FORMAT_STRING_PATTERN = "\\[(?<out_parameter>[^\\]]+)\\]|\\{const (?<const_parameter>[^}]+)\\}|\\{(?!const )(?<in_parameter>[^}]+)\\}|(?<label>[^\\{\\[]+)"

@export var name: StringName

Expand Down Expand Up @@ -102,6 +102,9 @@ static func parse_display_template(template_string: String):
elif regex_match.names.has("out_parameter"):
var parameter_string := regex_match.get_string("out_parameter")
items.append({"out_parameter": _parse_parameter_format(parameter_string)})
elif regex_match.names.has("const_parameter"):
var parameter_string := regex_match.get_string("const_parameter")
items.append({"const_parameter": _parse_parameter_format(parameter_string)})
return items


Expand Down
Loading

0 comments on commit c1b942b

Please sign in to comment.