|
29 | 29 |
|
30 | 30 | 6. When you play the scene, each `BlockCode` node will attach a generated script from it's BSD to it's parent node. The `_ready` and `_process` methods will start normally.
|
31 | 31 |
|
| 32 | +## How to create a new block |
| 33 | + |
| 34 | +Blocks are created from a template such as `StatementBlock`, `ParameterBlock`, `EntryBlock`, or `ControlBlock`. Blocks are defined programmatically and generated live, they are not saved permanently in any sort of class. |
| 35 | +* `StatementBlock`: Generates a line of code to be executed. Has notches to snap other statement blocks to. Supports input parameters. |
| 36 | +* `ParameterBlock`: Represents a value, or expression in some code. Can be used as input for any statement blocks, or other parameter blocks that also take input. |
| 37 | +* `EntryBlock`: Generates a method header, entry point to block script. Also supports input parameters. |
| 38 | +* `ControlBlock`: Dictates the flow of instruction, such as a loop or if/else statement. Can have multiple slots for calling different statements based on a conditional input. |
| 39 | + |
| 40 | +You can define a block: |
| 41 | +1. Globally in `CategoryFactory.get_general_categories()` |
| 42 | +2. For a specific built-in class in `CategoryFactory.get_built_in_categories()` |
| 43 | +3. In a custom class by defining a method `static func get_custom_blocks() -> Array[BlockCategory]:`. See `SimpleCharacter` for an example. |
| 44 | + |
| 45 | +Here is an example of generating a `STATEMENT` block: |
| 46 | +``` |
| 47 | +# Instantiate the template block. In this case we use a StatementBlock since we want to generate a statement from some parameter inputs. |
| 48 | +var b = BLOCKS["statement_block"].instantiate() |
| 49 | +
|
| 50 | +# Define the block format string. This is how the block will be rendered, with some text and two typed inputs. |
| 51 | +# Inputs are specified as {parameter_name: TYPE} |
| 52 | +b.block_format = "Set Int {var: STRING} {value: INT}" |
| 53 | +
|
| 54 | +# Define the statement that will be generated from the inputs. Use the parameter name to specify which goes where. |
| 55 | +b.statement = "VAR_DICT[{var}] = {value}" |
| 56 | +``` |
| 57 | +You can then add this new block to a `BlockCategory` like so: |
| 58 | +``` |
| 59 | +var variable_list: Array[Block] = [] |
| 60 | +variable_list.append(b) |
| 61 | +var variable_category: BlockCategory = BlockCategory.new("Variables", variable_list, Color("4f975d")) |
| 62 | +``` |
| 63 | +Look in `CategoryFactory` for more examples! |
| 64 | + |
| 65 | +Note: For `EntryBlock`s, you can use the syntax `[param: TYPE]` with square brackets instead of curlies to generate a copyable `ParameterBlock` that can be used in the below method. |
| 66 | +For example, to expose the `delta` argument in `func _on_process(delta):`, you would use the following format string: |
| 67 | +``` |
| 68 | +b.block_format = "On Process [delta: FLOAT]" |
| 69 | +``` |
32 | 70 |
|
33 | 71 | ## What's inside?
|
34 | 72 |
|
|
59 | 97 | * `/block_canvas/`: Contains the code for the `BlockCanvas` which loads and holds blocks on a canvas. Inherited by `NodeBlockCanvas` which can generate scripts for block scripts made for Godot `Node`s (which is all of the scripts ATM). Also contains resources for serializing blocks.
|
60 | 98 | * `/bsd_templates/`: Template block script data files for loading a default script. E.g. `_ready` and `_process` entry blocks already on canvas.
|
61 | 99 | * `/node_canvas/`: Deprecated
|
62 |
| - * `/node_lsit/`: Deprecated |
| 100 | + * `/node_list/`: Deprecated |
63 | 101 | * `/picker/`: Contains the picker scene, and code that generates the blocks that populate the picker.
|
64 | 102 | * `/categories/`: Contains `CategoryFactory` which generates the global block list programmatically from template blocks.
|
65 | 103 | * `/title_bar/`: Contains the title bar which should display the name of the current script and the node it inherits from.
|
|
0 commit comments