diff --git a/.gdlintrc b/.gdlintrc new file mode 100644 index 000000000..e44951049 --- /dev/null +++ b/.gdlintrc @@ -0,0 +1,48 @@ +class-definitions-order: +- tools +- classnames +- extends +- docstrings +- signals +- enums +- consts +- exports +- pubvars +- prvvars +- onreadypubvars +- onreadyprvvars +- staticvars +- others +class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*) +class-name: ([A-Z][a-z0-9]*)+ +class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* +comparison-with-itself: null +constant-name: _?[A-Z][A-Z0-9]*(_[A-Z0-9]+)* +disable: [] +duplicated-load: null +enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*' +enum-name: ([A-Z][a-z0-9]*)+ +excluded_directories: !!set + .git: null +expression-not-assigned: null +function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* +function-arguments-number: 10 +function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*) +function-preload-variable-name: ([A-Z][a-z0-9]*)+ +function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*' +load-constant-name: (([A-Z][a-z0-9]*)+|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*) +loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* +max-file-lines: 1000 +max-line-length: 140 +max-public-methods: 999 +max-returns: 20 +mixed-tabs-and-spaces: null +no-elif-return: null +no-else-return: null +private-method-call: null +signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*' +sub-class-name: _?([A-Z][a-z0-9]*)+ +tab-characters: 1 +trailing-whitespace: null +unnecessary-pass: null +unused-argument: null diff --git a/.github/workflows/gdlint.yml b/.github/workflows/gdlint.yml new file mode 100644 index 000000000..420dbc295 --- /dev/null +++ b/.github/workflows/gdlint.yml @@ -0,0 +1,43 @@ +name: GHA + +run-name: ${{ github.head_ref || github.ref_name }}-gdlint + +on: + workflow_call: + workflow_dispatch: + +jobs: + gdlint: + name: Formatting Checks + runs-on: 'ubuntu-22.04' + timeout-minutes: 5 + + steps: + - name: Checkout GdUnit Repository + uses: actions/checkout@v5 + with: + lfs: true + + - name: "Setup GDLint" + uses: Scony/godot-gdscript-toolkit@master + with: + version: 4.5.0 + + - name: "Run GDLint" + id: run-gdlint + shell: bash + run: | + mkdir -p reports/gdlint/ + gdlint addons/gaea/editor/ | tee reports/gdlint/editor.txt + gdlint addons/gaea/graph/ | tee reports/gdlint/graph.txt + gdlint addons/gaea/nodes/ | tee reports/gdlint/nodes.txt + gdlint addons/gaea/resources/ | tee reports/gdlint/resources.txt + + - name: "Upload GDLint Report" + if: failure() + uses: actions/upload-artifact@v4 + with: + name: gdlint.txt + path: reports/gdlint/** + if-no-files-found: error + compression-level: 0 # no compression diff --git a/.github/workflows/generation_testing.yml b/.github/workflows/generation_testing.yml index c80508867..9b7709525 100644 --- a/.github/workflows/generation_testing.yml +++ b/.github/workflows/generation_testing.yml @@ -1,10 +1,7 @@ name: GHA on: - pull_request: - paths-ignore: - - '**.yml' - - '**.md' + workflow_call: workflow_dispatch: @@ -15,8 +12,8 @@ concurrency: jobs: generate_test: - name: "Generation Testing" - runs-on: 'ubuntu-22.04' + name: Tests + runs-on: 'ubuntu-24.04' timeout-minutes: 10 # The overall timeout permissions: actions: write @@ -27,7 +24,7 @@ jobs: steps: # checkout your repository - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: lfs: true # run tests by using the gdUnit4-action with Godot version 4.2.1 and the latest GdUnit4 release @@ -38,3 +35,4 @@ jobs: res://testing/generation timeout: 5 publish-report: false + report-name: generation-gdunit4 diff --git a/.github/workflows/nodes_testing.yml b/.github/workflows/nodes_testing.yml index b0863983c..4eccbae23 100644 --- a/.github/workflows/nodes_testing.yml +++ b/.github/workflows/nodes_testing.yml @@ -1,10 +1,7 @@ name: GHA on: - pull_request: - paths-ignore: - - '**.yml' - - '**.md' + workflow_call: workflow_dispatch: @@ -15,8 +12,8 @@ concurrency: jobs: warning_check: - name: "Node Testing" - runs-on: 'ubuntu-22.04' + name: Tests + runs-on: 'ubuntu-24.04' timeout-minutes: 10 # The overall timeout permissions: actions: write @@ -38,3 +35,4 @@ jobs: res://testing/graph_nodes timeout: 5 publish-report: false + report-name: nodes-gdunit4 diff --git a/.github/workflows/on-prs.yml b/.github/workflows/on-prs.yml new file mode 100644 index 000000000..b028699f9 --- /dev/null +++ b/.github/workflows/on-prs.yml @@ -0,0 +1,67 @@ +name: GHA + +run-name: ${{ github.head_ref || github.ref_name }}-gha + +on: # yamllint disable-line rule:truthy + pull_request: + paths-ignore: + - '**.yml' + - '**.md' + workflow_dispatch: + +concurrency: + group: gha-${{ github.event.number }} + cancel-in-progress: true + + +jobs: + gdlint: + if: ${{ !cancelled() }} + name: '📝 GDLint' + uses: ./.github/workflows/gdlint.yml + + generation_testing: + name: '🐞 Generation' + uses: ./.github/workflows/generation_testing.yml + + permissions: + actions: write + checks: write + contents: write + pull-requests: write + statuses: write + + nodes_testing: + name: '🐞 Node' + uses: ./.github/workflows/nodes_testing.yml + + permissions: + actions: write + checks: write + contents: write + pull-requests: write + statuses: write + + renderers_testing: + name: '🐞 Renderers' + uses: ./.github/workflows/renderers_testing.yml + + permissions: + actions: write + checks: write + contents: write + pull-requests: write + statuses: write + + other_testing: + name: '🐞 Other' + uses: ./.github/workflows/other_testing.yml + + permissions: + actions: write + checks: write + contents: write + pull-requests: write + statuses: write + + diff --git a/.github/workflows/other_testing.yml b/.github/workflows/other_testing.yml index 4705d22ee..6994020a1 100644 --- a/.github/workflows/other_testing.yml +++ b/.github/workflows/other_testing.yml @@ -1,10 +1,7 @@ name: GHA on: - pull_request: - paths-ignore: - - '**.yml' - - '**.md' + workflow_call: workflow_dispatch: @@ -15,8 +12,8 @@ concurrency: jobs: warning_check: - name: "Other Testing" - runs-on: 'ubuntu-22.04' + name: Tests + runs-on: 'ubuntu-24.04' timeout-minutes: 10 # The overall timeout permissions: actions: write @@ -27,7 +24,7 @@ jobs: steps: # checkout your repository - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: lfs: true # run tests by using the gdUnit4-action with Godot version 4.2.1 and the latest GdUnit4 release @@ -38,3 +35,4 @@ jobs: res://testing/other timeout: 5 publish-report: false + report-name: other-gdunit4 diff --git a/.github/workflows/renderers_testing.yml b/.github/workflows/renderers_testing.yml index ad3b379bd..b0eac7580 100644 --- a/.github/workflows/renderers_testing.yml +++ b/.github/workflows/renderers_testing.yml @@ -1,10 +1,7 @@ name: GHA on: - pull_request: - paths-ignore: - - '**.yml' - - '**.md' + workflow_call: workflow_dispatch: @@ -15,8 +12,8 @@ concurrency: jobs: warning_check: - name: "Rendering Testing" - runs-on: 'ubuntu-22.04' + name: Tests + runs-on: 'ubuntu-24.04' timeout-minutes: 10 # The overall timeout permissions: actions: write @@ -27,7 +24,7 @@ jobs: steps: # checkout your repository - - uses: actions/checkout@v4 + - uses: actions/checkout@v5 with: lfs: true # run tests by using the gdUnit4-action with Godot version 4.2.1 and the latest GdUnit4 release @@ -38,3 +35,4 @@ jobs: res://testing/rendering timeout: 5 publish-report: false + report-name: rendering-gdunit4 diff --git a/addons/gaea/editor/about_window.gd b/addons/gaea/editor/about_window.gd index 300c2c776..2adbc1b96 100644 --- a/addons/gaea/editor/about_window.gd +++ b/addons/gaea/editor/about_window.gd @@ -1,7 +1,6 @@ @tool extends AcceptDialog - const CONTRIBUTORS_LIST := "res://addons/gaea/contributors.txt" var plugin: EditorPlugin @@ -12,7 +11,6 @@ var plugin: EditorPlugin @onready var _version_label: LinkButton = %VersionLabel - func initialize() -> void: if is_part_of_edited_scene(): return @@ -20,11 +18,17 @@ func initialize() -> void: _version_label.text = "Gaea %s" % plugin.get_plugin_version() _version_label.uri = "https://github.com/gaea-godot/gaea/releases/tag/%s" % plugin.get_plugin_version() _version_label.tooltip_text = _version_label.uri - _contributors_panel.add_theme_stylebox_override(&"panel", EditorInterface.get_base_control().get_theme_stylebox(&"LaunchPadNormal", &"EditorStyles")) + _contributors_panel.add_theme_stylebox_override( + &"panel", + EditorInterface.get_base_control().get_theme_stylebox(&"LaunchPadNormal", &"EditorStyles") + ) for child in _main_vbox.get_children(): if child is not PanelContainer: continue - child.add_theme_stylebox_override(&"panel", EditorInterface.get_base_control().get_theme_stylebox(&"Background", &"EditorStyles")) + child.add_theme_stylebox_override( + &"panel", + EditorInterface.get_base_control().get_theme_stylebox(&"Background", &"EditorStyles") + ) var contributors: Array[String] var file := FileAccess.open(CONTRIBUTORS_LIST, FileAccess.READ) diff --git a/addons/gaea/editor/create_node_popup.gd b/addons/gaea/editor/create_node_popup.gd index d9db06735..808329617 100644 --- a/addons/gaea/editor/create_node_popup.gd +++ b/addons/gaea/editor/create_node_popup.gd @@ -1,7 +1,6 @@ @tool extends Window - @onready var cancel_button: Button = %CancelButton @onready var tool_button: Button = %ToolButton @onready var tool_popup: PopupMenu = %ToolPopup diff --git a/addons/gaea/editor/create_node_tree.gd b/addons/gaea/editor/create_node_tree.gd index 179d0ffa8..291650459 100644 --- a/addons/gaea/editor/create_node_tree.gd +++ b/addons/gaea/editor/create_node_tree.gd @@ -1,7 +1,6 @@ @tool extends Tree - signal node_selected_for_creation(resource: GaeaNodeResource) signal special_node_selected_for_creation(id: StringName) @@ -23,7 +22,7 @@ func _unhandled_key_input(event: InputEvent) -> void: _select_next_visible( get_selected() if get_selected() != null else get_root(), 1 if not event.is_shift_pressed() else -1 - ) + ) func populate() -> void: @@ -31,11 +30,11 @@ func populate() -> void: var root: TreeItem = create_item() hide_root = true tree_dictionary = _populate_dict_with_files(NODES_FOLDER_PATH, {}) - tree_dictionary["Special"] = { - "Frame": &"frame" - } + tree_dictionary["Special"] = {"Frame": &"frame"} if not GaeaProjectSettings.get_custom_nodes_path().is_empty(): - tree_dictionary = _populate_dict_with_files(GaeaProjectSettings.get_custom_nodes_path(), tree_dictionary) + tree_dictionary = _populate_dict_with_files( + GaeaProjectSettings.get_custom_nodes_path(), tree_dictionary + ) _populate_from_dictionary(tree_dictionary, root) root.set_collapsed_recursive(true) root.set_collapsed(false) @@ -81,7 +80,6 @@ func _populate_dict_with_files(folder_path: String, dict: Dictionary) -> Diction if dir.current_is_dir(): _populate_dict_with_files(file_path + "/", dict.get_or_add(tree_name, {})) - if file_name.ends_with(".gd"): var script := load(file_path) if script is GDScript: @@ -122,10 +120,13 @@ func _on_create_button_pressed() -> void: func _on_item_selected() -> void: var item: TreeItem = get_selected() if item.get_metadata(0) is GaeaNodeResource: - description_label.set_text(GaeaNodeResource.get_formatted_text(item.get_metadata(0).get_description())) + description_label.set_text( + GaeaNodeResource.get_formatted_text(item.get_metadata(0).get_description()) + ) elif item.get_metadata(0) is StringName: match item.get_metadata(0): - &"frame": description_label.set_text("A rectangular area for better organziation.") + &"frame": + description_label.set_text("A rectangular area for better organziation.") func _on_nothing_selected() -> void: @@ -170,7 +171,9 @@ func _select_next_visible(from: TreeItem, direction: int = 1) -> void: if not is_instance_valid(from): return - var item: TreeItem = (from.get_next_visible(true) if direction == 1 else from.get_prev_visible(true)) + var item: TreeItem = ( + from.get_next_visible(true) if direction == 1 else from.get_prev_visible(true) + ) if not is_instance_valid(item): return diff --git a/addons/gaea/editor/editor_settings.gd b/addons/gaea/editor/editor_settings.gd index f06224674..1c2ed5ff1 100644 --- a/addons/gaea/editor/editor_settings.gd +++ b/addons/gaea/editor/editor_settings.gd @@ -2,6 +2,7 @@ class_name GaeaEditorSettings extends RefCounted +const CIRCLE := preload("res://addons/gaea/assets/slots/circle.svg") const LINE_CURVATURE := "gaea/graph/line_curvature" const LINE_THICKNESS := "gaea/graph/line_thickness" @@ -60,27 +61,24 @@ func add_settings() -> void: "type": TYPE_INT }) - _add_setting(OUTPUT_TITLE_COLOR, Color("632639"), {"type": TYPE_COLOR, "hint": PROPERTY_HINT_COLOR_NO_ALPHA}) + _add_setting( + OUTPUT_TITLE_COLOR, + Color("632639"), + {"type": TYPE_COLOR, "hint": PROPERTY_HINT_COLOR_NO_ALPHA} + ) for slot_type: GaeaValue.Type in CONFIGURABLE_SLOT_COLORS.keys(): _add_setting( COLOR_BASE % CONFIGURABLE_SLOT_COLORS.get(slot_type), GaeaValue.get_default_color(slot_type), - { - "type": TYPE_COLOR, - "hint": PROPERTY_HINT_COLOR_NO_ALPHA - } + {"type": TYPE_COLOR, "hint": PROPERTY_HINT_COLOR_NO_ALPHA} ) for slot_type: GaeaValue.Type in CONFIGURABLE_SLOT_COLORS.keys(): _add_setting( ICON_BASE % CONFIGURABLE_SLOT_COLORS.get(slot_type), GaeaValue.get_default_slot_icon(slot_type).resource_path, - { - "type": TYPE_STRING, - "hint": PROPERTY_HINT_FILE, - "hint_string": "*.png,*.jpg,*.svg" - } + {"type": TYPE_STRING, "hint": PROPERTY_HINT_FILE, "hint_string": "*.png,*.jpg,*.svg"} ) @@ -110,7 +108,7 @@ static func get_configured_color_for_value_type(value_type: GaeaValue.Type) -> C static func get_configured_icon_for_value_type(value_type: GaeaValue.Type) -> Texture: if not CONFIGURABLE_SLOT_COLORS.has(value_type): - return preload("res://addons/gaea/assets/slots/circle.svg") + return CIRCLE var editor_interface = Engine.get_singleton("EditorInterface") var settings = editor_interface.get_editor_settings() var setting_path = ICON_BASE % CONFIGURABLE_SLOT_COLORS.get(value_type) @@ -118,7 +116,7 @@ static func get_configured_icon_for_value_type(value_type: GaeaValue.Type) -> Te var loaded: Object = load(settings.get_setting(setting_path)) if loaded is Texture: return loaded - return preload("res://addons/gaea/assets/slots/circle.svg") + return CIRCLE static func get_line_curvature() -> float: diff --git a/addons/gaea/editor/gradient_visualizer.gd b/addons/gaea/editor/gradient_visualizer.gd index 8e93a110c..6dc0b6385 100644 --- a/addons/gaea/editor/gradient_visualizer.gd +++ b/addons/gaea/editor/gradient_visualizer.gd @@ -1,7 +1,6 @@ @tool extends TextureRect - const SIZE = Vector2i(128, 32) const CHECKERBOARD_SIZE = Vector2i(16, 16) @@ -20,10 +19,8 @@ func update() -> void: var image: Image = Image.create_empty(SIZE.x, SIZE.y, false, Image.FORMAT_RGB8) for x in roundi(float(SIZE.x) / CHECKERBOARD_SIZE.x): for y in roundi(float(SIZE.y) / CHECKERBOARD_SIZE.y): - image.fill_rect(Rect2i( - Vector2i(x, y) * CHECKERBOARD_SIZE, - CHECKERBOARD_SIZE - ), + image.fill_rect( + Rect2i(Vector2i(x, y) * CHECKERBOARD_SIZE, CHECKERBOARD_SIZE), Color.GRAY if (x % 2 == y % 2) else Color.DIM_GRAY ) @@ -37,12 +34,18 @@ func update() -> void: var gaea_material: GaeaMaterial = gradient.points.get(idx).get(&"material", null) if not is_instance_valid(gaea_material): continue - var color: Color = Color.TRANSPARENT if not is_instance_valid(gaea_material) else gaea_material.preview_color - - image.fill_rect(Rect2( + var color: Color = ( + Color.TRANSPARENT + if not is_instance_valid(gaea_material) + else gaea_material.preview_color + ) + + image.fill_rect( + Rect2( Vector2(start_offset * SIZE.x, 0.0).round(), Vector2(((end_offset + 0.005) - start_offset) * SIZE.x, SIZE.y).round() ), - color) + color + ) texture = ImageTexture.create_from_image(image) diff --git a/addons/gaea/editor/graph_edit.gd b/addons/gaea/editor/graph_edit.gd index a092b4ab4..4f561f98a 100644 --- a/addons/gaea/editor/graph_edit.gd +++ b/addons/gaea/editor/graph_edit.gd @@ -1,12 +1,12 @@ @tool extends GraphEdit - signal connection_update_requested var attached_elements: Dictionary var generator: GaeaGenerator + func _init() -> void: for cast in GaeaValueCast.get_cast_list(): add_valid_connection_type(cast[0], cast[1]) @@ -31,8 +31,12 @@ func delete_nodes(nodes: Array[StringName]) -> void: continue for connection in node.connections: - disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port) - + disconnect_node( + connection.from_node, + connection.from_port, + connection.to_node, + connection.to_port + ) node.removed.emit() generator.data.remove_node(node.resource.id) elif node is GaeaGraphFrame: @@ -45,7 +49,9 @@ func delete_nodes(nodes: Array[StringName]) -> void: connection_update_requested.emit() -func _on_connection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void: +func _on_connection_request( + from_node: StringName, from_port: int, to_node: StringName, to_port: int +) -> void: if is_nodes_connected_relatively(from_node, to_node): return @@ -94,7 +100,9 @@ func _on_connection_request(from_node: StringName, from_port: int, to_node: Stri to_graph_node.notify_connections_updated.call_deferred() -func _on_disconnection_request(from_node: StringName, from_port: int, to_node: StringName, to_port: int) -> void: +func _on_disconnection_request( + from_node: StringName, from_port: int, to_node: StringName, to_port: int +) -> void: disconnect_node(from_node, from_port, to_node, to_port) connection_update_requested.emit() @@ -109,28 +117,40 @@ func _on_disconnection_request(from_node: StringName, from_port: int, to_node: S to_graph_node.notify_connections_updated.call_deferred() + func remove_invalid_connections() -> void: for connection in get_connection_list(): var to_node: GaeaGraphNode = get_node(NodePath(connection.to_node)) var from_node: GaeaGraphNode = get_node(NodePath(connection.from_node)) - if not is_instance_valid(from_node) or not is_instance_valid(to_node): - disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port) + disconnect_node( + connection.from_node, connection.from_port, connection.to_node, connection.to_port + ) continue if to_node.get_input_port_count() <= connection.to_port: - disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port) + disconnect_node( + connection.from_node, connection.from_port, connection.to_node, connection.to_port + ) continue if from_node.get_output_port_count() <= connection.from_port: - disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port) + disconnect_node( + connection.from_node, connection.from_port, connection.to_node, connection.to_port + ) continue - var from_type: GaeaValue.Type = from_node.get_output_port_type(connection.from_port) as GaeaValue.Type - var to_type: GaeaValue.Type = to_node.get_input_port_type(connection.to_port) as GaeaValue.Type + var from_type: GaeaValue.Type = ( + from_node.get_output_port_type(connection.from_port) as GaeaValue.Type + ) + var to_type: GaeaValue.Type = ( + to_node.get_input_port_type(connection.to_port) as GaeaValue.Type + ) if not is_valid_connection_type(from_type, to_type) and from_type != to_type: - disconnect_node(connection.from_node, connection.from_port, connection.to_node, connection.to_port) + disconnect_node( + connection.from_node, connection.from_port, connection.to_node, connection.to_port + ) to_node.notify_connections_updated.call_deferred() from_node.notify_connections_updated.call_deferred() continue @@ -148,9 +168,10 @@ func is_nodes_connected_relatively(from_node: StringName, to_node: StringName) - return true return false + func get_selected() -> Array: - return get_children().filter(func(child: Node) -> bool: - return child is GraphElement and child.selected + return get_children().filter( + func(child: Node) -> bool: return child is GraphElement and child.selected ) @@ -189,7 +210,9 @@ func _on_element_attached_to_frame(element: StringName, frame: StringName) -> vo generator.data.attach_node_to_frame(node.id, frame_node.id) -func _is_node_hover_valid(from_node: StringName, _from_port: int, to_node: StringName, _to_port: int) -> bool: +func _is_node_hover_valid( + from_node: StringName, _from_port: int, to_node: StringName, _to_port: int +) -> bool: if from_node == to_node: return false return true @@ -197,13 +220,15 @@ func _is_node_hover_valid(from_node: StringName, _from_port: int, to_node: Strin ## This function converts a local position to a grid position based on the current zoom level and scroll offset. ## It also applies snapping if enabled in the GraphEdit. -func local_to_grid(local_position: Vector2, grid_offset: Vector2 = Vector2.ZERO, enable_snapping: bool = true) -> Vector2: +func local_to_grid( + local_position: Vector2, grid_offset: Vector2 = Vector2.ZERO, enable_snapping: bool = true +) -> Vector2: local_position = (local_position + scroll_offset) / zoom local_position += grid_offset if enable_snapping and snapping_enabled: return local_position.snapped(Vector2.ONE * snapping_distance) - else: - return local_position + + return local_position func _on_editor_script_changed(script: Script): diff --git a/addons/gaea/editor/inspector_plugin.gd b/addons/gaea/editor/inspector_plugin.gd index c0494f659..4e00cc384 100644 --- a/addons/gaea/editor/inspector_plugin.gd +++ b/addons/gaea/editor/inspector_plugin.gd @@ -1,6 +1,5 @@ extends EditorInspectorPlugin - const GradientVisualizer = preload("res://addons/gaea/editor/gradient_visualizer.gd") diff --git a/addons/gaea/editor/link_popup.gd b/addons/gaea/editor/link_popup.gd index d818c8bb0..187912187 100644 --- a/addons/gaea/editor/link_popup.gd +++ b/addons/gaea/editor/link_popup.gd @@ -1,17 +1,14 @@ @tool extends PopupMenu -enum Action { - DISCONNECT, - INSERT_NEW_REROUTE -} +signal new_reroute_requested(connection: Dictionary) + +enum Action { DISCONNECT, INSERT_NEW_REROUTE } @export var graph_edit: GraphEdit var current_connection: Dictionary -signal new_reroute_requested(connection: Dictionary) - func _ready() -> void: if is_part_of_edited_scene(): @@ -26,6 +23,7 @@ func populate(connection: Dictionary) -> void: add_item("Insert New Reroute", Action.INSERT_NEW_REROUTE) size = get_contents_minimum_size() + func _on_id_pressed(id: int) -> void: match id: Action.DISCONNECT: diff --git a/addons/gaea/editor/node_popup.gd b/addons/gaea/editor/node_popup.gd index 20940c780..d1d6150c0 100644 --- a/addons/gaea/editor/node_popup.gd +++ b/addons/gaea/editor/node_popup.gd @@ -1,6 +1,7 @@ @tool extends PopupMenu +signal create_node_popup_requested enum Action { ADD, @@ -16,8 +17,6 @@ enum Action { @export var panel: Control @export var graph_edit: GraphEdit -signal create_node_popup_requested - func _ready() -> void: if is_part_of_edited_scene(): @@ -43,7 +42,9 @@ func populate(selected: Array) -> void: set_item_disabled(get_item_index(Action.TINT), not selected.front().tint_color_enabled) set_item_checked(get_item_index(Action.ENABLE_TINT), selected.front().tint_color_enabled) - set_item_checked(get_item_index(Action.ENABLE_AUTO_SHRINK), selected.front().autoshrink_enabled) + set_item_checked( + get_item_index(Action.ENABLE_AUTO_SHRINK), selected.front().autoshrink_enabled + ) size = get_contents_minimum_size() if selected.front() is GaeaGraphNode and selected.size() == 1: var node: GaeaGraphNode = selected.front() diff --git a/addons/gaea/editor/panel.gd b/addons/gaea/editor/panel.gd index 13c43d915..998c10579 100644 --- a/addons/gaea/editor/panel.gd +++ b/addons/gaea/editor/panel.gd @@ -1,15 +1,17 @@ @tool extends Control -const _LinkPopup = preload("uid://btt4eqjkp5pyf") +const LinkPopup = preload("uid://btt4eqjkp5pyf") -var _selected_generator: GaeaGenerator = null: get = get_selected_generator -var _output_node: GaeaGraphNode var is_loading = false +var plugin: EditorPlugin + +var _selected_generator: GaeaGenerator = null: + get = get_selected_generator +var _output_node: GaeaGraphNode ## Local position on [GraphEdit] for a node that may be created in the future. var _node_creation_target: Vector2 = Vector2.ZERO -var plugin: EditorPlugin @onready var _no_data: Control = $NoData @onready var _editor: Control = $Editor @@ -17,7 +19,7 @@ var plugin: EditorPlugin @onready var _create_node_popup: Window = %CreateNodePopup @onready var _create_node_panel: Panel = %CreateNodePanel @onready var _node_popup: PopupMenu = %NodePopup -@onready var _link_popup: _LinkPopup = %LinkPopup +@onready var _link_popup: LinkPopup = %LinkPopup @onready var _create_node_tree: Tree = %CreateNodeTree @onready var _search_bar: LineEdit = %SearchBar @onready var _save_button: Button = %SaveButton @@ -46,10 +48,18 @@ func _ready() -> void: _reload_parameters_list_button.icon = preload("../assets/reload_variables_list.svg") _save_button.icon = EditorInterface.get_base_control().get_theme_icon(&"Save", &"EditorIcons") _load_button.icon = EditorInterface.get_base_control().get_theme_icon(&"Load", &"EditorIcons") - _window_popout_button.icon = EditorInterface.get_base_control().get_theme_icon(&"MakeFloating", &"EditorIcons") - _online_docs_button.icon = EditorInterface.get_base_control().get_theme_icon(&"ExternalLink", &"EditorIcons") - _create_node_panel.add_theme_stylebox_override(&"panel", EditorInterface.get_base_control().get_theme_stylebox(&"panel", &"PopupPanel")) - _about_button.icon = EditorInterface.get_base_control().get_theme_icon(&"NodeInfo", &"EditorIcons") + _window_popout_button.icon = EditorInterface.get_base_control().get_theme_icon( + &"MakeFloating", &"EditorIcons" + ) + _online_docs_button.icon = EditorInterface.get_base_control().get_theme_icon( + &"ExternalLink", &"EditorIcons" + ) + _create_node_panel.add_theme_stylebox_override( + &"panel", EditorInterface.get_base_control().get_theme_stylebox(&"panel", &"PopupPanel") + ) + _about_button.icon = EditorInterface.get_base_control().get_theme_icon( + &"NodeInfo", &"EditorIcons" + ) _about_button.pressed.connect(_about_window.popup_centered) _about_window.plugin = plugin _about_window.initialize() @@ -83,11 +93,11 @@ func _on_graph_edit_gui_input(event: InputEvent) -> void: _popup_link_context_menu_at_mouse(connection) return - var _selected: Array = _graph_edit.get_selected() - if _selected.is_empty(): + var selected: Array = _graph_edit.get_selected() + if selected.is_empty(): _popup_create_node_menu_at_mouse() else: - _popup_node_context_menu_at_mouse(_selected) + _popup_node_context_menu_at_mouse(selected) func _on_visibility_changed() -> void: @@ -96,6 +106,7 @@ func _on_visibility_changed() -> void: _graph_edit.set_connection_lines_thickness(GaeaEditorSettings.get_line_thickness()) _graph_edit.set_minimap_opacity(GaeaEditorSettings.get_minimap_opacity()) + #endregion @@ -105,7 +116,10 @@ func populate(node: GaeaGenerator) -> void: await _remove_children() _output_node = null - if is_instance_valid(_selected_generator) and _selected_generator.data_changed.is_connected(_on_data_changed): + if ( + is_instance_valid(_selected_generator) + and _selected_generator.data_changed.is_connected(_on_data_changed) + ): _selected_generator.data_changed.disconnect(_on_data_changed) _selected_generator = node @@ -127,7 +141,10 @@ func populate(node: GaeaGenerator) -> void: func unpopulate() -> void: if is_instance_valid(_selected_generator): - if is_instance_valid(_selected_generator.data) and _selected_generator.data.layer_count_modified.is_connected(_update_output_node): + if ( + is_instance_valid(_selected_generator.data) + and _selected_generator.data.layer_count_modified.is_connected(_update_output_node) + ): _selected_generator.data.layer_count_modified.disconnect(_update_output_node) if _selected_generator.data_changed.is_connected(_on_data_changed): _selected_generator.data_changed.disconnect(_on_data_changed) @@ -165,21 +182,20 @@ func _load_data() -> void: has_output_node = true _output_node = node - if not has_output_node: _output_node = _add_node(GaeaNodeOutput.new(), Vector2.ZERO) _load_scroll_offset.call_deferred( _output_node.size * 0.5 - _graph_edit.get_rect().size * 0.5 ) - + # from_node and to_node are indexes in the resources array _load_connections.call_deferred(_selected_generator.data.get_all_connections()) update_connections() set_deferred(&"is_loading", false) - - + + func _load_scroll_offset(default_offset: Vector2) -> void: if is_nan(_selected_generator.data.scroll_offset.x): _selected_generator.data.scroll_offset = default_offset @@ -195,7 +211,9 @@ func _load_connections(connections: Array[Dictionary]) -> void: continue if to_node.get_input_port_count() <= connection.to_port: continue - _graph_edit.connection_request.emit(from_node.name, connection.from_port, to_node.name, connection.to_port) + _graph_edit.connection_request.emit( + from_node.name, connection.from_port, to_node.name, connection.to_port + ) func _load_frame(frame_data: Dictionary) -> GaeaGraphFrame: @@ -228,12 +246,12 @@ func _load_attached_elements(attached: Array, frame_name: StringName) -> void: var node_resource: GaeaNodeResource = _selected_generator.data.get_node(id) var node: GraphElement if not is_instance_valid(node_resource): - var _graph_children := _graph_edit.get_children() - var _attached_frame_idx := _graph_children.find_custom( + var graph_children := _graph_edit.get_children() + var attached_frame_idx := graph_children.find_custom( func(child: Node) -> bool: return child is GaeaGraphFrame and child.id == id ) - if _attached_frame_idx != -1: - node = _graph_children[_attached_frame_idx] + if attached_frame_idx != -1: + node = graph_children[attached_frame_idx] else: node = node_resource.node @@ -252,6 +270,8 @@ func _on_new_data_button_pressed() -> void: func _on_data_changed() -> void: populate(_selected_generator) + + #endregion @@ -327,25 +347,48 @@ func _on_new_reroute_requested(connection: Dictionary) -> void: resource.type = from_node.get_output_port_type(connection.from_port) as GaeaValue.Type var reroute: GaeaGraphNode = _add_node(resource, Vector2.ZERO) - var offset = - reroute.get_output_port_position(0) + var offset = -reroute.get_output_port_position(0) offset.y -= reroute.get_slot_custom_icon_right(0).get_size().y * 0.5 reroute.set_position_offset(_graph_edit.local_to_grid(_node_creation_target, offset)) _selected_generator.data.set_node_position(reroute.resource.id, reroute.position_offset) - _graph_edit.disconnection_request.emit.call_deferred( - connection.from_node, connection.from_port, - connection.to_node, connection.to_port, + ( + _graph_edit + .disconnection_request + .emit + .call_deferred( + connection.from_node, + connection.from_port, + connection.to_node, + connection.to_port, + ) ) - _graph_edit.connection_request.emit.call_deferred( - connection.from_node, connection.from_port, - reroute.name, 0, + ( + _graph_edit + .connection_request + .emit + .call_deferred( + connection.from_node, + connection.from_port, + reroute.name, + 0, + ) ) - _graph_edit.connection_request.emit.call_deferred( - reroute.name, 0, - connection.to_node, connection.to_port, + ( + _graph_edit + .connection_request + .emit + .call_deferred( + reroute.name, + 0, + connection.to_node, + connection.to_port, + ) ) + + #endregion @@ -367,6 +410,8 @@ func _popup_link_context_menu_at_mouse(connection: Dictionary) -> void: if not EditorInterface.get_editor_settings().get_setting("interface/editor/single_window_mode"): _link_popup.position += get_window().position _link_popup.popup() + + #endregion @@ -376,6 +421,8 @@ func _update_output_node() -> void: await _output_node.update_slots() await get_tree().process_frame _graph_edit.remove_invalid_connections() + + #endregion @@ -392,8 +439,12 @@ func update_connections() -> void: to_node.connections.append(connection) -func _on_graph_edit_connection_to_empty(_from_node: StringName, _from_port: int, _release_position: Vector2) -> void: +func _on_graph_edit_connection_to_empty( + _from_node: StringName, _from_port: int, _release_position: Vector2 +) -> void: _popup_create_node_menu_at_mouse() + + #endregion @@ -414,7 +465,10 @@ func _on_file_dialog_file_selected(path: String) -> void: func _on_reload_parameters_list_button_pressed() -> void: - if not is_instance_valid(_selected_generator) or not is_instance_valid(_selected_generator.data): + if ( + not is_instance_valid(_selected_generator) + or not is_instance_valid(_selected_generator.data) + ): return var existing_parameters: Array[String] @@ -478,13 +532,23 @@ func _on_window_popout_button_pressed() -> void: func _get_multiwindow_support_tooltip_text() -> String: # Adapted from https://github.com/godotengine/godot/blob/a8598cd8e261716fa3addb6f10bb57c03a061be9/editor/editor_node.cpp#L4725-L4737 if EditorInterface.get_editor_settings().get_setting("interface/editor/single_window_mode"): - return tr("Multi-window support is not available because Interface > Editor > Single Window Mode is enabled in the editor settings.") - elif not EditorInterface.get_editor_settings().get_setting("interface/multi_window/enable"): - return tr("Multi-window support is not available because Interface > Multi Window > Enable is disabled in the editor settings.") - elif DisplayServer.has_feature(DisplayServer.FEATURE_SUBWINDOWS): - return tr("Multi-window support is not available because the `--single-window` command line argument was used to start the editor.") - else: - return tr("Multi-window support is not available because the current platform doesn't support multiple windows.") + return tr( + "Multi-window support is not available because Interface > Editor > Single Window Mode is enabled in the editor settings." + ) + + if not EditorInterface.get_editor_settings().get_setting("interface/multi_window/enable"): + return tr( + "Multi-window support is not available because Interface > Multi Window > Enable is disabled in the editor settings." + ) + + if DisplayServer.has_feature(DisplayServer.FEATURE_SUBWINDOWS): + return tr( + "Multi-window support is not available because the `--single-window` command line argument was used to start the editor." + ) + + return tr( + "Multi-window support is not available because the current platform doesn't support multiple windows." + ) func _on_window_close_requested(original_parent: Control, window: Window) -> void: @@ -492,6 +556,8 @@ func _on_window_close_requested(original_parent: Control, window: Window) -> voi window.queue_free() _window_popout_button.show() _window_popout_separator.show() + + #endregion #endregion @@ -505,18 +571,27 @@ func update_bottom_note(): var mouse_position = _graph_edit.get_local_mouse_position() if get_rect().has_point(mouse_position): _bottom_note_label.visible = true - _bottom_note_label.text = "%s" % [ - Vector2i(_graph_edit.local_to_grid(_graph_edit.get_local_mouse_position(), Vector2.ZERO, false)) - ] + _bottom_note_label.text = ( + "%s" + % [ + Vector2i( + _graph_edit.local_to_grid( + _graph_edit.get_local_mouse_position(), Vector2.ZERO, false + ) + ) + ] + ) else: _bottom_note_label.visible = false + + #endregion func _on_graph_edit_scroll_offset_changed(offset: Vector2) -> void: if is_loading: return - + if is_instance_valid(_selected_generator): if is_instance_valid(_selected_generator.data): _selected_generator.data.scroll_offset = offset diff --git a/addons/gaea/editor/project_settings.gd b/addons/gaea/editor/project_settings.gd index b3341e6c5..818cb08db 100644 --- a/addons/gaea/editor/project_settings.gd +++ b/addons/gaea/editor/project_settings.gd @@ -2,7 +2,6 @@ class_name GaeaProjectSettings extends RefCounted - const CUSTOM_NODES_PATH := "gaea/nodes/custom_nodes_path" diff --git a/addons/gaea/editor/range_slider.gd b/addons/gaea/editor/range_slider.gd index 045282c4e..24bdd23b4 100644 --- a/addons/gaea/editor/range_slider.gd +++ b/addons/gaea/editor/range_slider.gd @@ -111,11 +111,10 @@ func _get_minimum_size() -> Vector2: maxi(slider_min_size.y, maxi(grabber_size_low.y, grabber_size_high.y)), ) - else: - return Vector2i( - maxi(slider_min_size.x, maxi(grabber_size_low.x, grabber_size_high.x)), - maxi(slider_min_size.y, grabber_size_low.y + grabber_size_high.y), - ) + return Vector2i( + maxi(slider_min_size.x, maxi(grabber_size_low.x, grabber_size_high.x)), + maxi(slider_min_size.y, grabber_size_low.y + grabber_size_high.y), + ) func _draw() -> void: @@ -402,15 +401,15 @@ func _update_theme_cache() -> void: func _theme_icon_get_or_fallback(icon_name: StringName, theme_type: StringName, theme_type_fallback: StringName) -> Texture2D: if has_theme_icon(name, theme_type): return get_theme_icon(icon_name, theme_type) - else: - return get_theme_icon(icon_name, theme_type_fallback) + + return get_theme_icon(icon_name, theme_type_fallback) func _theme_stylebox_get_or_fallback(icon_name: StringName, theme_type: StringName, theme_type_fallback: StringName) -> StyleBox: if has_theme_stylebox(name, theme_type): return get_theme_stylebox(icon_name, theme_type) - else: - return get_theme_stylebox(icon_name, theme_type_fallback) + + return get_theme_stylebox(icon_name, theme_type_fallback) func _set_bounds(low: float, high: float) -> void: @@ -448,18 +447,20 @@ func _get_grabber_icon(element: Element) -> Texture2D: Element.GRABBER_LOW: if not editable: return _theme_cache.grabber_icon_low_disabled - elif _highlight_element == Element.GRABBER_LOW: + + if _highlight_element == Element.GRABBER_LOW: return _theme_cache.grabber_icon_low_highlight - else: - return _theme_cache.grabber_icon_low + + return _theme_cache.grabber_icon_low Element.GRABBER_HIGH: if not editable: return _theme_cache.grabber_icon_high_disabled - elif _highlight_element == Element.GRABBER_HIGH: + + if _highlight_element == Element.GRABBER_HIGH: return _theme_cache.grabber_icon_high_highlight - else: - return _theme_cache.grabber_icon_high + + return _theme_cache.grabber_icon_high return null @@ -467,8 +468,8 @@ func _get_grabber_icon(element: Element) -> Texture2D: func _get_grabber_area_style() -> StyleBox: if _highlight_element == Element.GRABBER_AREA: return _theme_cache.grabber_area_highlight - else: - return _theme_cache.grabber_area + + return _theme_cache.grabber_area func _get_grabber_rect(element: Element) -> Rect2i: @@ -590,7 +591,7 @@ func _get_element_at_point(point: Vector2) -> Element: return Element.GRABBER_LOW - elif grabber_rect_high.has_point(point): + if grabber_rect_high.has_point(point): var rect := Rect2(_get_grabber_rect(Element.GRABBER_HIGH)) match _orientation: @@ -604,7 +605,7 @@ func _get_element_at_point(point: Vector2) -> Element: return Element.GRABBER_HIGH - elif range_rect.has_point(point): + if range_rect.has_point(point): var rect := Rect2(_get_grabber_rect(Element.GRABBER_LOW)) _drag_range = end_value - start_value diff --git a/addons/gaea/gaea.gd b/addons/gaea/gaea.gd index 92c18c928..39173d4f0 100644 --- a/addons/gaea/gaea.gd +++ b/addons/gaea/gaea.gd @@ -44,18 +44,18 @@ func _exit_tree() -> void: func _get_unsaved_status(for_scene): if for_scene.is_empty(): return "Save changes in Gaea before closing?" - else: - return "Scene %s has changes from Gaea. Save before closing?" % for_scene.get_file() + + return "Scene %s has changes from Gaea. Save before closing?" % for_scene.get_file() func _on_selection_changed() -> void: if Engine.is_editor_hint(): - var _selected: Array[Node] = _editor_selection.get_selected_nodes() + var selected: Array[Node] = _editor_selection.get_selected_nodes() - if _selected.size() == 1 and _selected.front() is GaeaGenerator: + if selected.size() == 1 and selected.front() is GaeaGenerator: _panel_button.show() make_bottom_panel_item_visible(_container) - _panel.populate(_selected.front()) + _panel.populate(selected.front()) else: if is_instance_valid(_panel.get_selected_generator()): _panel_button.hide() diff --git a/addons/gaea/graph/components/argument_editors/argument_editor.gd b/addons/gaea/graph/components/argument_editors/argument_editor.gd index 4f5f36cc2..a2cd12c70 100644 --- a/addons/gaea/graph/components/argument_editors/argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/argument_editor.gd @@ -23,7 +23,13 @@ var hint: Dictionary[String, Variant] ## Sets the corresponding variables. -func initialize(for_graph_node: GaeaGraphNode, for_type: GaeaValue.Type, display_name: String, default_value: Variant, for_hint: Dictionary) -> void: +func initialize( + for_graph_node: GaeaGraphNode, + for_type: GaeaValue.Type, + display_name: String, + default_value: Variant, + for_hint: Dictionary +) -> void: graph_node = for_graph_node type = for_type set_label_text(display_name) diff --git a/addons/gaea/graph/components/argument_editors/bitmask_argument_editor.gd b/addons/gaea/graph/components/argument_editors/bitmask_argument_editor.gd index 2bfffd191..ccfd6987e 100644 --- a/addons/gaea/graph/components/argument_editors/bitmask_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/bitmask_argument_editor.gd @@ -1,6 +1,6 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaBitsArgumentEditor +extends GaeaGraphNodeArgumentEditor @onready var grid_container: GridContainer = $GridContainer @onready var drop_button: TextureButton = $DropButton @@ -9,7 +9,7 @@ class_name GaeaBitsArgumentEditor func _configure() -> void: if is_part_of_edited_scene(): return - await super () + await super() var button_group: ButtonGroup = ButtonGroup.new() for button: Button in grid_container.get_children(): button.text = str(button.get_index() + 1) @@ -21,7 +21,9 @@ func _configure() -> void: button.toggled.connect(_on_value_changed.unbind(1)) var editor_interface = Engine.get_singleton("EditorInterface") - drop_button.texture_normal = editor_interface.get_base_control().get_theme_icon(&"GuiOptionArrow", &"EditorIcons") + drop_button.texture_normal = editor_interface.get_base_control().get_theme_icon( + &"GuiOptionArrow", &"EditorIcons" + ) drop_button.toggled.connect(_on_drop_button_toggled) @@ -37,22 +39,22 @@ func _on_value_changed() -> void: func get_arg_value() -> Variant: - if super () != null: - return super () + if super() != null: + return super() - if type != GaeaValue.Type.FLAGS: - var num: int = 0 - for button: Button in grid_container.get_children(): - if button.button_pressed: - num |= 1 << button.get_index() - return num - else: + if type == GaeaValue.Type.FLAGS: var flags: Array[int] = [] for button: Button in grid_container.get_children(): if button.button_pressed: flags.append(1 << button.get_index()) return flags + var num: int = 0 + for button: Button in grid_container.get_children(): + if button.button_pressed: + num |= 1 << button.get_index() + return num + func set_arg_value(new_value: Variant) -> void: if type != GaeaValue.Type.FLAGS: diff --git a/addons/gaea/graph/components/argument_editors/boolean_argument_editor.gd b/addons/gaea/graph/components/argument_editors/boolean_argument_editor.gd index d9800d047..eadc8f1b7 100644 --- a/addons/gaea/graph/components/argument_editors/boolean_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/boolean_argument_editor.gd @@ -1,7 +1,6 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaBooleanArgumentEditor - +extends GaeaGraphNodeArgumentEditor @onready var check_box: CheckBox = $CheckBox diff --git a/addons/gaea/graph/components/argument_editors/neighbor_argument_editor.gd b/addons/gaea/graph/components/argument_editors/neighbor_argument_editor.gd index 4d8852eb1..32c84806b 100644 --- a/addons/gaea/graph/components/argument_editors/neighbor_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/neighbor_argument_editor.gd @@ -1,11 +1,18 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaNeighborArgumentEditor +extends GaeaGraphNodeArgumentEditor - -const DIRECTIONS = [Vector2i.UP + Vector2i.LEFT , Vector2i.UP , Vector2i.UP + Vector2i.RIGHT, - Vector2i.LEFT , Vector2i.ZERO , Vector2i.RIGHT, - Vector2i.DOWN + Vector2i.LEFT , Vector2i.DOWN , Vector2i.DOWN + Vector2i.RIGHT] +const DIRECTIONS = [ + Vector2i.UP + Vector2i.LEFT, + Vector2i.UP, + Vector2i.UP + Vector2i.RIGHT, + Vector2i.LEFT, + Vector2i.ZERO, + Vector2i.RIGHT, + Vector2i.DOWN + Vector2i.LEFT, + Vector2i.DOWN, + Vector2i.DOWN + Vector2i.RIGHT +] @onready var grid_container: GridContainer = $GridContainer diff --git a/addons/gaea/graph/components/argument_editors/number_argument_editor.gd b/addons/gaea/graph/components/argument_editors/number_argument_editor.gd index 3b91271a4..1c1202378 100644 --- a/addons/gaea/graph/components/argument_editors/number_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/number_argument_editor.gd @@ -1,7 +1,6 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaNumberArgumentEditor - +extends GaeaGraphNodeArgumentEditor @onready var spin_box: SpinBox = %SpinBox @onready var h_slider: HSlider = %HSlider @@ -10,7 +9,9 @@ class_name GaeaNumberArgumentEditor func _ready() -> void: if is_part_of_edited_scene(): return - h_slider.add_theme_icon_override(&"grabber", get_theme_icon(&"GuiScrollGrabberHl", &"EditorIcons")) + h_slider.add_theme_icon_override( + &"grabber", get_theme_icon(&"GuiScrollGrabberHl", &"EditorIcons") + ) func _configure() -> void: diff --git a/addons/gaea/graph/components/argument_editors/parameter_name_argument_editor.gd b/addons/gaea/graph/components/argument_editors/parameter_name_argument_editor.gd index 730163d39..1e877905d 100644 --- a/addons/gaea/graph/components/argument_editors/parameter_name_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/parameter_name_argument_editor.gd @@ -1,38 +1,37 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaParameterNameArgumentEditor +extends GaeaGraphNodeArgumentEditor - -@onready var name_label: Label = $NameLabel +@onready var _name_label: Label = $NameLabel @onready var _edit_button: Button = $EditButton func _configure() -> void: if is_part_of_edited_scene(): return - await super () + await super() var editor_interface = Engine.get_singleton("EditorInterface") _edit_button.icon = editor_interface.get_base_control().get_theme_icon(&"Edit", &"EditorIcons") func get_arg_value() -> String: - if super () != null: - return super () - return name_label.text + if super() != null: + return super() + return _name_label.text func set_arg_value(new_value: Variant) -> void: if typeof(new_value) not in [TYPE_STRING, TYPE_STRING_NAME]: return - name_label.text = new_value + _name_label.text = new_value func _on_edit_button_pressed() -> void: var line_edit: LineEdit = LineEdit.new() line_edit.select_all_on_focus = true - line_edit.text = name_label.text + line_edit.text = _name_label.text line_edit.expand_to_text_length = true line_edit.text_changed.connect(_on_line_edit_text_changed.bind(line_edit)) line_edit.text_submitted.connect(_on_line_edit_text_submitted.bind(line_edit)) @@ -44,14 +43,14 @@ func _on_edit_button_pressed() -> void: func _on_line_edit_text_changed(new_text: String, line_edit: LineEdit) -> void: var editor_interface = Engine.get_singleton("EditorInterface") - if (graph_node.generator.data.has_parameter(new_text) and new_text != name_label.text) or not new_text.is_valid_identifier(): + if (graph_node.generator.data.has_parameter(new_text) and new_text != _name_label.text) or not new_text.is_valid_identifier(): line_edit.add_theme_color_override(&"font_color", editor_interface.get_base_control().get_theme_color(&"error_color", &"Editor")) else: line_edit.remove_theme_color_override(&"font_color") func _on_line_edit_text_submitted(new_text: String, line_edit: LineEdit) -> void: - if new_text == name_label.text: + if new_text == _name_label.text: line_edit.queue_free() return @@ -63,7 +62,7 @@ func _on_line_edit_text_submitted(new_text: String, line_edit: LineEdit) -> void push_error("Parameter name '%s' matches an already existing parameter." % new_text) return - name_label.text = new_text + _name_label.text = new_text graph_node.auto_shrink.call_deferred() argument_value_changed.emit(new_text) line_edit.queue_free() diff --git a/addons/gaea/graph/components/argument_editors/range_argument_editor.gd b/addons/gaea/graph/components/argument_editors/range_argument_editor.gd index 3b34c0654..020667301 100644 --- a/addons/gaea/graph/components/argument_editors/range_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/range_argument_editor.gd @@ -1,12 +1,12 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaRangeArgumentEditor +extends GaeaGraphNodeArgumentEditor -@onready var min_spin_box: SpinBox = %MinSpinBox -@onready var max_spin_box: SpinBox = %MaxSpinBox -@onready var range_slider: Control = %RangeSlider +@onready var _min_spin_box: SpinBox = %MinSpinBox +@onready var _max_spin_box: SpinBox = %MaxSpinBox +@onready var _range_slider: Control = %RangeSlider @@ -18,24 +18,24 @@ func _configure() -> void: var range_max: float = hint.get("max", 1.0) var allow_lesser: bool = hint.get("allow_lesser", true) var allow_greater: bool = hint.get("allow_greater", true) - var step: float = hint.get("step", min_spin_box.step) + var step: float = hint.get("step", _min_spin_box.step) - range_slider.min_value = range_min - range_slider.max_value = range_max - range_slider.step = step + _range_slider.min_value = range_min + _range_slider.max_value = range_max + _range_slider.step = step - range_slider.allow_lesser = false - range_slider.allow_greater = false + _range_slider.allow_lesser = false + _range_slider.allow_greater = false - min_spin_box.suffix = hint.get("suffix", "") - max_spin_box.suffix = min_spin_box.suffix + _min_spin_box.suffix = hint.get("suffix", "") + _max_spin_box.suffix = _min_spin_box.suffix - min_spin_box.prefix = hint.get("prefix", "") - max_spin_box.prefix = min_spin_box.prefix + _min_spin_box.prefix = hint.get("prefix", "") + _max_spin_box.prefix = _min_spin_box.prefix - min_spin_box.value_changed.connect(_on_spin_box_changed_value.unbind(1)) - max_spin_box.value_changed.connect(_on_spin_box_changed_value.unbind(1)) + _min_spin_box.value_changed.connect(_on_spin_box_changed_value.unbind(1)) + _max_spin_box.value_changed.connect(_on_spin_box_changed_value.unbind(1)) _configure_min_max_spin_box(allow_lesser, allow_greater) @@ -43,52 +43,52 @@ func _configure() -> void: func _configure_min_max_spin_box(allow_lesser: int, allow_greater: int) -> void: - min_spin_box.min_value = range_slider.min_value - max_spin_box.min_value = range_slider.min_value - max_spin_box.max_value = range_slider.max_value - min_spin_box.max_value = range_slider.max_value + _min_spin_box.min_value = _range_slider.min_value + _max_spin_box.min_value = _range_slider.min_value + _max_spin_box.max_value = _range_slider.max_value + _min_spin_box.max_value = _range_slider.max_value - min_spin_box.step = range_slider.step - max_spin_box.step = range_slider.step + _min_spin_box.step = _range_slider.step + _max_spin_box.step = _range_slider.step - min_spin_box.allow_lesser = allow_lesser - min_spin_box.allow_greater = allow_greater - max_spin_box.allow_lesser = allow_lesser - max_spin_box.allow_greater = allow_greater + _min_spin_box.allow_lesser = allow_lesser + _min_spin_box.allow_greater = allow_greater + _max_spin_box.allow_lesser = allow_lesser + _max_spin_box.allow_greater = allow_greater func _on_spin_box_changed_value() -> void: - if min_spin_box.value > max_spin_box.value: - max_spin_box.set_value_no_signal(min_spin_box.value) - elif max_spin_box.value < min_spin_box.value: - min_spin_box.set_value_no_signal(max_spin_box.value) - - if max_spin_box.value > range_slider.max_value: - range_slider.max_value = max_spin_box.value - if min_spin_box.value < range_slider.min_value: - range_slider.min_value = min_spin_box.value - range_slider.set_range(min_spin_box.value, max_spin_box.value) + if _min_spin_box.value > _max_spin_box.value: + _max_spin_box.set_value_no_signal(_min_spin_box.value) + elif _max_spin_box.value < _min_spin_box.value: + _min_spin_box.set_value_no_signal(_max_spin_box.value) + + if _max_spin_box.value > _range_slider.max_value: + _range_slider.max_value = _max_spin_box.value + if _min_spin_box.value < _range_slider.min_value: + _range_slider.min_value = _min_spin_box.value + _range_slider.set_range(_min_spin_box.value, _max_spin_box.value) func get_arg_value() -> Dictionary: if super() != null: return super() return { - "min": range_slider.start_value, - "max": range_slider.end_value + "min": _range_slider.start_value, + "max": _range_slider.end_value } func set_arg_value(new_value: Variant) -> void: if typeof(new_value) != TYPE_DICTIONARY: return - min_spin_box.value = new_value.get("min", 0.0) - max_spin_box.value = new_value.get("max", 1.0) + _min_spin_box.value = new_value.get("min", 0.0) + _max_spin_box.value = new_value.get("max", 1.0) func _on_range_slider_value_changed(start_value: float, end_value: float) -> void: - min_spin_box.set_value_no_signal(start_value) - max_spin_box.set_value_no_signal(end_value) + _min_spin_box.set_value_no_signal(start_value) + _max_spin_box.set_value_no_signal(end_value) argument_value_changed.emit(get_arg_value()) diff --git a/addons/gaea/graph/components/argument_editors/rules_argument_editor.gd b/addons/gaea/graph/components/argument_editors/rules_argument_editor.gd index 5ca6d26dc..491859e27 100644 --- a/addons/gaea/graph/components/argument_editors/rules_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/rules_argument_editor.gd @@ -1,6 +1,6 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaRulesArgumentEditor +extends GaeaGraphNodeArgumentEditor @onready var grid_container: GridContainer = $GridContainer diff --git a/addons/gaea/graph/components/argument_editors/three_state_button.gd b/addons/gaea/graph/components/argument_editors/three_state_button.gd index dd62b2169..9ec6cb8d5 100644 --- a/addons/gaea/graph/components/argument_editors/three_state_button.gd +++ b/addons/gaea/graph/components/argument_editors/three_state_button.gd @@ -1,7 +1,6 @@ @tool extends CheckBox - const CHECK = preload("res://addons/gaea/assets/check.svg") const CROSS = preload("res://addons/gaea/assets/cross.svg") @@ -15,6 +14,7 @@ func _ready() -> void: return add_theme_icon_override("checked", get_theme_icon("unchecked")) + func _toggled(toggled_on: bool) -> void: texture_rect.set_visible.call_deferred(toggled_on) diff --git a/addons/gaea/graph/components/argument_editors/vector_argument_editor.gd b/addons/gaea/graph/components/argument_editors/vector_argument_editor.gd index 8f8997136..e9d02fac1 100644 --- a/addons/gaea/graph/components/argument_editors/vector_argument_editor.gd +++ b/addons/gaea/graph/components/argument_editors/vector_argument_editor.gd @@ -1,7 +1,10 @@ @tool -extends GaeaGraphNodeArgumentEditor class_name GaeaVector3ArgumentEditor +extends GaeaGraphNodeArgumentEditor +const VALID_TYPES := [ + GaeaValue.Type.VECTOR2, GaeaValue.Type.VECTOR2I, GaeaValue.Type.VECTOR3, GaeaValue.Type.VECTOR3I +] @onready var _x_spin_box: SpinBox = %XSpinBox @onready var _y_spin_box: SpinBox = %YSpinBox @@ -20,9 +23,18 @@ func _configure() -> void: _y_spin_box.value_changed.connect(_on_slider_changed_value.unbind(1)) _z_spin_box.value_changed.connect(_on_slider_changed_value.unbind(1)) var editor_interface = Engine.get_singleton("EditorInterface") - _x_label.add_theme_color_override(&"font_color", editor_interface.get_base_control().get_theme_color("property_color_x", "Editor")) - _y_label.add_theme_color_override(&"font_color", editor_interface.get_base_control().get_theme_color("property_color_y", "Editor")) - _z_label.add_theme_color_override(&"font_color", editor_interface.get_base_control().get_theme_color("property_color_z", "Editor")) + _x_label.add_theme_color_override( + &"font_color", + editor_interface.get_base_control().get_theme_color("property_color_x", "Editor") + ) + _y_label.add_theme_color_override( + &"font_color", + editor_interface.get_base_control().get_theme_color("property_color_y", "Editor") + ) + _z_label.add_theme_color_override( + &"font_color", + editor_interface.get_base_control().get_theme_color("property_color_z", "Editor") + ) if type == GaeaValue.Type.VECTOR2I or type == GaeaValue.Type.VECTOR3I: _x_spin_box.step = 1 @@ -69,8 +81,8 @@ func set_editor_visible(value: bool) -> void: func get_arg_value() -> Variant: - if super () != null: - return super () + if super() != null: + return super() match type: GaeaValue.Type.VECTOR2: return Vector2(_x_spin_box.value, _y_spin_box.value) @@ -85,12 +97,7 @@ func get_arg_value() -> Variant: func set_arg_value(new_value: Variant) -> void: var new_value_type = typeof(new_value) - if not typeof(new_value) in [ - GaeaValue.Type.VECTOR2, - GaeaValue.Type.VECTOR2I, - GaeaValue.Type.VECTOR3, - GaeaValue.Type.VECTOR3I - ]: + if not (typeof(new_value) in VALID_TYPES): return _x_spin_box.value = float(new_value.x) diff --git a/addons/gaea/graph/components/graph_node_output.gd b/addons/gaea/graph/components/graph_node_output.gd index 8bc38633d..1ee5b0425 100644 --- a/addons/gaea/graph/components/graph_node_output.gd +++ b/addons/gaea/graph/components/graph_node_output.gd @@ -3,20 +3,21 @@ class_name GaeaGraphNodeOutput extends MarginContainer ## An output slot inside a [GaeaGraphNode]. - ## Reference to the [GaeaGraphNode] instance var graph_node: GaeaGraphNode ## Index of the slot in the [GaeaGraphNode]. var idx: int var type: GaeaValue.Type - @onready var _label: RichTextLabel = %RightLabel -@onready var _toggle_preview_button: TextureButton = %TogglePreviewButton : get = get_toggle_preview_button +@onready var _toggle_preview_button: TextureButton = %TogglePreviewButton: + get = get_toggle_preview_button ## Sets the corresponding variables. -func initialize(for_graph_node: GaeaGraphNode, for_type: GaeaValue.Type, display_name: String) -> void: +func initialize( + for_graph_node: GaeaGraphNode, for_type: GaeaValue.Type, display_name: String +) -> void: graph_node = for_graph_node type = for_type _label.text = display_name diff --git a/addons/gaea/graph/components/preview_texture.gd b/addons/gaea/graph/components/preview_texture.gd index ee9e288b3..16eb52ae8 100644 --- a/addons/gaea/graph/components/preview_texture.gd +++ b/addons/gaea/graph/components/preview_texture.gd @@ -1,7 +1,6 @@ @tool extends TextureRect - const RESOLUTION: Vector2i = Vector2i(64, 64) var selected_output: StringName = &"" @@ -56,7 +55,9 @@ func _ready() -> void: func toggle(for_output: StringName) -> void: if not get_parent().visible: get_parent().show() - slider_container.visible = node.resource.get_output_port_type(for_output) == GaeaValue.Type.DATA + slider_container.visible = ( + node.resource.get_output_port_type(for_output) == GaeaValue.Type.DATA + ) selected_output = for_output update() else: @@ -95,7 +96,7 @@ func update() -> void: ).get("value", {}) node.generator.data.cache.clear() - + var sim_center:Vector3i = sim_size / 2 var res_center:Vector3i = Vector3i(resolution.x, resolution.y, 0) / 2 var sim_offset := sim_center.max(res_center) - sim_center.min(res_center) diff --git a/addons/gaea/graph/graph_nodes/generic_classes/constant.gd b/addons/gaea/graph/graph_nodes/generic_classes/constant.gd index dab512d98..f649a211e 100644 --- a/addons/gaea/graph/graph_nodes/generic_classes/constant.gd +++ b/addons/gaea/graph/graph_nodes/generic_classes/constant.gd @@ -1,7 +1,7 @@ @tool @abstract -extends GaeaNodeResource class_name GaeaNodeConstant +extends GaeaNodeResource ## Generic class for [b]TypeConstant[/b] nodes. See [enum GaeaValue.Type]. ## ## Accepts no inputs and has only one output, [param value]. diff --git a/addons/gaea/graph/graph_nodes/generic_classes/number_operation.gd b/addons/gaea/graph/graph_nodes/generic_classes/number_operation.gd index 8b48d7700..02ea63288 100644 --- a/addons/gaea/graph/graph_nodes/generic_classes/number_operation.gd +++ b/addons/gaea/graph/graph_nodes/generic_classes/number_operation.gd @@ -4,7 +4,6 @@ class_name GaeaNodeNumOp extends GaeaNodeResource ## Base class for operations between 2 numbers. - enum Operation { ADD, SUBTRACT, @@ -29,10 +28,12 @@ enum Operation { WRAP, } + class Definition: var args: Array[StringName] var output: String var conversion: Callable + func _init(_args: Array[StringName], _output: String, _conversion: Callable): args = _args output = _output @@ -40,7 +41,8 @@ class Definition: ## All possible operations. -var OPERATION_DEFINITIONS: Dictionary[Operation, Definition] : get = _get_operation_definitions +var operation_definitions: Dictionary[Operation, Definition]: + get = _get_operation_definitions func _get_description() -> String: @@ -66,7 +68,9 @@ func _get_description() -> String: Operation.SIGN: return "Returns [code]-1[/code] for negative numbers, [code]1[/code] for positive numbers and [code]0[/code] for zeroes." Operation.SMOOTHSTEP: - return "Returns [code]0[/code] if [param a] < [param from], [code]1[/code] if [param a] > [param to], otherwise returns an interpolated value between [code]0[/code] and [code]1[/code]." + return """Returns [code]0[/code] if [param a] < [param from], \ +[code]1[/code] if [param a] > [param to], \ +otherwise returns an interpolated value between [code]0[/code] and [code]1[/code].""" Operation.STEP: return "Returns [code]0[/code] if [param a] < [param edge], otherwise [code]1[/code]." Operation.WRAP: @@ -77,9 +81,12 @@ func _get_description() -> String: func _get_tree_items() -> Array[GaeaNodeResource]: var items: Array[GaeaNodeResource] items.append_array(super()) - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): var item: GaeaNodeResource = get_script().new() - item.set_tree_name_override("%s (%s)" % [Operation.find_key(operation).to_pascal_case(), OPERATION_DEFINITIONS[operation].output] ) + var operation_name: String = Operation.find_key(operation).to_pascal_case() + var output_name := operation_definitions[operation].output + var tree_name := "%s (%s)" % [operation_name, output_name] + item.set_tree_name_override(tree_name) item.set_default_enum_value_override(0, operation) items.append(item) @@ -93,14 +100,14 @@ func _get_enums_count() -> int: func _get_enum_options(_idx: int) -> Dictionary: var options: Dictionary = {} - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): options.set(Operation.find_key(operation), operation) return options func _get_arguments_list() -> Array[StringName]: - return OPERATION_DEFINITIONS.get(get_enum_selection(0)).args + return operation_definitions.get(get_enum_selection(0)).args func _get_argument_display_name(arg_name: StringName) -> String: @@ -111,7 +118,6 @@ func _get_argument_type(_arg_name: StringName) -> GaeaValue.Type: return get_type() - func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void: notify_argument_list_changed() @@ -121,27 +127,26 @@ func _get_output_ports_list() -> Array[StringName]: func _get_output_port_display_name(_output_name: StringName) -> String: - return OPERATION_DEFINITIONS[get_enum_selection(0)].output - + return operation_definitions[get_enum_selection(0)].output func _get_data(_output_port: StringName, _area: AABB, graph: GaeaGraph) -> Variant: var operation: Operation = get_enum_selection(0) as Operation var args: Array - for arg_name: StringName in OPERATION_DEFINITIONS[operation].args: + for arg_name: StringName in operation_definitions[operation].args: args.append(_get_arg(arg_name, _area, graph)) return _get_new_value(operation, args) func _get_new_value(operation: Operation, args: Array) -> Variant: - return OPERATION_DEFINITIONS[operation].conversion.callv(args) + return operation_definitions[operation].conversion.callv(args) func _get_operation_definitions() -> Dictionary[Operation, Definition]: - if not OPERATION_DEFINITIONS.is_empty(): - return OPERATION_DEFINITIONS + if not operation_definitions.is_empty(): + return operation_definitions - OPERATION_DEFINITIONS = { + operation_definitions = { Operation.ADD: Definition.new([&"a", &"b"], "a + b", func(a: Variant, b: Variant): return a + b), Operation.SUBTRACT: @@ -149,17 +154,21 @@ func _get_operation_definitions() -> Dictionary[Operation, Definition]: Operation.MULTIPLY: Definition.new([&"a", &"b"], "a * b", func(a: Variant, b: Variant): return a * b), Operation.DIVIDE: - Definition.new([&"a", &"b"], "a / b", func(a: Variant, b: Variant): return 0 if is_zero_approx(b) else a / b), + Definition.new( + [&"a", &"b"], + "a / b", + func(a: Variant, b: Variant): return 0 if is_zero_approx(b) else a / b + ), #Operation.REMAINDER: - #Definition.new([&"a", &"b"], "a % b", func(a: float, b: float): return 0.0 if is_zero_approx(b) else fmod(a, b)), + #Definition.new([&"a", &"b"], "a % b", func(a: float, b: float): return 0.0 if is_zero_approx(b) else fmod(a, b)), Operation.POWER: Definition.new([&"base", &"exp"], "base ** exp", pow), Operation.MAX: - Definition.new([&"a",&"b"], "max(a, b)", max), + Definition.new([&"a", &"b"], "max(a, b)", max), Operation.MIN: - Definition.new([&"a",&"b"], "min(a, b)", min), + Definition.new([&"a", &"b"], "min(a, b)", min), #Operation.SNAPPED: - #Definition.new([&"a", "Step"], "snapped(a, step)", snapped), + #Definition.new([&"a", "Step"], "snapped(a, step)", snapped), Operation.ABS: Definition.new([&"a"], "abs(a)", abs), Operation.CEIL: @@ -171,22 +180,22 @@ func _get_operation_definitions() -> Dictionary[Operation, Definition]: Operation.CLAMP: Definition.new([&"a", &"min", &"max"], "clamp(a, min, max)", clamp), #Operation.LERP: - #Definition.new([&"from", &"to", &"weight"], "lerpf(from, to, weight)", lerpf), + #Definition.new([&"from", &"to", &"weight"], "lerpf(from, to, weight)", lerpf), #Operation.LOG: - #Definition.new([&"a"], "log(a)", log), + #Definition.new([&"a"], "log(a)", log), Operation.REMAP: Definition.new( - [&"a", &"in_start", &"in_stop", &"out_start", &"out_stop"], - "remap(a, ...)", - remap + [&"a", &"in_start", &"in_stop", &"out_start", &"out_stop"], "remap(a, ...)", remap ), Operation.SIGN: Definition.new([&"a"], "sign(a)", sign), Operation.SMOOTHSTEP: Definition.new([&"from", &"to", &"a"], "smoothstep(from, to, a)", smoothstep), Operation.STEP: - Definition.new([&"a", &"edge"], "step(a, edge)", func(a, edge): return 0 if a < edge else 1), + Definition.new( + [&"a", &"edge"], "step(a, edge)", func(a, edge): return 0 if a < edge else 1 + ), Operation.WRAP: Definition.new([&"a", &"min", &"max"], "wrap(a, min, max)", wrap), } - return OPERATION_DEFINITIONS + return operation_definitions diff --git a/addons/gaea/graph/graph_nodes/generic_classes/parameter.gd b/addons/gaea/graph/graph_nodes/generic_classes/parameter.gd index 656c9506d..2ec660b0d 100644 --- a/addons/gaea/graph/graph_nodes/generic_classes/parameter.gd +++ b/addons/gaea/graph/graph_nodes/generic_classes/parameter.gd @@ -1,20 +1,22 @@ @tool @abstract -extends GaeaNodeResource class_name GaeaNodeParameter +extends GaeaNodeResource ## Generic class for [b]TypeParameter[/b] nodes. See [enum GaeaValue.Type]. ## ## Adds a variable of [member type], with [member hint] and [member hint_string], editable in the ## inspector, which can be accessed by other nodes through this node's output.[br] ## Parameters are added to the [member GaeaGraph._parameters] array. - ## See [enum Variant.Type] and equivalents in [method GaeaValue.from_variant_type]. -var type: int: get = _get_variant_type +var type: int: + get = _get_variant_type ## See [enum PropertyHint]. -var hint: PropertyHint: get = _get_property_hint +var hint: PropertyHint: + get = _get_property_hint ## See [enum PropertyHint]. -var hint_string: String: get = _get_property_hint_string +var hint_string: String: + get = _get_property_hint_string ## Override this method to determine the [enum Variant.Type] for the variable this node adds.[br][br] @@ -49,12 +51,12 @@ func _get_available_name(from: String) -> String: if not is_instance_valid(node): return "" - var _available_name: String = from - var _suffix: int = 1 - while node.generator.data.has_parameter(_available_name): - _suffix += 1 - _available_name = "%s%s" % [from, _suffix] - return _available_name + var available_name: String = from + var suffix: int = 1 + while node.generator.data.parameters.has(available_name): + suffix += 1 + available_name = "%s%s" % [from, suffix] + return available_name func _get_output_ports_list() -> Array[StringName]: @@ -66,7 +68,9 @@ func _get_overridden_output_port_idx(_output_name: StringName) -> int: func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: - return GaeaValue.from_variant_type(_get_variant_type(), _get_property_hint(), _get_property_hint_string()) + return GaeaValue.from_variant_type( + _get_variant_type(), _get_property_hint(), _get_property_hint_string() + ) func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Variant: diff --git a/addons/gaea/graph/graph_nodes/generic_classes/parameter_node.gd b/addons/gaea/graph/graph_nodes/generic_classes/parameter_node.gd index 9bd015937..66470f2d7 100644 --- a/addons/gaea/graph/graph_nodes/generic_classes/parameter_node.gd +++ b/addons/gaea/graph/graph_nodes/generic_classes/parameter_node.gd @@ -1,7 +1,6 @@ @tool extends GaeaGraphNode - var type: Variant.Type var hint: PropertyHint var hint_string: String @@ -39,8 +38,9 @@ func _on_removed() -> void: generator.data.notify_property_list_changed() - -func _on_argument_value_changed(value: Variant, _node: GaeaGraphNodeArgumentEditor, arg_name: String) -> void: +func _on_argument_value_changed( + value: Variant, _node: GaeaGraphNodeArgumentEditor, arg_name: String +) -> void: if arg_name != "name" and value is not String: return @@ -52,7 +52,6 @@ func _on_argument_value_changed(value: Variant, _node: GaeaGraphNodeArgumentEdit generator.data.set_node_argument(resource.id, &"name", current_name) - func _get_default_value(for_type: Variant.Type) -> Variant: match for_type: TYPE_FLOAT, TYPE_INT: diff --git a/addons/gaea/graph/graph_nodes/generic_classes/set_operation.gd b/addons/gaea/graph/graph_nodes/generic_classes/set_operation.gd index 92f0743df..e246c2a53 100644 --- a/addons/gaea/graph/graph_nodes/generic_classes/set_operation.gd +++ b/addons/gaea/graph/graph_nodes/generic_classes/set_operation.gd @@ -3,13 +3,7 @@ class_name GaeaNodeSetOp extends GaeaNodeResource - -enum Operation { - UNION, - INTERSECTION, - COMPLEMENT, - DIFFERENCE -} +enum Operation { UNION, INTERSECTION, COMPLEMENT, DIFFERENCE } const OPERATION_SYMBOLS := { Operation.UNION: "∪", @@ -22,9 +16,11 @@ const OPERATION_SYMBOLS := { func _get_description() -> String: match get_enum_selection(0): Operation.UNION: - return "Merges [param A]-[param D].\nLater grids override any cells from the previous grids when valid. (B overrides A, C overrides B, etc.)" + return """Merges [param A]-[param D]. +Later grids override any cells from the previous grids when valid. (B overrides A, C overrides B, etc.)""" Operation.INTERSECTION: - return "Returns the intersection between [param A]-[param D].\nLater grids override any cells from the previous grids when valid. (B overrides A, C overrides B, etc.)" + return """Returns the intersection between [param A]-[param D]. +Later grids override any cells from the previous grids when valid. (B overrides A, C overrides B, etc.)""" Operation.COMPLEMENT: return "Returns the complement of [param A]." Operation.DIFFERENCE: @@ -36,7 +32,9 @@ func _get_tree_items() -> Array[GaeaNodeResource]: var items: Array[GaeaNodeResource] for operation: Operation in _get_enum_options(0).values(): var item: GaeaNodeResource = get_script().new() - var tree_name: String = "%s (%s)" % [Operation.find_key(operation).to_pascal_case(), OPERATION_SYMBOLS[operation]] + var operation_name: String = Operation.find_key(operation).to_pascal_case() + var symbol: String = OPERATION_SYMBOLS[operation] + var tree_name := "%s (%s)" % [operation_name, symbol] item.set_tree_name_override(tree_name) item.set_default_enum_value_override(0, operation) items.append(item) @@ -57,9 +55,12 @@ func _get_enum_options(_idx: int) -> Dictionary: func _get_arguments_list() -> Array[StringName]: match get_enum_selection(0): - Operation.UNION, Operation.INTERSECTION: return [&"a", &"b", &"c", &"d"] - Operation.COMPLEMENT: return [&"a"] - Operation.DIFFERENCE: return [&"a", &"b"] + Operation.UNION, Operation.INTERSECTION: + return [&"a", &"b", &"c", &"d"] + Operation.COMPLEMENT: + return [&"a"] + Operation.DIFFERENCE: + return [&"a", &"b"] return [] @@ -73,10 +74,14 @@ func _get_output_ports_list() -> Array[StringName]: func _get_output_port_display_name(output_name: StringName) -> String: match get_enum_selection(0): - Operation.UNION: return "A ∪ B ∪ ..." - Operation.INTERSECTION: return "A ∩ B ∩ ..." - Operation.COMPLEMENT: return "Aᶜ" - Operation.DIFFERENCE: return "A - B" + Operation.UNION: + return "A ∪ B ∪ ..." + Operation.INTERSECTION: + return "A ∩ B ∩ ..." + Operation.COMPLEMENT: + return "Aᶜ" + Operation.DIFFERENCE: + return "A - B" return super(output_name) @@ -88,9 +93,9 @@ func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void: func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictionary: var grids: Array[Dictionary] = [] for arg in _get_arguments_list(): - var _grid: Dictionary = _get_arg(arg, area, graph) - if not _grid.is_empty(): - grids.append(_grid) + var arg_grid: Dictionary = _get_arg(arg, area, graph) + if not arg_grid.is_empty(): + grids.append(arg_grid) var grid: Dictionary = GaeaValue.get_default_value(_get_output_port_type(_output_port)) diff --git a/addons/gaea/graph/graph_nodes/node.gd b/addons/gaea/graph/graph_nodes/node.gd index e17677aa9..2549e351e 100644 --- a/addons/gaea/graph/graph_nodes/node.gd +++ b/addons/gaea/graph/graph_nodes/node.gd @@ -3,7 +3,6 @@ class_name GaeaGraphNode extends GraphNode ## The in-editor representation of a [GaeaNodeResource] to be used in the Gaea bottom panel. -const _PreviewTexture = preload("res://addons/gaea/graph/components/preview_texture.gd") ## Emitted when connections to this node are updated. signal connections_updated @@ -11,6 +10,8 @@ signal connections_updated signal removed signal remove_invalid_connections_requested +const PreviewTexture = preload("res://addons/gaea/graph/components/preview_texture.gd") + ## The [GaeaNodeResource] this acts as an editor of. @export var resource: GaeaNodeResource @@ -20,17 +21,22 @@ var generator: GaeaGenerator ## Used by the generator during runtime. This list is updated ## from [method update_connections] method. var connections: Array[Dictionary] -# Holds a cache of the generated titlebar styleboxes for each [enum GaeaValue.Type]. -# Updated if the type's color changes. -static var _titlebar_styleboxes: Dictionary[GaeaValue.Type, Dictionary] -var _preview: _PreviewTexture + +var _preview: PreviewTexture var _preview_container: VBoxContainer -var _finished_loading: bool = false: set = set_finished_loading, get = has_finished_loading -var _finished_rebuilding: bool = true: get = has_finished_rebuilding +var _finished_loading: bool = false: + set = set_finished_loading, + get = has_finished_loading +var _finished_rebuilding: bool = true: + get = has_finished_rebuilding var _editors: Dictionary[StringName, GaeaGraphNodeArgumentEditor] var _enum_editors: Array[OptionButton] var _last_category: GaeaArgumentCategory +# Holds a cache of the generated titlebar styleboxes for each [enum GaeaValue.Type]. +# Updated if the type's color changes. +static var _titlebar_styleboxes: Dictionary[GaeaValue.Type, Dictionary] + func _ready() -> void: _on_added() @@ -42,11 +48,15 @@ func _ready() -> void: if is_instance_valid(script): var documentation_button := Button.new() var editor_interface = Engine.get_singleton("EditorInterface") - documentation_button.icon = editor_interface.get_editor_theme().get_icon(&"HelpSearch", &"EditorIcons") + documentation_button.icon = editor_interface.get_editor_theme().get_icon( + &"HelpSearch", &"EditorIcons" + ) documentation_button.flat = true get_titlebar_hbox().add_child(documentation_button) documentation_button.pressed.connect(_open_node_documentation) - tree_exiting.connect(documentation_button.pressed.disconnect.bind(_open_node_documentation)) + tree_exiting.connect( + documentation_button.pressed.disconnect.bind(_open_node_documentation) + ) connections_updated.connect(_update_arguments_visibility) removed.connect(_on_removed) @@ -68,7 +78,7 @@ func _on_added() -> void: option_button.set_item_icon( option_button.get_item_index(option), resource.get_enum_option_icon(enum_idx, option) - ) + ) option_button.select(option_button.get_item_index(resource.get_enum_selection(enum_idx))) add_child(option_button) @@ -184,7 +194,7 @@ func _add_output_slot(for_output: StringName) -> GaeaGraphNodeOutput: if not is_instance_valid(_preview): _preview_container = VBoxContainer.new() - _preview = _PreviewTexture.new() + _preview = PreviewTexture.new() _preview.node = self generator.generation_finished.connect(_preview.update.unbind(1)) @@ -228,12 +238,25 @@ func _set_titlebar() -> void: if type != GaeaValue.Type.NULL: remove_theme_stylebox_override("titlebar") remove_theme_stylebox_override("titlebar_selected") - if not _titlebar_styleboxes.has(type) or _titlebar_styleboxes.get(type).get("for_color", Color.TRANSPARENT) != resource.get_title_color(): + if ( + not _titlebar_styleboxes.has(type) + or ( + _titlebar_styleboxes.get(type).get("for_color", Color.TRANSPARENT) + != resource.get_title_color() + ) + ): titlebar = get_theme_stylebox("titlebar", "GraphNode").duplicate() titlebar_selected = get_theme_stylebox("titlebar_selected", "GraphNode").duplicate() titlebar.bg_color = titlebar.bg_color.blend(Color(resource.get_title_color(), 0.3)) titlebar_selected.bg_color = titlebar.bg_color - _titlebar_styleboxes.set(type, {"titlebar": titlebar, "selected": titlebar_selected, "for_color": resource.get_title_color()}) + _titlebar_styleboxes.set( + type, + { + "titlebar": titlebar, + "selected": titlebar_selected, + "for_color": resource.get_title_color() + } + ) else: titlebar = _titlebar_styleboxes.get(type).get("titlebar") titlebar_selected = _titlebar_styleboxes.get(type).get("selected") @@ -256,7 +279,9 @@ func _set_arg_value(arg_name: StringName, value: Variant) -> void: editor.set_arg_value(value) -func _on_argument_value_changed(value: Variant, _node: GaeaGraphNodeArgumentEditor, arg_name: String) -> void: +func _on_argument_value_changed( + value: Variant, _node: GaeaGraphNodeArgumentEditor, arg_name: String +) -> void: if _finished_loading: resource.set_argument_value(arg_name, value) generator.data.set_node_argument(resource.id, arg_name, value) @@ -337,7 +362,6 @@ func load_save_data(saved_data: Dictionary) -> void: if arguments.get(argument) != null: editor.set_arg_value(arguments.get(argument)) - _finished_loading = true diff --git a/addons/gaea/graph/graph_nodes/node_resource.gd b/addons/gaea/graph/graph_nodes/node_resource.gd index 68c1f2512..10f6ab482 100644 --- a/addons/gaea/graph/graph_nodes/node_resource.gd +++ b/addons/gaea/graph/graph_nodes/node_resource.gd @@ -13,7 +13,6 @@ extends Resource ## ## @tutorial(Anatomy of a Graph): https://gaea-godot.github.io/gaea-docs/#/2.0/tutorials/anatomy-of-a-graph - @warning_ignore_start("unused_parameter") @warning_ignore_start("unused_signal") @@ -21,6 +20,13 @@ signal argument_list_changed signal argument_value_changed(arg_name: StringName, new_value: Variant) signal enum_value_changed(enum_idx: int, option_value: int) +## Used in [_get_preview_simulation_size]. +enum SimSize +{ + PREVIEW, + WORLD +} + #region Description Formatting const PARAM_TEXT_COLOR := Color("cdbff0") const PARAM_BG_COLOR := Color("bfbfbf1a") @@ -31,6 +37,9 @@ const GAEA_MATERIAL_HINT := "Resource used to tell GaeaRenderers what to place." const GAEA_MATERIAL_GRADIENT_HINT := "Resource that maps values from 0.0-1.0 to certain GaeaMaterials." #endregion +@export_storage var default_value_overrides: Dictionary[StringName, Variant] +@export_storage var default_enum_value_overrides: Dictionary[int, int] + ## List of all connections to this node. Doesn't include connections [i]from[/i] this node.[br] ## The dictionaries contain the following properties: ## [codeblock] @@ -59,16 +68,9 @@ var rng: RandomNumberGenerator ## Id in the [GaeaGraph] save data. var id: int = 0 ## If empty, [method _get_title] will be used instead. -var tree_name_override: String = "": set = set_tree_name_override -@export_storage var default_value_overrides: Dictionary[StringName, Variant] -@export_storage var default_enum_value_overrides: Dictionary[int, int] +var tree_name_override: String = "": + set = set_tree_name_override -## Used in [_get_preview_simulation_size]. -enum SimSize -{ - PREVIEW, - WORLD -} func notify_argument_list_changed() -> void: argument_list_changed.emit() @@ -176,6 +178,7 @@ func get_argument_display_name(arg_name: StringName) -> String: func get_argument_default_value(arg_name: StringName) -> Variant: return default_value_overrides.get(arg_name, _get_argument_default_value(arg_name)) + ## Public version of [method _get_argument_hint]. Prefer to override that method over this one. func get_argument_hint(arg_name: StringName) -> Dictionary[String, Variant]: return _get_argument_hint(arg_name) @@ -224,7 +227,8 @@ func get_custom_saved_data() -> Dictionary[StringName, Variant]: ## Override this method to define the name shown in the title bar of this node. ## Defining this method is [b]required[/b]. -@abstract func _get_title() -> String +@abstract +func _get_title() -> String ## Override this method to define the description shown in the 'Create Node' dialog and in a @@ -254,12 +258,13 @@ func _get_preview_simulation_size() -> SimSize: ## Override this method to define the options available for the added enums.[br][br] ## The returned [Dictionary] should be [code]{String: int}[/code]. Built-in enums can be used directly. -func _get_enum_options(idx: int) -> Dictionary: +func _get_enum_options(_idx: int) -> Dictionary: return {} ## Override this method if you want to change the display name for the options in the added enums.[br][br] -## Defining this method is [b]optional[/b]. If not defined, the name will be [code]_get_enum_options(enum_idx).find_key(option_value).capitalize()[/code]. +## Defining this method is [b]optional[/b]. +## If not defined, the name will be [code]_get_enum_options(enum_idx).find_key(option_value).capitalize()[/code]. func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String: var options := _get_enum_options(enum_idx) var key = options.find_key(option_value) @@ -270,7 +275,7 @@ func _get_enum_option_display_name(enum_idx: int, option_value: int) -> String: ## Override this method if you want to add icons to the options in the added enums.[br][br] ## Defining this method is [b]optional[/b]. -func _get_enum_option_icon(enum_idx: int, option_value: int) -> Texture: +func _get_enum_option_icon(_enum_idx: int, _option_value: int) -> Texture: return null @@ -283,8 +288,8 @@ func _get_enum_default_value(enum_idx: int) -> int: ## Override this method to define the arguments and inputs that will be available in the node. ## Should be a list of (preferably) [code]snake_case[/code] names.[br][br] ## Defining this method is [b]required[/b]. -@abstract func _get_arguments_list() -> Array[StringName] - +@abstract +func _get_arguments_list() -> Array[StringName] ## Override this method to define the type of the arguments defined in [method _get_arguments_list].[br][br] ## Defining this method is [b]required[/b]. @@ -299,7 +304,8 @@ func _get_argument_display_name(arg_name: StringName) -> String: ## Override this method to define the default value of the arguments defined in [method _get_arguments_list].[br][br] -## Defining this method is [b]optional[/b], but recommended. If not defined, the used default value will be the one in [method GaeaValue.get_default_value] +## Defining this method is [b]optional[/b], but recommended. +## If not defined, the used default value will be the one in [method GaeaValue.get_default_value] ## corresponding to the argument's type. func _get_argument_default_value(arg_name: StringName) -> Variant: return GaeaValue.get_default_value(_get_argument_type(arg_name)) @@ -308,20 +314,21 @@ func _get_argument_default_value(arg_name: StringName) -> Variant: ## Override this method to change the way the editors for the arguments behave. For example, ## if the returned [Dictionary] has a [code]"min"[/code] key, [GaeaNumberArgumentEditor] will not be able to go below that number.[br][br] ## Defining this method is [b]optional[/b]. -func _get_argument_hint(arg_name: StringName) -> Dictionary[String, Variant]: +func _get_argument_hint(_arg_name: StringName) -> Dictionary[String, Variant]: return {} ## Override this method to determine whether or not arguments can be connected to.[br] ## [b]Note[/b]: Some argument types can't have input slots. See [method GaeaValue.is_wireable].[br][br] ## Defining this method is [b]optional[/b]. If not defined, it'll always be true. -func _has_input_slot(arg_name: StringName) -> bool: +func _has_input_slot(_arg_name: StringName) -> bool: return true ## Override this method to define the outputs this node will have.[br][br] ## Defining this method is [b]required[/b]. -@abstract func _get_output_ports_list() -> Array[StringName] +@abstract +func _get_output_ports_list() -> Array[StringName] ## Override this method to define the display name for any outputs in [method _get_output_ports_list].[br][br] @@ -332,14 +339,15 @@ func _get_output_port_display_name(output_name: StringName) -> String: ## Override this method to define the type of the outputs defined in [method _get_output_ports_list].[br][br] ## Defining this method is [b]required[/b]. -@abstract func _get_output_port_type(output_name: StringName) -> GaeaValue.Type +@abstract +func _get_output_port_type(output_name: StringName) -> GaeaValue.Type ## If this returns a value higher than 0, the output slot for [param output_name] will be ## added in that index instead of below the arguments.[br][br] ## Overriding this method is [b]dangerous[/b]. Outputs should still follow the same order as in ## [method _get_output_list]; and the slot won't have a display name nor a preview. -func _get_overridden_output_port_idx(output_name: StringName) -> int: +func _get_overridden_output_port_idx(_output_name: StringName) -> int: return -1 @@ -366,7 +374,7 @@ func set_enum_value(enum_idx: int, option_value: int) -> void: ## Called when an enum is changed in the editor. When overridden, ## [method super] should [b]always[/b] be called at the head of the function. -func _on_enum_value_changed(enum_idx: int, option_value: int) -> void: +func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void: return @@ -378,7 +386,7 @@ func set_argument_value(arg_name: StringName, new_value: Variant) -> void: ## Called when an enum is changed in the editor. Does nothing by default, but can be used to call ## [method notify_arguments_list_changed] to rebuild the node. -func _on_argument_value_changed(arg_name: StringName, new_value: Variant) -> void: +func _on_argument_value_changed(_arg_name: StringName, _new_value: Variant) -> void: return @@ -393,25 +401,32 @@ func _get_arg(arg_name: StringName, area: AABB, graph: GaeaGraph) -> Variant: var connected_id = connection.from_node var connected_node = graph.get_node(connected_id) var connected_output = connected_node.connection_idx_to_output(connection.from_port) - var connected_data = connected_node.traverse( - connected_output, - area, - graph - ) + var connected_data = connected_node.traverse(connected_output, area, graph) if connected_data.has("value"): var connected_value = connected_data.get("value") - var connected_type: GaeaValue.Type = connected_node.get_output_port_type(connected_output) + var connected_type: GaeaValue.Type = connected_node.get_output_port_type( + connected_output + ) if connected_data.has("type"): connected_type = connected_data.get("type") + if connected_type == _get_argument_type(arg_name): return connected_value - else: - return GaeaValueCast.cast_value(connected_type, _get_argument_type(arg_name), connected_value) - else: - _log_error("Could not get data from previous node, using default value instead.", graph, connected_id) - return get_argument_default_value(arg_name) + + return GaeaValueCast.cast_value( + connected_type, _get_argument_type(arg_name), connected_value + ) + + _log_error( + "Could not get data from previous node, using default value instead.", + graph, + connected_id + ) + return get_argument_default_value(arg_name) return arguments.get(arg_name, get_argument_default_value(arg_name)) + + #endregion @@ -473,6 +488,8 @@ func _has_cached_data(output_port: StringName, graph: GaeaGraph) -> bool: ## See also [method has_cached_data] func _get_cached_data(output_port: StringName, graph: GaeaGraph) -> Variant: return graph.cache[self][output_port] + + #endregion @@ -502,6 +519,8 @@ func _get_input_resource(arg_name: StringName, graph: GaeaGraph) -> GaeaNodeReso return null return data_input_resource + + #endregion @@ -526,8 +545,11 @@ func _get_argument_connection(arg_name: StringName) -> Dictionary: func _filter_has_input(arg_name: StringName) -> bool: return GaeaValue.is_wireable(_get_argument_type(arg_name)) and _has_input_slot(arg_name) + + #endregion + #region Output connections ## Returns the connection idx of [param output]. func output_to_connection_idx(output: StringName) -> int: @@ -539,6 +561,8 @@ func connection_idx_to_output(output_idx: int) -> StringName: if _get_output_ports_list().size() <= output_idx: return &"" return _get_output_ports_list().get(output_idx) + + #endregion @@ -568,7 +592,7 @@ func _log_traverse(graph: GaeaGraph): ## If enabled in [member GaeaGraph.logging], log the data information. (See [enum GaeaGraph.Log]). func _log_data(output_port: StringName, graph: GaeaGraph): if is_instance_valid(graph) and graph.logging & GaeaGraph.Log.DATA > 0: - print("Data | %s from port &\"%s\"" % [_get_title(), output_port]) + print('Data | %s from port &"%s"' % [_get_title(), output_port]) # If enabled in [member GaeaGraph.logging], log the argument information. (See [enum GaeaGraph.Log]). @@ -594,6 +618,8 @@ func _log_error(message: String, graph: GaeaGraph, node_idx: int = -1): graph.resource_path, message, ]) + + #endregion @@ -619,9 +645,12 @@ func _get_scene_script() -> GDScript: ## Returns an array of points in the [param axis] of [param area]. func _get_axis_range(axis: Vector3i.Axis, area: AABB) -> Array: match axis: - Vector3i.AXIS_X: return range(area.position.x, area.end.x) - Vector3i.AXIS_Y: return range(area.position.y, area.end.y) - Vector3i.AXIS_Z: return range(area.position.z, area.end.z) + Vector3i.AXIS_X: + return range(area.position.x, area.end.x) + Vector3i.AXIS_Y: + return range(area.position.y, area.end.y) + Vector3i.AXIS_Z: + return range(area.position.z, area.end.z) return [] @@ -629,12 +658,26 @@ func _get_axis_range(axis: Vector3i.Axis, area: AABB) -> Array: static func get_formatted_text(unformatted_text: String) -> String: var param_regex = RegEx.new() param_regex.compile("\\[param ([^\\]]+)\\]") - - return param_regex.sub(unformatted_text, "[bgcolor=%s][color=%s]$1[/color][/bgcolor]" % [PARAM_BG_COLOR.to_html(true), PARAM_TEXT_COLOR.to_html(true)], true) \ - .replace("GaeaMaterial ", "[hint=%s]GaeaMaterial[/hint] " % GAEA_MATERIAL_HINT) \ - .replace("GradientGaeaMaterial ", "[hint=%s]GradientGaeaMaterial[/hint] " % GAEA_MATERIAL_GRADIENT_HINT) \ - .replace("[code]", "[bgcolor=%s][color=%s][code]" % [CODE_BG_COLOR.to_html(true), CODE_TEXT_COLOR.to_html(true)]) \ + var param_bg_html := PARAM_BG_COLOR.to_html(true) + var param_text_html := PARAM_TEXT_COLOR.to_html(true) + var code_bg_html := CODE_BG_COLOR.to_html(true) + var code_text_html := CODE_TEXT_COLOR.to_html(true) + + return ( + param_regex + .sub(unformatted_text, + "[bgcolor=%s][color=%s]$1[/color][/bgcolor]" % [param_bg_html, param_text_html], + true + ) + .replace("GaeaMaterial ", "[hint=%s]GaeaMaterial[/hint] " % GAEA_MATERIAL_HINT) + .replace( + "GradientGaeaMaterial ", "[hint=%s]GradientGaeaMaterial[/hint] " % GAEA_MATERIAL_GRADIENT_HINT + ) + .replace( + "[code]", "[bgcolor=%s][color=%s][code]" % [code_bg_html, code_text_html] + ) .replace("[/code]", "[/code][/color][/bgcolor]") + ) ## Returns the corresponding node icon to be used in the 'Create Node' list. @@ -655,8 +698,15 @@ func get_title_color() -> Color: func _is_point_outside_area(area: AABB, point: Vector3) -> bool: area.end -= Vector3.ONE - return (point.x < area.position.x or point.y < area.position.y or point.z < area.position.z or - point.x > area.end.x or point.y > area.end.y or point.z > area.end.z) + return ( + point.x < area.position.x + or point.y < area.position.y + or point.z < area.position.z + or point.x > area.end.x + or point.y > area.end.y + or point.z > area.end.z + ) + func _define_rng(graph: GaeaGraph) -> void: rng = RandomNumberGenerator.new() diff --git a/addons/gaea/graph/graph_nodes/root/data/basic/fill.gd b/addons/gaea/graph/graph_nodes/root/data/basic/fill.gd index 49b2869f2..313d87c17 100644 --- a/addons/gaea/graph/graph_nodes/root/data/basic/fill.gd +++ b/addons/gaea/graph/graph_nodes/root/data/basic/fill.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeFill +extends GaeaNodeResource ## Fills the grid with [param value]. diff --git a/addons/gaea/graph/graph_nodes/root/data/border/border.gd b/addons/gaea/graph/graph_nodes/root/data/border/border.gd index 0eabf244a..47e5ffea1 100644 --- a/addons/gaea/graph/graph_nodes/root/data/border/border.gd +++ b/addons/gaea/graph/graph_nodes/root/data/border/border.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeBorder2D +extends GaeaNodeResource ## Returns the border of [param data]. If [param inside] is [code]true[/code], returns the inner border. ## ## Loops through all the points in the generation area.[br] @@ -26,16 +26,20 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"data": return GaeaValue.Type.DATA - &"neighbors": return GaeaValue.Type.NEIGHBORS - &"inside": return GaeaValue.Type.BOOLEAN + &"data": + return GaeaValue.Type.DATA + &"neighbors": + return GaeaValue.Type.NEIGHBORS + &"inside": + return GaeaValue.Type.BOOLEAN return GaeaValue.Type.NULL func _get_argument_default_value(arg_name: StringName) -> Variant: match arg_name: - &"neighbors": return [Vector2i.RIGHT, Vector2i.LEFT, Vector2i.UP, Vector2i.DOWN] - return super (arg_name) + &"neighbors": + return [Vector2i.RIGHT, Vector2i.LEFT, Vector2i.UP, Vector2i.DOWN] + return super(arg_name) func _get_output_ports_list() -> Array[StringName]: @@ -60,17 +64,23 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio for y in _get_axis_range(Vector3i.AXIS_Y, area): for z in _get_axis_range(Vector3i.AXIS_Z, area): var cell: Vector3i = Vector3i(x, y, z) - if (inside and input_data.get(cell) == null) or (not inside and input_data.get(cell) != null): + var is_inside_border := inside and input_data.get(cell) == null + var is_outside_border := not inside and input_data.get(cell) != null + if is_inside_border or is_outside_border: continue for n: Vector2i in neighbors: if not inside: - var neighboring_cell: Vector3i = Vector3i(cell.x - n.x, cell.y - n.y, cell.z) + var neighboring_cell: Vector3i = Vector3i( + cell.x - n.x, cell.y - n.y, cell.z + ) if input_data.get(neighboring_cell) != null: border.set(cell, 1) break else: - var neighboring_cell: Vector3i = Vector3i(cell.x - n.x, cell.y - n.y, cell.z) + var neighboring_cell: Vector3i = Vector3i( + cell.x - n.x, cell.y - n.y, cell.z + ) if input_data.get(neighboring_cell) == null: border.set(cell, 1) break diff --git a/addons/gaea/graph/graph_nodes/root/data/filters/distance_filter.gd b/addons/gaea/graph/graph_nodes/root/data/filters/distance_filter.gd index 90d32540b..f63a8c6ea 100644 --- a/addons/gaea/graph/graph_nodes/root/data/filters/distance_filter.gd +++ b/addons/gaea/graph/graph_nodes/root/data/filters/distance_filter.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeFilter class_name GaeaNodeDistanceFilter +extends GaeaNodeFilter ## Filters [param data] to only the cells at a distance from [param to_point] in [param distance_range]. @@ -18,8 +18,10 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"to_point": return GaeaValue.Type.VECTOR3 - &"distance_range": return GaeaValue.Type.RANGE + &"to_point": + return GaeaValue.Type.VECTOR3 + &"distance_range": + return GaeaValue.Type.RANGE return super(arg_name) @@ -31,4 +33,6 @@ func _passes_filter(_input_data: Dictionary, cell: Vector3i, area: AABB, graph: var point: Vector3 = _get_arg(&"to_point", area, graph) var distance_range: Dictionary = _get_arg(&"distance_range", area, graph) var distance: float = Vector3(cell).distance_squared_to(point) - return distance >= distance_range.get("min", -INF) ** 2 and distance <= distance_range.get("max", INF) ** 2 + var is_further_than_min: bool = distance >= distance_range.get("min", -INF) ** 2 + var is_closer_than_max: bool = distance <= distance_range.get("max", INF) ** 2 + return is_further_than_min and is_closer_than_max diff --git a/addons/gaea/graph/graph_nodes/root/data/filters/filter.gd b/addons/gaea/graph/graph_nodes/root/data/filters/filter.gd index 814a2d237..323f95a5f 100644 --- a/addons/gaea/graph/graph_nodes/root/data/filters/filter.gd +++ b/addons/gaea/graph/graph_nodes/root/data/filters/filter.gd @@ -1,7 +1,7 @@ @tool @abstract -extends GaeaNodeResource class_name GaeaNodeFilter +extends GaeaNodeResource ## Abstract class used for filter nodes. @@ -49,5 +49,7 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio ## Override this method to change the filtering functionality. Should return [code]true[/code] ## if the [param cell] in [param input_data] passes the filter, and therefore should be included ## in the output. -func _passes_filter(_input_data: Dictionary, _cell: Vector3i, _area: AABB, _graph: GaeaGraph) -> bool: +func _passes_filter( + _input_data: Dictionary, _cell: Vector3i, _area: AABB, _graph: GaeaGraph +) -> bool: return true diff --git a/addons/gaea/graph/graph_nodes/root/data/filters/flags_filter.gd b/addons/gaea/graph/graph_nodes/root/data/filters/flags_filter.gd index 021b5c9e0..546976c97 100644 --- a/addons/gaea/graph/graph_nodes/root/data/filters/flags_filter.gd +++ b/addons/gaea/graph/graph_nodes/root/data/filters/flags_filter.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeFilter class_name GaeaNodeFlagsFilter +extends GaeaNodeFilter ## Filters [param data] to only the cells that match the flag conditions. ## ## Flags are [code]int[/code]s, so the filtering is done with the rounded value @@ -24,9 +24,12 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"match_all": return GaeaValue.Type.BOOLEAN - &"match_flags": return GaeaValue.Type.FLAGS - &"exclude_flags": return GaeaValue.Type.FLAGS + &"match_all": + return GaeaValue.Type.BOOLEAN + &"match_flags": + return GaeaValue.Type.FLAGS + &"exclude_flags": + return GaeaValue.Type.FLAGS return super(arg_name) @@ -40,10 +43,13 @@ func _passes_filter(input_data: Dictionary, cell: Vector3i, area: AABB, graph: G var match_all: bool = _get_arg(&"match_all", area, graph) var value: float = input_data[cell] + var matches_excluded_flags := exclude_flags.any(_matches_flag.bind(value)) if match_all: - return flags.all(_matches_flag.bind(value)) and not exclude_flags.any(_matches_flag.bind(value)) - else: - return flags.any(_matches_flag.bind(value)) and not exclude_flags.any(_matches_flag.bind(value)) + var matches_all_flags := flags.all(_matches_flag.bind(value)) + return matches_all_flags and not matches_excluded_flags + + var matches_any_flags := flags.any(_matches_flag.bind(value)) + return matches_any_flags and not matches_excluded_flags func _matches_flag(value: float, flag: int) -> bool: diff --git a/addons/gaea/graph/graph_nodes/root/data/filters/random_filter.gd b/addons/gaea/graph/graph_nodes/root/data/filters/random_filter.gd index 653a0f07b..31bfa7297 100644 --- a/addons/gaea/graph/graph_nodes/root/data/filters/random_filter.gd +++ b/addons/gaea/graph/graph_nodes/root/data/filters/random_filter.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeFilter class_name GaeaNodeRandomFilter +extends GaeaNodeFilter ## Randomly filters [param data] to only the cells that pass the [param chance] check. @@ -18,19 +18,22 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"chance": return GaeaValue.Type.INT + &"chance": + return GaeaValue.Type.INT return super(arg_name) func _get_argument_default_value(arg_name: StringName) -> Variant: match arg_name: - &"chance": return 50 + &"chance": + return 50 return super(arg_name) func _get_argument_hint(arg_name: StringName) -> Dictionary[String, Variant]: match arg_name: - &"chance": return {"suffix": "%", "min": 0, "max": 100} + &"chance": + return {"suffix": "%", "min": 0, "max": 100} return super(arg_name) diff --git a/addons/gaea/graph/graph_nodes/root/data/filters/threshold_filter.gd b/addons/gaea/graph/graph_nodes/root/data/filters/threshold_filter.gd index dd53c653d..b8812ea09 100644 --- a/addons/gaea/graph/graph_nodes/root/data/filters/threshold_filter.gd +++ b/addons/gaea/graph/graph_nodes/root/data/filters/threshold_filter.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeFilter class_name GaeaNodeThresholdFilter +extends GaeaNodeFilter ## Filters [param data] to only the cells of a value in [param range]. @@ -18,7 +18,8 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"range": return GaeaValue.Type.RANGE + &"range": + return GaeaValue.Type.RANGE return super(arg_name) diff --git a/addons/gaea/graph/graph_nodes/root/data/generation/falloff_map.gd b/addons/gaea/graph/graph_nodes/root/data/generation/falloff_map.gd index 831ed5256..edf2fb864 100644 --- a/addons/gaea/graph/graph_nodes/root/data/generation/falloff_map.gd +++ b/addons/gaea/graph/graph_nodes/root/data/generation/falloff_map.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeFalloffMap +extends GaeaNodeResource ## Returns a grid that goes from higher values in the center to lower in the borders. ## Rate can be adjusted with [param start] and [param end]. ## @@ -15,8 +15,8 @@ enum FalloffShape { SQUIRCLE, } - -@abstract class FalloffSampler: +@abstract +class FalloffSampler: var area: AABB var start: float var end: float @@ -84,11 +84,14 @@ enum FalloffShape { if value < start: return 1.0 - elif value > end: + + if value > end: return 0.0 + return smoothstep(1.0, 0.0, inverse_lerp(start, end, value)) - @abstract func _get_sample(_x: int, _y: int) -> float + @abstract + func _get_sample(_x: int, _y: int) -> float class FalloffSamplerSquare: @@ -128,7 +131,9 @@ func _get_title() -> String: func _get_description() -> String: - return "Returns a grid that goes from higher values in the center to lower in the borders.\nRate can be adjusted with [param start] and [param end]." + return """Returns a grid that goes from higher values in the center to lower in the borders. +Rate can be adjusted with [param start] and [param end].""" + func _get_enums_count() -> int: return 1 diff --git a/addons/gaea/graph/graph_nodes/root/data/generation/floor_walker.gd b/addons/gaea/graph/graph_nodes/root/data/generation/floor_walker.gd index ac5bc639f..1086cac94 100644 --- a/addons/gaea/graph/graph_nodes/root/data/generation/floor_walker.gd +++ b/addons/gaea/graph/graph_nodes/root/data/generation/floor_walker.gd @@ -1,6 +1,7 @@ @tool -extends GaeaNodeResource class_name GaeaNodeFloorWalker +extends GaeaNodeResource +#gdlint:disable = max-line-length ## Generates a floor by using [b]walkers[/b], which move around and ## set cells where they walk to [code]1.0[/code], while changing direction and/or spawning new walkers. ## @@ -12,17 +13,15 @@ class_name GaeaNodeFloorWalker ## When a size of [param max_cells] is reached, the generation will stop.[br][br] ## This is how [url=https://nuclearthrone.com]Nuclear Throne[/url] does its generation, ## for example, as seen [url=https://web.archive.org/web/20151009004931/https://www.vlambeer.com/2013/04/02/random-level-generation-in-wasteland-kings/]here[/url]. +#gdlint:enable = max-line-length - -enum AxisType { - XY, XZ -} +enum AxisType { XY, XZ } ## Walker as used in [GaeaNodeFloorWalker]. class Walker: - var dir: Vector3 ## Current direction, should be in 90-degrees angles. - var pos: Vector3 ## Current position, should be rounded. + var dir: Vector3 ## Current direction, should be in 90-degrees angles. + var pos: Vector3 ## Current position, should be rounded. func _get_title() -> String: @@ -30,7 +29,8 @@ func _get_title() -> String: func _get_description() -> String: - return "Generates a floor by using [b]walkers[/b], which move around and set cells where they walk to [code]1.0[/code], while changing direction and/or spawning new walkers." + return """Generates a floor by using [b]walkers[/b], which move around and set cells \ +where they walk to [code]1.0[/code], while changing direction and/or spawning new walkers.""" func _get_enums_count() -> int: @@ -46,10 +46,20 @@ func _get_enum_option_display_name(_enum_idx: int, option_value: int) -> String: func _get_arguments_list() -> Array[StringName]: - return [&"max_cells", &"starting_position", - &"CATEGORY_DIRECTION_CHANCES", &"direction_change_chance", &"rotate_90_weight", &"rotate_-90_weight", &"rotate_180_weight", - &"CATEGORY_WALKER_CHANCE", &"new_walker_chance", &"destroy_walker_chance", &"bigger_room_chance", &"bigger_room_size_range" - ] + return [ + &"max_cells", + &"starting_position", + &"CATEGORY_DIRECTION_CHANCES", + &"direction_change_chance", + &"rotate_90_weight", + &"rotate_-90_weight", + &"rotate_180_weight", + &"CATEGORY_WALKER_CHANCE", + &"new_walker_chance", + &"destroy_walker_chance", + &"bigger_room_chance", + &"bigger_room_size_range" + ] func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: @@ -67,16 +77,21 @@ func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: func _get_argument_default_value(arg_name: StringName) -> Variant: match arg_name: - &"max_cells": return 100 - &"direction_change_chance": return 50 - &"rotate_90_weight", &"rotate_-90_weight", &"rotate_180_weight": return 40 - &"new_walker_chance", &"destroy_walker_chance": return 5 - &"bigger_room_chance": return 15 - &"bigger_room_size_range": return {"min": 2, "max": 3} + &"max_cells": + return 100 + &"direction_change_chance": + return 50 + &"rotate_90_weight", &"rotate_-90_weight", &"rotate_180_weight": + return 40 + &"new_walker_chance", &"destroy_walker_chance": + return 5 + &"bigger_room_chance": + return 15 + &"bigger_room_size_range": + return {"min": 2, "max": 3} return super(arg_name) - func _get_output_ports_list() -> Array[StringName]: return [&"data"] @@ -84,9 +99,11 @@ func _get_output_ports_list() -> Array[StringName]: func _get_argument_hint(arg_name: StringName) -> Dictionary[String, Variant]: if arg_name == &"bigger_room_size_range": return {"min": 1, "max": 5, "suffix": "²", "step": 1, "allow_lesser": false} - elif arg_name.ends_with(&"chance"): + + if arg_name.ends_with(&"chance"): return {"suffix": "%", "min": 0, "max": 100} - elif arg_name.ends_with(&"weight") or arg_name == &"max_cells": + + if arg_name.ends_with(&"weight") or arg_name == &"max_cells": return {"min": 0} return super(arg_name) @@ -104,70 +121,85 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio _log_data(_output_port, graph) var axis_type: AxisType = get_enum_selection(0) as AxisType - var _starting_position: Vector3 = _get_arg(&"starting_position", area, graph) - _starting_position = _starting_position.round() + var starting_position: Vector3 = _get_arg(&"starting_position", area, graph) + starting_position = starting_position.round() var rotation_weights: Dictionary = { PI / 2.0: _get_arg(&"rotate_90_weight", area, graph), -PI / 2.0: _get_arg(&"rotate_-90_weight", area, graph), PI: _get_arg(&"rotate_180_weight", area, graph) } - var direction_change_chance: float = float(_get_arg(&"direction_change_chance", area, graph)) / 100.0 + var direction_change_chance: float = ( + float(_get_arg(&"direction_change_chance", area, graph)) / 100.0 + ) var new_walker_chance: float = float(_get_arg(&"new_walker_chance", area, graph)) / 100.0 - var destroy_walker_chance: float = float(_get_arg(&"destroy_walker_chance", area, graph)) / 100.0 + var destroy_walker_chance: float = ( + float(_get_arg(&"destroy_walker_chance", area, graph)) / 100.0 + ) var bigger_room_chance: float = float(_get_arg(&"bigger_room_chance", area, graph)) / 100.0 var bigger_room_size_range: Dictionary = _get_arg(&"bigger_room_size_range", area, graph) var max_cells: int = _get_arg(&"max_cells", area, graph) max_cells = mini( max_cells, - roundi(area.size.x) * (roundi(area.size.y) if axis_type == AxisType.XY else roundi(area.size.z)) + ( + roundi(area.size.x) + * (roundi(area.size.y) if axis_type == AxisType.XY else roundi(area.size.z)) + ) ) - var _walkers: Array[Walker] - var _walked_cells: Array[Vector3i] + var walkers: Array[Walker] + var walked_cells: Array[Vector3i] var iterations: int = 0 - _add_walker(_starting_position, _walkers) + _add_walker(starting_position, walkers) - while iterations < 10000 and _walked_cells.size() < max_cells: - for walker in _walkers: - - if rng.randf() <= destroy_walker_chance and _walkers.size() > 1: - _walkers.erase(walker) + while iterations < 10000 and walked_cells.size() < max_cells: + for walker in walkers: + if rng.randf() <= destroy_walker_chance and walkers.size() > 1: + walkers.erase(walker) continue if rng.randf() <= new_walker_chance: - _add_walker(walker.pos, _walkers) + _add_walker(walker.pos, walkers) if rng.randf() <= direction_change_chance: - var direction:int = rng.rand_weighted(rotation_weights.values()) + var direction: int = rng.rand_weighted(rotation_weights.values()) walker.dir = walker.dir.rotated( Vector3(0, 0, 1) if axis_type == AxisType.XY else Vector3(0, 1, 0), rotation_weights.keys()[direction] ).round() if rng.randf() <= bigger_room_chance: - var size: int = rng.randi_range(bigger_room_size_range.min, bigger_room_size_range.max) - for cell in _get_square_room(walker.pos, Vector3(size, size if axis_type == AxisType.XY else 1, size if axis_type == AxisType.XZ else 1)): + var size: int = rng.randi_range( + bigger_room_size_range.min, bigger_room_size_range.max + ) + for cell in _get_square_room( + walker.pos, + Vector3( + size, + size if axis_type == AxisType.XY else 1, + size if axis_type == AxisType.XZ else 1 + ) + ): cell = cell.clamp(area.position, area.end - Vector3.ONE) - if not _walked_cells.has(Vector3i(cell)): - _walked_cells.append(Vector3i(cell)) + if not walked_cells.has(Vector3i(cell)): + walked_cells.append(Vector3i(cell)) walker.pos += walker.dir - walker.pos = walker.pos.clamp(area.position, area.end - Vector3.ONE ) + walker.pos = walker.pos.clamp(area.position, area.end - Vector3.ONE) - if not _walked_cells.has(Vector3i(walker.pos)): - _walked_cells.append(Vector3i(walker.pos)) + if not walked_cells.has(Vector3i(walker.pos)): + walked_cells.append(Vector3i(walker.pos)) - if _walked_cells.size() >= max_cells: + if walked_cells.size() >= max_cells: break iterations += 1 var grid: Dictionary[Vector3i, float] - for cell in _walked_cells: + for cell in walked_cells: grid[cell] = 1.0 return grid @@ -176,11 +208,15 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio func _add_walker(pos: Vector3, array: Array[Walker]) -> void: var walker: Walker = Walker.new() walker.pos = pos - walker.dir = [ - Vector3.LEFT, - Vector3.RIGHT, - Vector3.DOWN if get_enum_selection(0) == AxisType.XY else Vector3.FORWARD, - Vector3.UP if get_enum_selection(0) == AxisType.XY else Vector3.BACK].pick_random() + walker.dir = ( + [ + Vector3.LEFT, + Vector3.RIGHT, + Vector3.DOWN if get_enum_selection(0) == AxisType.XY else Vector3.FORWARD, + Vector3.UP if get_enum_selection(0) == AxisType.XY else Vector3.BACK + ] + . pick_random() + ) array.append(walker) diff --git a/addons/gaea/graph/graph_nodes/root/data/generation/snake_path_2d.gd b/addons/gaea/graph/graph_nodes/root/data/generation/snake_path_2d.gd index 897369945..dce4ad6c3 100644 --- a/addons/gaea/graph/graph_nodes/root/data/generation/snake_path_2d.gd +++ b/addons/gaea/graph/graph_nodes/root/data/generation/snake_path_2d.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeSnakePath2D +extends GaeaNodeResource ## Generates a path that goes from the top of the world to the bottom, ## with each cell consisting of flags that indicate their exits (up, down, left, right). ## @@ -20,12 +20,21 @@ func _get_title() -> String: func _get_description() -> String: - return "Generates a path that goes from the top of the world to the bottom, with each cell consisting of flags that indicate their exits (up, down, left, right)." + return """Generates a path that goes from the top of the world to the bottom, \ +with each cell consisting of flags that indicate their exits (up, down, left, right).""" func _get_arguments_list() -> Array[StringName]: - return [&"move_left_weight", &"move_right_weight", &"move_down_weight", - &"CATEGORY_FLAGS", &"left", &"right", &"down", &"up"] + return [ + &"move_left_weight", + &"move_right_weight", + &"move_down_weight", + &"CATEGORY_FLAGS", + &"left", + &"right", + &"down", + &"up" + ] func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: @@ -40,11 +49,16 @@ func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: func _get_argument_default_value(arg_name: StringName) -> Variant: match arg_name: - &"move_left_weight", &"move_right_weight", &"move_down_weight": return 40 - &"left": return 1 - &"right": return 2 - &"down": return 4 - &"up": return 8 + &"move_left_weight", &"move_right_weight", &"move_down_weight": + return 40 + &"left": + return 1 + &"right": + return 2 + &"down": + return 4 + &"up": + return 8 return super(arg_name) diff --git a/addons/gaea/graph/graph_nodes/root/data/noise/noise.gd b/addons/gaea/graph/graph_nodes/root/data/noise/noise.gd index 08ba352f2..f650553e8 100644 --- a/addons/gaea/graph/graph_nodes/root/data/noise/noise.gd +++ b/addons/gaea/graph/graph_nodes/root/data/noise/noise.gd @@ -1,12 +1,11 @@ @tool @abstract -extends GaeaNodeResource class_name GaeaNodeNoise +extends GaeaNodeResource ## Creates a grid of values from [code]0.0[/code] to [code]1.0[/code] based on a noise algorithm. ## ## Base class for both the 2D and 3D version of this node. - enum NoiseType { SIMPLEX = FastNoiseLite.NoiseType.TYPE_SIMPLEX, SIMPLEX_SMOOTH = FastNoiseLite.NoiseType.TYPE_SIMPLEX_SMOOTH, @@ -14,7 +13,7 @@ enum NoiseType { PERLIN = FastNoiseLite.NoiseType.TYPE_PERLIN, VALUE_CUBIC = FastNoiseLite.NoiseType.TYPE_VALUE_CUBIC, VALUE = FastNoiseLite.NoiseType.TYPE_VALUE -} # This has to be copied because you can't use FastNoiseLite.NoiseType directly. +} # This has to be copied because you can't use FastNoiseLite.NoiseType directly. func _get_title() -> String: @@ -47,9 +46,12 @@ func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: func _get_argument_default_value(arg_name: StringName) -> Variant: match arg_name: - &"frequency": return 0.01 - &"lacunarity": return 2.0 - &"octaves": return 5 + &"frequency": + return 0.01 + &"lacunarity": + return 2.0 + &"octaves": + return 5 return super(arg_name) @@ -62,21 +64,21 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictionary[Vector3i, float]: - var _noise: FastNoiseLite = FastNoiseLite.new() - _noise.seed = graph.generator.seed + salt - _noise.noise_type = get_enum_selection(0) as FastNoiseLite.NoiseType + var noise: FastNoiseLite = FastNoiseLite.new() + noise.seed = graph.generator.seed + salt + noise.noise_type = get_enum_selection(0) as FastNoiseLite.NoiseType - _noise.frequency = _get_arg(&"frequency", area, graph) - _noise.fractal_octaves = _get_arg(&"octaves", area, graph) - _noise.fractal_lacunarity = _get_arg(&"lacunarity", area, graph) + noise.frequency = _get_arg(&"frequency", area, graph) + noise.fractal_octaves = _get_arg(&"octaves", area, graph) + noise.fractal_lacunarity = _get_arg(&"lacunarity", area, graph) var dictionary: Dictionary[Vector3i, float] for x in _get_axis_range(Vector3i.AXIS_X, area): for y in _get_axis_range(Vector3i.AXIS_Y, area): for z in _get_axis_range(Vector3i.AXIS_Z, area): - dictionary[Vector3i(x, y, z)] = (_get_noise_value(Vector3i(x, y, z), _noise) + 1.0) / 2.0 + var noise_value := _get_noise_value(Vector3i(x, y, z), noise) + dictionary[Vector3i(x, y, z)] = (noise_value + 1.0) / 2.0 return dictionary - func _get_noise_value(_cell: Vector3i, _noise: FastNoiseLite) -> float: return -1.0 diff --git a/addons/gaea/graph/graph_nodes/root/data/noise/noise_2d.gd b/addons/gaea/graph/graph_nodes/root/data/noise/noise_2d.gd index d2bdd5722..07d95472b 100644 --- a/addons/gaea/graph/graph_nodes/root/data/noise/noise_2d.gd +++ b/addons/gaea/graph/graph_nodes/root/data/noise/noise_2d.gd @@ -1,7 +1,6 @@ @tool -extends GaeaNodeNoise class_name GaeaNodeNoise2D - +extends GaeaNodeNoise func _get_title() -> String: diff --git a/addons/gaea/graph/graph_nodes/root/data/noise/noise_3d.gd b/addons/gaea/graph/graph_nodes/root/data/noise/noise_3d.gd index 770714da0..1bff8592c 100644 --- a/addons/gaea/graph/graph_nodes/root/data/noise/noise_3d.gd +++ b/addons/gaea/graph/graph_nodes/root/data/noise/noise_3d.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeNoise class_name GaeaNodeNoise3D +extends GaeaNodeNoise func _get_title() -> String: diff --git a/addons/gaea/graph/graph_nodes/root/data/operations/datas/datas_operation.gd b/addons/gaea/graph/graph_nodes/root/data/operations/datas/datas_operation.gd index 6d1a397c4..ce31d4cfb 100644 --- a/addons/gaea/graph/graph_nodes/root/data/operations/datas/datas_operation.gd +++ b/addons/gaea/graph/graph_nodes/root/data/operations/datas/datas_operation.gd @@ -3,19 +3,14 @@ class_name GaeaNodeDatasOp extends GaeaNodeResource ## Operation between 2 data grids. +enum Operation { ADD, SUBTRACT, MULTIPLY, DIVIDE, LERP } -enum Operation { - ADD, - SUBTRACT, - MULTIPLY, - DIVIDE, - LERP -} class Definition: var args: Array[StringName] var output: String var conversion: Callable + func _init(_args: Array[StringName], _output: String, _conversion: Callable): args = _args output = _output @@ -23,7 +18,8 @@ class Definition: ## All possible operations. -var OPERATION_DEFINITIONS: Dictionary[Operation, Definition] : get = _get_operation_definitions +var operation_definitions: Dictionary[Operation, Definition]: + get = _get_operation_definitions func _get_title() -> String: @@ -52,9 +48,12 @@ func _get_description() -> String: func _get_tree_items() -> Array[GaeaNodeResource]: var items: Array[GaeaNodeResource] items.append_array(super()) - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): var item: GaeaNodeResource = get_script().new() - item.set_tree_name_override("%sDatas (%s)" % [Operation.find_key(operation).to_pascal_case(), OPERATION_DEFINITIONS[operation].output] ) + var operation_name: String = Operation.find_key(operation).to_pascal_case() + var output_name: String = operation_definitions[operation].output + var tree_name := "%sDatas (%s)" % [operation_name, output_name] + item.set_tree_name_override(tree_name) item.set_default_enum_value_override(0, operation) items.append(item) @@ -68,14 +67,14 @@ func _get_enums_count() -> int: func _get_enum_options(_idx: int) -> Dictionary: var options: Dictionary = {} - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): options.set(Operation.find_key(operation), operation) return options func _get_arguments_list() -> Array[StringName]: - return OPERATION_DEFINITIONS.get(get_enum_selection(0)).args + return operation_definitions.get(get_enum_selection(0)).args func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: @@ -89,6 +88,7 @@ func _get_argument_hint(arg_name: StringName) -> Dictionary[String, Variant]: return {"min": 0.0, "max": 1.0} return super(arg_name) + func _on_enum_value_changed(_enum_idx: int, _option_value: int) -> void: notify_argument_list_changed() @@ -102,8 +102,7 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: func _get_output_port_display_name(_output_name: StringName) -> String: - return OPERATION_DEFINITIONS[get_enum_selection(0)].output - + return operation_definitions[get_enum_selection(0)].output func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictionary[Vector3i, float]: @@ -111,7 +110,7 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio var a_grid: Dictionary = _get_arg(&"a", area, graph) var b_grid: Dictionary = _get_arg(&"b", area, graph) var new_grid: Dictionary[Vector3i, float] - var operation_definition: Definition = OPERATION_DEFINITIONS[operation] + var operation_definition: Definition = operation_definitions[operation] var static_args: Array for arg in operation_definition.args: if _get_argument_type(arg) == GaeaValue.Type.DATA: @@ -121,24 +120,29 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio for cell: Vector3i in a_grid: if not b_grid.has(cell): continue - new_grid.set(cell, operation_definition.conversion.callv([a_grid[cell], b_grid[cell]] + static_args)) + new_grid.set( + cell, operation_definition.conversion.callv([a_grid[cell], b_grid[cell]] + static_args) + ) return new_grid func _get_operation_definitions() -> Dictionary[Operation, Definition]: - if not OPERATION_DEFINITIONS.is_empty(): - return OPERATION_DEFINITIONS + if not operation_definitions.is_empty(): + return operation_definitions - OPERATION_DEFINITIONS = { + operation_definitions = { Operation.ADD: - Definition.new([&"a", &"b"], "A + B", func(a: Variant, b: Variant): return a + b), + Definition.new([&"a", &"b"], "A + B", func(a: Variant, b: Variant): return a + b), Operation.SUBTRACT: - Definition.new([&"a", &"b"], "A - B", func(a: Variant, b: Variant): return a - b), + Definition.new([&"a", &"b"], "A - B", func(a: Variant, b: Variant): return a - b), Operation.MULTIPLY: - Definition.new([&"a", &"b"], "A * B", func(a: Variant, b: Variant): return a * b), + Definition.new([&"a", &"b"], "A * B", func(a: Variant, b: Variant): return a * b), Operation.DIVIDE: - Definition.new([&"a", &"b"], "A / B", func(a: Variant, b: Variant): return 0 if is_zero_approx(b) else a / b), - Operation.LERP: - Definition.new([&"a", &"b", &"weight"], "lerp(a, b, weight)", lerpf) + Definition.new( + [&"a", &"b"], + "A / B", + func(a: Variant, b: Variant): return 0 if is_zero_approx(b) else a / b + ), + Operation.LERP: Definition.new([&"a", &"b", &"weight"], "lerp(a, b, weight)", lerpf) } - return OPERATION_DEFINITIONS + return operation_definitions diff --git a/addons/gaea/graph/graph_nodes/root/data/operations/scalar/data_operation.gd b/addons/gaea/graph/graph_nodes/root/data/operations/scalar/data_operation.gd index a9f1b20b7..b96beae80 100644 --- a/addons/gaea/graph/graph_nodes/root/data/operations/scalar/data_operation.gd +++ b/addons/gaea/graph/graph_nodes/root/data/operations/scalar/data_operation.gd @@ -22,9 +22,15 @@ func _get_description() -> String: Operation.DIVIDE: return "Divides all cells in [param A] by a [code]float[/code] number." Operation.POWER: - return super().replace("base", "a") + "\n\nOperates over all cells of [param A], [param a] being the cells' value." + return ( + super().replace("base", "a") + + "\n\nOperates over all cells of [param A], [param a] being the cells' value." + ) _: - return super() + "\n\nOperates over all cells of [param A], [param a] being the cells' value." + return ( + super() + + "\n\nOperates over all cells of [param A], [param a] being the cells' value." + ) func _get_argument_display_name(arg_name: StringName) -> String: @@ -58,10 +64,10 @@ func _get_operation_definitions() -> Dictionary[Operation, Definition]: func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictionary[Vector3i, float]: var operation: Operation = get_enum_selection(0) as Operation - var operation_definition: Definition = OPERATION_DEFINITIONS[operation] + var operation_definition: Definition = operation_definitions[operation] var args: Array var input_grid: Dictionary = _get_arg(&"a", area, graph) - for arg_name: StringName in OPERATION_DEFINITIONS[operation].args: + for arg_name: StringName in operation_definitions[operation].args: if arg_name == &"a": continue args.append(_get_arg(arg_name, area, graph)) diff --git a/addons/gaea/graph/graph_nodes/root/data/transformation/to_height.gd b/addons/gaea/graph/graph_nodes/root/data/transformation/to_height.gd index 9d73144f8..5e93bc763 100644 --- a/addons/gaea/graph/graph_nodes/root/data/transformation/to_height.gd +++ b/addons/gaea/graph/graph_nodes/root/data/transformation/to_height.gd @@ -1,6 +1,7 @@ @tool class_name GaeaNodeToHeight extends GaeaNodeResource +#gdlint:disable = max-line-length ## Transforms [param reference_data] into a new data grid where the height of each column is determined by [param height_offset] + ([param reference_data] * [param displacement_intensity]) ## ## For each cell in [param reference_data]'s [param reference_y] row, it'll get the [code]float[/code] value, @@ -10,6 +11,7 @@ extends GaeaNodeResource ## This functions to create a heightmap, which can be used to create 2D side-view or ## 3D terrain.[br][br] ## [b]Note: Keep in mind the y axis in Godot is negative for up in 2D and down in 3D.[/b] +#gdlint:enable = max-line-length enum Type { TYPE_2D, ## Referenced data will only take into account the x coordinate of the cell. @@ -22,13 +24,13 @@ func _get_title() -> String: func _get_description() -> String: - var desc: String = "Transforms [param reference_data] into a new data grid where the height of each column is determined by\ - [param height_offset] + ([param reference_data] * [param displacement_intensity]).\n" + var desc: String = """Transforms [param reference_data] into a new data grid \ +where the height of each column is determined by [param height_offset] + ([param reference_data] * [param displacement_intensity]).""" match get_enum_selection(0): Type.TYPE_2D: - desc += "\nReferences all the x values of the [param reference_y] row." + desc += "\n\nReferences all the x values of the [param reference_y] row." Type.TYPE_3D: - desc += "\nReferences all the x,z values of the [param reference_y] row." + desc += "\n\nReferences all the x,z values of the [param reference_y] row." return desc diff --git a/addons/gaea/graph/graph_nodes/root/input/input.gd b/addons/gaea/graph/graph_nodes/root/input/input.gd index 660d34784..e99308394 100644 --- a/addons/gaea/graph/graph_nodes/root/input/input.gd +++ b/addons/gaea/graph/graph_nodes/root/input/input.gd @@ -1,15 +1,9 @@ @tool -extends GaeaNodeResource class_name GaeaNodeInput +extends GaeaNodeResource ## Returns different input variables. - -enum InputVar { - WORLD_SIZE, - AREA_SIZE, - AREA_POSITION, - AREA_END -} +enum InputVar { WORLD_SIZE, AREA_SIZE, AREA_POSITION, AREA_END } func _get_title() -> String: @@ -18,10 +12,14 @@ func _get_title() -> String: func _get_description() -> String: match get_enum_selection(0): - InputVar.WORLD_SIZE: return "Outputs the [param world_size] parameter in the generator's inspector." - InputVar.AREA_SIZE: return "Outputs the size of the area being currently generated." - InputVar.AREA_POSITION: return "Outputs the position of the area being currently generated." - InputVar.AREA_END: return "Outputs the bottom right corner position of the area being currently generated." + InputVar.WORLD_SIZE: + return "Outputs the [param world_size] parameter in the generator's inspector." + InputVar.AREA_SIZE: + return "Outputs the size of the area being currently generated." + InputVar.AREA_POSITION: + return "Outputs the position of the area being currently generated." + InputVar.AREA_END: + return "Outputs the bottom right corner position of the area being currently generated." return super() @@ -74,16 +72,23 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: func _get_type_of_input(input: InputVar) -> GaeaValue.Type: match input: - InputVar.WORLD_SIZE: return GaeaValue.Type.VECTOR3I - InputVar.AREA_SIZE, InputVar.AREA_POSITION, InputVar.AREA_END: return GaeaValue.Type.VECTOR3 - _: return GaeaValue.Type.NULL + InputVar.WORLD_SIZE: + return GaeaValue.Type.VECTOR3I + InputVar.AREA_SIZE, InputVar.AREA_POSITION, InputVar.AREA_END: + return GaeaValue.Type.VECTOR3 + _: + return GaeaValue.Type.NULL func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Variant: match get_enum_selection(0): - InputVar.WORLD_SIZE: return graph.generator.world_size - InputVar.AREA_SIZE: return area.size - InputVar.AREA_POSITION: return area.position - InputVar.AREA_END: return area.end + InputVar.WORLD_SIZE: + return graph.generator.world_size + InputVar.AREA_SIZE: + return area.size + InputVar.AREA_POSITION: + return area.position + InputVar.AREA_END: + return area.end return null diff --git a/addons/gaea/graph/graph_nodes/root/map/filters/random_filter.gd b/addons/gaea/graph/graph_nodes/root/map/filters/random_filter.gd index 3abfba901..19d672289 100644 --- a/addons/gaea/graph/graph_nodes/root/map/filters/random_filter.gd +++ b/addons/gaea/graph/graph_nodes/root/map/filters/random_filter.gd @@ -8,6 +8,5 @@ func _get_description() -> String: return super().replace("data", "map") - func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: return GaeaValue.Type.MAP diff --git a/addons/gaea/graph/graph_nodes/root/map/mappers/basic_mapper.gd b/addons/gaea/graph/graph_nodes/root/map/mappers/basic_mapper.gd index 38d158f25..849c134c9 100644 --- a/addons/gaea/graph/graph_nodes/root/map/mappers/basic_mapper.gd +++ b/addons/gaea/graph/graph_nodes/root/map/mappers/basic_mapper.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeMapper class_name GaeaNodeBasicMapper +extends GaeaNodeMapper ## Maps all non-empty cells in [param data] to [param material]. diff --git a/addons/gaea/graph/graph_nodes/root/map/mappers/flags_mapper.gd b/addons/gaea/graph/graph_nodes/root/map/mappers/flags_mapper.gd index b463cabb1..5d43499a8 100644 --- a/addons/gaea/graph/graph_nodes/root/map/mappers/flags_mapper.gd +++ b/addons/gaea/graph/graph_nodes/root/map/mappers/flags_mapper.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeMapper class_name GaeaNodeFlagsMapper +extends GaeaNodeMapper ## Maps every cell of [param data] that matches the flag conditions to [param material]. ## ## Flags are [code]int[/code]s, so the filtering is done with the rounded value @@ -24,9 +24,12 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"match_all": return GaeaValue.Type.BOOLEAN - &"match_flags": return GaeaValue.Type.FLAGS - &"exclude_flags": return GaeaValue.Type.FLAGS + &"match_all": + return GaeaValue.Type.BOOLEAN + &"match_flags": + return GaeaValue.Type.FLAGS + &"exclude_flags": + return GaeaValue.Type.FLAGS return super(arg_name) @@ -36,10 +39,13 @@ func _passes_mapping(grid_data: Dictionary, cell: Vector3i, area: AABB, graph: G var exclude_flags: Array = _get_arg(&"exclude_flags", area, graph) var value: float = grid_data.get(cell) + var matches_excluded_flags := exclude_flags.any(_matches_flag.bind(value)) if match_all: - return flags.all(_matches_flag.bind(value)) and not exclude_flags.any(_matches_flag.bind(value)) - else: - return flags.any(_matches_flag.bind(value)) and not exclude_flags.any(_matches_flag.bind(value)) + var matches_all_flags := flags.all(_matches_flag.bind(value)) + return matches_all_flags and not matches_excluded_flags + + var matches_any_flags := flags.any(_matches_flag.bind(value)) + return matches_any_flags and not matches_excluded_flags func _matches_flag(value: float, flag: int) -> bool: diff --git a/addons/gaea/graph/graph_nodes/root/map/mappers/mapper.gd b/addons/gaea/graph/graph_nodes/root/map/mappers/mapper.gd index 7939620e1..aebb799ff 100644 --- a/addons/gaea/graph/graph_nodes/root/map/mappers/mapper.gd +++ b/addons/gaea/graph/graph_nodes/root/map/mappers/mapper.gd @@ -37,11 +37,11 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio material = material.prepare_sample(rng) if not is_instance_valid(material): material = _get_arg(&"material", area, graph) - _log_error( - "Recursive limit reached (%d): Invalid material provided at %s" % [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path], - graph, - graph.resources.find(self) + var error := ( + "Recursive limit reached (%d): Invalid material provided at %s" + % [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path] ) + _log_error(error, graph, graph.resources.find(self)) return grid for cell in grid_data: diff --git a/addons/gaea/graph/graph_nodes/root/map/mappers/threshold_mapper.gd b/addons/gaea/graph/graph_nodes/root/map/mappers/threshold_mapper.gd index db329fb1d..4aeaf27c0 100644 --- a/addons/gaea/graph/graph_nodes/root/map/mappers/threshold_mapper.gd +++ b/addons/gaea/graph/graph_nodes/root/map/mappers/threshold_mapper.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeMapper class_name GaeaNodeThresholdMapper +extends GaeaNodeMapper ## Maps every cell of [param data] of a value in [param range] to [param material]. @@ -18,7 +18,8 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"range": return GaeaValue.Type.RANGE + &"range": + return GaeaValue.Type.RANGE return super(arg_name) diff --git a/addons/gaea/graph/graph_nodes/root/map/mappers/value_mapper.gd b/addons/gaea/graph/graph_nodes/root/map/mappers/value_mapper.gd index a3fd9ab24..3fcc538bb 100644 --- a/addons/gaea/graph/graph_nodes/root/map/mappers/value_mapper.gd +++ b/addons/gaea/graph/graph_nodes/root/map/mappers/value_mapper.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeMapper class_name GaeaNodeValueMapper +extends GaeaNodeMapper ## Maps every cell in [param data] equal to [param value] to [param material]. ## ## Uses [method @GlobalScope.is_equal_approx] to avoid floating point precision problems. @@ -20,7 +20,8 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"value": return GaeaValue.Type.FLOAT + &"value": + return GaeaValue.Type.FLOAT return super(arg_name) diff --git a/addons/gaea/graph/graph_nodes/root/map/placing/random_scatter.gd b/addons/gaea/graph/graph_nodes/root/map/placing/random_scatter.gd index 84e8c65f7..e1e4310d8 100644 --- a/addons/gaea/graph/graph_nodes/root/map/placing/random_scatter.gd +++ b/addons/gaea/graph/graph_nodes/root/map/placing/random_scatter.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeRandomScatter +extends GaeaNodeResource ## Randomly places [param amount] [param material]s in the cells of [param reference_data]. @@ -18,9 +18,12 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(arg_name: StringName) -> GaeaValue.Type: match arg_name: - &"reference_data": return GaeaValue.Type.DATA - &"material": return GaeaValue.Type.MATERIAL - &"amount": return GaeaValue.Type.INT + &"reference_data": + return GaeaValue.Type.DATA + &"material": + return GaeaValue.Type.MATERIAL + &"amount": + return GaeaValue.Type.INT return GaeaValue.Type.NULL @@ -48,11 +51,11 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio material = material.prepare_sample(rng) if not is_instance_valid(material): material = _get_arg(&"material", area, graph) - _log_error( - "Recursive limit reached (%d): Invalid material provided at %s" % [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path], - graph, - id + var error := ( + "Recursive limit reached (%d): Invalid material provided at %s" + % [GaeaMaterial.RECURSIVE_LIMIT, material.resource_path] ) + _log_error(error, graph, graph.resources.find(self)) return grid for cell: Vector3i in cells_to_place_on: diff --git a/addons/gaea/graph/graph_nodes/root/map/placing/rules_placer.gd b/addons/gaea/graph/graph_nodes/root/map/placing/rules_placer.gd index 9e5da68db..b6ee23b4b 100644 --- a/addons/gaea/graph/graph_nodes/root/map/placing/rules_placer.gd +++ b/addons/gaea/graph/graph_nodes/root/map/placing/rules_placer.gd @@ -1,6 +1,7 @@ @tool -extends GaeaNodeResource class_name GaeaNodeRulesPlacer +extends GaeaNodeResource +#gdlint:disable = max-line-length ## Places [param material] on every world cell that follows [param rules] based on [param reference_data]. ## [img]res://addons/gaea/assets/cross.svg[/img] means data DOESN'T have a cell there, ## [img]res://addons/gaea/assets/check.svg[/img] means the opposite. @@ -11,10 +12,12 @@ class_name GaeaNodeRulesPlacer ## You can also think about it as the outlined cell having an offset of [code](0,0)[/code].[br] ## For every offset:[br] ## - If the editor has no icon, that offset has no rule. It is ignored.[br] -## - If the offset is marked as [img]res://addons/gaea/assets/check.svg[/img], that offset has to have a corresponding cell in [param reference_data] to qualify as "following the rules".[br] +## - If the offset is marked as [img]res://addons/gaea/assets/check.svg[/img], +## that offset has to have a corresponding cell in [param reference_data] to qualify as "following the rules".[br] ## - If the offset is marked as [img]res://addons/gaea/assets/cross.svg[/img], it's the opposite.[br] ## If a cell doesn't follow all the rules for each offset, it won't qualify. Otherwise, the outputted [param map] ## will have [param material] there. +#gdlint:enable = max-line-length func _get_title() -> String: @@ -22,9 +25,10 @@ func _get_title() -> String: func _get_description() -> String: - return "Places [param material] on every world cell that follows [param rules] based -on [param reference_data].\n[img]res://addons/gaea/assets/cross.svg[/img] means data DOESN'T have a cell there,\ - [img]res://addons/gaea/assets/check.svg[/img] means the opposite." + return """Places [param material] on every world cell that follows [param rules] based on [param reference_data]. +[img]res://addons/gaea/assets/cross.svg[/img] means data DOESN'T have a cell there,\ +[img]res://addons/gaea/assets/check.svg[/img] means the opposite.""" + func _get_arguments_list() -> Array[StringName]: diff --git a/addons/gaea/graph/graph_nodes/root/other/composition/compose_range.gd b/addons/gaea/graph/graph_nodes/root/other/composition/compose_range.gd index 967feabda..16d218089 100644 --- a/addons/gaea/graph/graph_nodes/root/other/composition/compose_range.gd +++ b/addons/gaea/graph/graph_nodes/root/other/composition/compose_range.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeComposeRange +extends GaeaNodeResource ## Composes a range value from 2 numbers, [param min] and [param max]. ## ## Ranges internally have the following format: diff --git a/addons/gaea/graph/graph_nodes/root/resources/samplers/texture_sampler.gd b/addons/gaea/graph/graph_nodes/root/resources/samplers/texture_sampler.gd index 46710e558..d1d0c366a 100644 --- a/addons/gaea/graph/graph_nodes/root/resources/samplers/texture_sampler.gd +++ b/addons/gaea/graph/graph_nodes/root/resources/samplers/texture_sampler.gd @@ -44,7 +44,7 @@ func _get_data(output_port: StringName, area: AABB, graph: GaeaGraph) -> Diction var b_grid: Dictionary[Vector3i, float] var a_grid: Dictionary[Vector3i, float] - var slices: Array[Image] # Only one is texture is 2D + var slices: Array[Image] # Only one is texture is 2D if texture is Texture2D: slices = [texture.get_image()] elif texture is Texture3D: diff --git a/addons/gaea/graph/graph_nodes/root/resources/variables/material_parameter.gd b/addons/gaea/graph/graph_nodes/root/resources/variables/material_parameter.gd index 80113010a..4ff5c2821 100644 --- a/addons/gaea/graph/graph_nodes/root/resources/variables/material_parameter.gd +++ b/addons/gaea/graph/graph_nodes/root/resources/variables/material_parameter.gd @@ -4,7 +4,6 @@ extends GaeaNodeParameter ## [GaeaMaterial] parameter editable in the inspector. - func _get_variant_type() -> int: return TYPE_OBJECT diff --git a/addons/gaea/graph/graph_nodes/root/resources/variables/texture_2d_parameter.gd b/addons/gaea/graph/graph_nodes/root/resources/variables/texture_2d_parameter.gd index 2406ee68c..5e45f109c 100644 --- a/addons/gaea/graph/graph_nodes/root/resources/variables/texture_2d_parameter.gd +++ b/addons/gaea/graph/graph_nodes/root/resources/variables/texture_2d_parameter.gd @@ -6,8 +6,8 @@ extends GaeaNodeParameter func _get_variant_type() -> int: return TYPE_OBJECT - - + + func _get_property_hint() -> PropertyHint: return PROPERTY_HINT_RESOURCE_TYPE diff --git a/addons/gaea/graph/graph_nodes/root/resources/variables/texture_3d_parameter.gd b/addons/gaea/graph/graph_nodes/root/resources/variables/texture_3d_parameter.gd index 50e2de093..29d3c30db 100644 --- a/addons/gaea/graph/graph_nodes/root/resources/variables/texture_3d_parameter.gd +++ b/addons/gaea/graph/graph_nodes/root/resources/variables/texture_3d_parameter.gd @@ -6,8 +6,8 @@ extends GaeaNodeParameter func _get_variant_type() -> int: return TYPE_OBJECT - - + + func _get_property_hint() -> PropertyHint: return PROPERTY_HINT_RESOURCE_TYPE diff --git a/addons/gaea/graph/graph_nodes/root/scalar/operations/float_operation.gd b/addons/gaea/graph/graph_nodes/root/scalar/operations/float_operation.gd index 34b53095f..f74e9fd10 100644 --- a/addons/gaea/graph/graph_nodes/root/scalar/operations/float_operation.gd +++ b/addons/gaea/graph/graph_nodes/root/scalar/operations/float_operation.gd @@ -4,7 +4,6 @@ extends GaeaNodeNumOp ## A [float] operator. - func _get_title() -> String: return "FloatOp" diff --git a/addons/gaea/graph/graph_nodes/root/scalar/operations/int_operation.gd b/addons/gaea/graph/graph_nodes/root/scalar/operations/int_operation.gd index 331e54cf3..5a991c5f9 100644 --- a/addons/gaea/graph/graph_nodes/root/scalar/operations/int_operation.gd +++ b/addons/gaea/graph/graph_nodes/root/scalar/operations/int_operation.gd @@ -4,7 +4,6 @@ extends GaeaNodeNumOp ## [int] operation. - func _get_title() -> String: return "IntOp" diff --git a/addons/gaea/graph/graph_nodes/root/vector/composition/compose_vector.gd b/addons/gaea/graph/graph_nodes/root/vector/composition/compose_vector.gd index d7ef91b2f..232886d0a 100644 --- a/addons/gaea/graph/graph_nodes/root/vector/composition/compose_vector.gd +++ b/addons/gaea/graph/graph_nodes/root/vector/composition/compose_vector.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeVectorBase class_name GaeaNodeComposeVector +extends GaeaNodeVectorBase ## Composes floats to vector. @@ -9,7 +9,10 @@ func _get_title() -> String: func _get_description() -> String: - return "Composes %d [code]float[/code]s into [code]%s[/code]." % [_get_arguments_list().size(), _get_vector_type_name()] + return ( + "Composes %d [code]float[/code]s into [code]%s[/code]." + % [_get_arguments_list().size(), _get_vector_type_name()] + ) #region Arguments @@ -27,7 +30,9 @@ func _get_argument_display_name(arg_name: StringName) -> String: func _get_argument_type(_arg_name: StringName) -> GaeaValue.Type: - return (GaeaValue.Type.INT if _is_integer_vector() else GaeaValue.Type.FLOAT) + return GaeaValue.Type.INT if _is_integer_vector() else GaeaValue.Type.FLOAT + + #endregion @@ -42,6 +47,8 @@ func _get_output_port_display_name(_output_name: StringName) -> String: func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: return get_enum_selection(0) as GaeaValue.Type + + #endregion @@ -51,9 +58,7 @@ func _get_tree_items() -> Array[GaeaNodeResource]: for i in VectorType.values(): var item: GaeaNodeResource = get_script().new() item.set_default_enum_value_override(0, i) - item.set_tree_name_override( - _get_enum_option_display_name(0, i) + "Compose" - ) + item.set_tree_name_override(_get_enum_option_display_name(0, i) + "Compose") array.append(item) return array diff --git a/addons/gaea/graph/graph_nodes/root/vector/composition/decompose_vector.gd b/addons/gaea/graph/graph_nodes/root/vector/composition/decompose_vector.gd index a9034153e..dabe5163f 100644 --- a/addons/gaea/graph/graph_nodes/root/vector/composition/decompose_vector.gd +++ b/addons/gaea/graph/graph_nodes/root/vector/composition/decompose_vector.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeVectorBase class_name GaeaNodeDecomposeVector +extends GaeaNodeVectorBase ## Decomposes vector to floats. @@ -9,7 +9,10 @@ func _get_title() -> String: func _get_description() -> String: - return "Decomposes a [code]%s[/code] into %d [code]float[/code]s." % [_get_vector_type_name(), _get_output_ports_list().size()] + return ( + "Decomposes a [code]%s[/code] into %d [code]float[/code]s." + % [_get_vector_type_name(), _get_output_ports_list().size()] + ) #region Arguments @@ -23,6 +26,8 @@ func _get_argument_display_name(_arg_name: StringName) -> String: func _get_argument_type(_arg_name: StringName) -> GaeaValue.Type: return get_enum_selection(0) as GaeaValue.Type + + #endregion @@ -41,7 +46,9 @@ func _get_output_port_display_name(output_name: StringName) -> String: func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: - return (GaeaValue.Type.INT if _is_integer_vector() else GaeaValue.Type.FLOAT) + return GaeaValue.Type.INT if _is_integer_vector() else GaeaValue.Type.FLOAT + + #endregion @@ -51,9 +58,7 @@ func _get_tree_items() -> Array[GaeaNodeResource]: for i in VectorType.values(): var item: GaeaNodeResource = get_script().new() item.set_default_enum_value_override(0, i) - item.set_tree_name_override( - _get_enum_option_display_name(0, i) + "Decompose" - ) + item.set_tree_name_override(_get_enum_option_display_name(0, i) + "Decompose") array.append(item) return array diff --git a/addons/gaea/graph/graph_nodes/root/vector/operations/vector_operation.gd b/addons/gaea/graph/graph_nodes/root/vector/operations/vector_operation.gd index cb954f387..f18d9064b 100644 --- a/addons/gaea/graph/graph_nodes/root/vector/operations/vector_operation.gd +++ b/addons/gaea/graph/graph_nodes/root/vector/operations/vector_operation.gd @@ -15,13 +15,15 @@ class Definition: var args: Array[StringName] var output: String var conversion: Callable + func _init(_args: Array[StringName], _output: String, _conversion: Callable): args = _args output = _output conversion = _conversion -var OPERATION_DEFINITIONS: Dictionary[Operation, Definition] : get = _get_operation_definitions +var operation_definitions: Dictionary[Operation, Definition]: + get = _get_operation_definitions func _get_title() -> String: @@ -32,15 +34,16 @@ func _get_description() -> String: if get_tree_name() == _get_title() and not is_instance_valid(node): return "Operation between 2 [code]Vector[/code]s." + var vector_name := _get_enum_option_display_name(0, get_enum_selection(0)) match get_enum_selection(1): Operation.ADD: - return "Sums 2 [code]%s[/code]s." % _get_enum_option_display_name(0, get_enum_selection(0)) + return "Sums 2 [code]%s[/code]s." % vector_name Operation.SUBTRACT: - return "Subtracts 2 [code]%s[/code]s." % _get_enum_option_display_name(0, get_enum_selection(0)) + return "Subtracts 2 [code]%s[/code]s." % vector_name Operation.MULTIPLY: - return "Multiplies 2 [code]%s[/code]s together." % _get_enum_option_display_name(0, get_enum_selection(0)) + return "Multiplies 2 [code]%s[/code]s together." % vector_name Operation.DIVIDE: - return "Divides 2 [code]%s[/code]s together." % _get_enum_option_display_name(0, get_enum_selection(0)) + return "Divides 2 [code]%s[/code]s together." % vector_name return "" @@ -48,12 +51,17 @@ func _get_tree_items() -> Array[GaeaNodeResource]: var items: Array[GaeaNodeResource] items.append_array(super()) for vector_type in VectorType.keys(): - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): var item: GaeaNodeResource = get_script().new() - item.set_tree_name_override("%s (%s)" % [ - Operation.find_key(operation).to_pascal_case(), - OPERATION_DEFINITIONS[operation].output - ]) + item.set_tree_name_override( + ( + "%s (%s)" + % [ + Operation.find_key(operation).to_pascal_case(), + operation_definitions[operation].output + ] + ) + ) item.set_default_enum_value_override(0, VectorType[vector_type]) item.set_default_enum_value_override(1, operation) items.append(item) @@ -69,7 +77,7 @@ func _get_enum_options(_idx: int) -> Dictionary: return super(_idx) var options: Dictionary = {} - for operation in OPERATION_DEFINITIONS.keys(): + for operation in operation_definitions.keys(): options.set(Operation.find_key(operation), operation) return options @@ -81,7 +89,7 @@ func _get_enum_option_icon(enum_idx: int, option_value: int) -> Texture: func _get_arguments_list() -> Array[StringName]: - return OPERATION_DEFINITIONS.get(get_enum_selection(1)).args + return operation_definitions.get(get_enum_selection(1)).args func _get_argument_display_name(arg_name: StringName) -> String: @@ -105,7 +113,7 @@ func _get_output_ports_list() -> Array[StringName]: func _get_output_port_display_name(_output_name: StringName) -> String: - return OPERATION_DEFINITIONS[get_enum_selection(1)].output + return operation_definitions[get_enum_selection(1)].output func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: @@ -115,27 +123,31 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: func _get_data(_output_port: StringName, _area: AABB, graph: GaeaGraph) -> Variant: var operation: Operation = get_enum_selection(1) as Operation var args: Array - for arg_name: StringName in OPERATION_DEFINITIONS[operation].args: + for arg_name: StringName in operation_definitions[operation].args: args.append(_get_arg(arg_name, _area, graph)) return _get_new_value(operation, args) func _get_new_value(operation: Operation, args: Array) -> Variant: - return OPERATION_DEFINITIONS[operation].conversion.callv(args) + return operation_definitions[operation].conversion.callv(args) func _get_operation_definitions() -> Dictionary[Operation, Definition]: - if not OPERATION_DEFINITIONS.is_empty(): - return OPERATION_DEFINITIONS + if not operation_definitions.is_empty(): + return operation_definitions - OPERATION_DEFINITIONS = { + operation_definitions = { Operation.ADD: - Definition.new([&"a", &"b"], "a + b", func(a: Variant, b: Variant): return a + b), + Definition.new([&"a", &"b"], "a + b", func(a: Variant, b: Variant): return a + b), Operation.SUBTRACT: - Definition.new([&"a", &"b"], "a - b", func(a: Variant, b: Variant): return a - b), + Definition.new([&"a", &"b"], "a - b", func(a: Variant, b: Variant): return a - b), Operation.MULTIPLY: - Definition.new([&"a", &"b"], "a * b", func(a: Variant, b: Variant): return a * b), + Definition.new([&"a", &"b"], "a * b", func(a: Variant, b: Variant): return a * b), Operation.DIVIDE: - Definition.new([&"a", &"b"], "a / b", func(a: Variant, b: Variant): return 0 if b.is_zero_approx() else a / b), + Definition.new( + [&"a", &"b"], + "a / b", + func(a: Variant, b: Variant): return 0 if b.is_zero_approx() else a / b + ), } - return OPERATION_DEFINITIONS + return operation_definitions diff --git a/addons/gaea/graph/graph_nodes/root/vector/vector_base.gd b/addons/gaea/graph/graph_nodes/root/vector/vector_base.gd index 69ab77d4a..4c85dab89 100644 --- a/addons/gaea/graph/graph_nodes/root/vector/vector_base.gd +++ b/addons/gaea/graph/graph_nodes/root/vector/vector_base.gd @@ -4,7 +4,6 @@ class_name GaeaNodeVectorBase extends GaeaNodeResource ## Base class for vector operation nodes. - enum VectorType { VECTOR2 = GaeaValue.Type.VECTOR2, VECTOR3 = GaeaValue.Type.VECTOR3, @@ -23,7 +22,8 @@ func _get_enums_count() -> int: func _get_enum_options(enum_idx: int) -> Dictionary: match enum_idx: - 0: return VectorType + 0: + return VectorType return {} diff --git a/addons/gaea/graph/graph_nodes/special/frame/graph_frame.gd b/addons/gaea/graph/graph_nodes/special/frame/graph_frame.gd index df38585a6..d9f3b4a8e 100644 --- a/addons/gaea/graph/graph_nodes/special/frame/graph_frame.gd +++ b/addons/gaea/graph/graph_nodes/special/frame/graph_frame.gd @@ -43,8 +43,8 @@ func _on_rename_text_submitted(new_text: String) -> void: func start_tint_color_change(gaea_panel: Control) -> void: - var _popup: PopupPanel = PopupPanel.new() - _popup.position = gaea_panel.get_global_mouse_position() as Vector2i + var popup: PopupPanel = PopupPanel.new() + popup.position = gaea_panel.get_global_mouse_position() as Vector2i var vbox_container: VBoxContainer = VBoxContainer.new() @@ -54,15 +54,15 @@ func start_tint_color_change(gaea_panel: Control) -> void: var ok_button: Button = Button.new() ok_button.text = "OK" - ok_button.pressed.connect(_popup.queue_free) + ok_button.pressed.connect(popup.queue_free) vbox_container.add_child(color_picker) vbox_container.add_child(ok_button) - _popup.add_child(vbox_container) + popup.add_child(vbox_container) - gaea_panel.add_child(_popup) - _popup.popup() + gaea_panel.add_child(popup) + popup.popup() func _on_color_changed(new_color: Color) -> void: diff --git a/addons/gaea/graph/graph_nodes/special/output/output_node.gd b/addons/gaea/graph/graph_nodes/special/output/output_node.gd index 476feb161..36fa027ca 100644 --- a/addons/gaea/graph/graph_nodes/special/output/output_node.gd +++ b/addons/gaea/graph/graph_nodes/special/output/output_node.gd @@ -7,12 +7,13 @@ func _on_added() -> void: if not is_instance_valid(resource) or is_part_of_edited_scene(): return - super() custom_minimum_size.x = 192.0 var titlebar: StyleBoxFlat = get_theme_stylebox("titlebar", "GraphNode").duplicate() - var titlebar_selected: StyleBoxFlat = get_theme_stylebox("titlebar_selected", "GraphNode").duplicate() + var titlebar_selected: StyleBoxFlat = ( + get_theme_stylebox("titlebar_selected", "GraphNode").duplicate() + ) titlebar.bg_color = titlebar.bg_color.blend(Color(resource.get_title_color(), 0.3)) titlebar_selected.bg_color = titlebar.bg_color diff --git a/addons/gaea/graph/graph_nodes/special/output/output_node_resource.gd b/addons/gaea/graph/graph_nodes/special/output/output_node_resource.gd index c1dfad55a..d7c2b7e99 100644 --- a/addons/gaea/graph/graph_nodes/special/output/output_node_resource.gd +++ b/addons/gaea/graph/graph_nodes/special/output/output_node_resource.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeOutput +extends GaeaNodeResource ## Outputs the generated grid via [signal GaeaGenerator.generation_finished]. ## ## All Gaea graphs should lead to this node. When a generation is needed, diff --git a/addons/gaea/graph/graph_nodes/special/reroute/reroute_node.gd b/addons/gaea/graph/graph_nodes/special/reroute/reroute_node.gd index ec7e017fa..ac81f2650 100644 --- a/addons/gaea/graph/graph_nodes/special/reroute/reroute_node.gd +++ b/addons/gaea/graph/graph_nodes/special/reroute/reroute_node.gd @@ -1,7 +1,6 @@ @tool extends GaeaGraphNode - var tween: Tween var icon_opacity: float = 0.0: @@ -16,6 +15,7 @@ var has_no_input: bool = false: get: return connections.size() == 0 + #region init func _on_added() -> void: if not is_instance_valid(resource) or is_part_of_edited_scene(): @@ -55,28 +55,42 @@ func _on_removed() -> void: if connections.size() == 1: input_connection = connections[0] - graph_edit.disconnection_request.emit( - input_connection.from_node, - input_connection.from_port, - input_connection.to_node, - input_connection.to_port, + ( + graph_edit + .disconnection_request + .emit( + input_connection.from_node, + input_connection.from_port, + input_connection.to_node, + input_connection.to_port, + ) ) for connection in graph_edit.connections: if connection.from_node == name and connection.from_port == 0: - graph_edit.disconnection_request.emit( - connection.from_node, - connection.from_port, - connection.to_node, - connection.to_port, - ) - if not input_connection.is_empty(): - graph_edit.connection_request.emit( - input_connection.from_node, - input_connection.from_port, + ( + graph_edit + .disconnection_request + .emit( + connection.from_node, + connection.from_port, connection.to_node, connection.to_port, ) + ) + if not input_connection.is_empty(): + ( + graph_edit + .connection_request + .emit( + input_connection.from_node, + input_connection.from_port, + connection.to_node, + connection.to_port, + ) + ) + + #endregion @@ -97,10 +111,7 @@ func _draw_port(slot_index: int, pos: Vector2i, left: bool, color: Color) -> voi draw_texture_rect( port_icon, - Rect2( - center_pos + icon_offset * editor_scale, - port_icon.get_size() * editor_scale - ), + Rect2(center_pos + icon_offset * editor_scale, port_icon.get_size() * editor_scale), false, color ) @@ -132,4 +143,6 @@ func _set_icon_opacity(value: float): tween.kill() tween = create_tween() tween.tween_property(self, "icon_opacity", value, 0.3) + + #endregion diff --git a/addons/gaea/graph/graph_nodes/special/reroute/reroute_node_resource.gd b/addons/gaea/graph/graph_nodes/special/reroute/reroute_node_resource.gd index fcb502f86..58c7abae3 100644 --- a/addons/gaea/graph/graph_nodes/special/reroute/reroute_node_resource.gd +++ b/addons/gaea/graph/graph_nodes/special/reroute/reroute_node_resource.gd @@ -1,6 +1,6 @@ @tool -extends GaeaNodeResource class_name GaeaNodeReroute +extends GaeaNodeResource ## Allows rerouting a connection within the Gaea graph. ## ## Can be placed by pressing [kbd]Right Click[/kbd] in a connection wire and selecting the option, @@ -27,6 +27,8 @@ func _get_arguments_list() -> Array[StringName]: func _get_argument_type(_arg_name: StringName) -> GaeaValue.Type: return type + + #endregion @@ -37,6 +39,8 @@ func _get_output_ports_list() -> Array[StringName]: func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type: return type + + #endregion diff --git a/addons/gaea/nodes/chunk_loaders/threaded_chunk_loader_2d.gd b/addons/gaea/nodes/chunk_loaders/threaded_chunk_loader_2d.gd index d554d1bec..e2d7aaf13 100644 --- a/addons/gaea/nodes/chunk_loaders/threaded_chunk_loader_2d.gd +++ b/addons/gaea/nodes/chunk_loaders/threaded_chunk_loader_2d.gd @@ -22,15 +22,15 @@ func _update_loading(actor_position: Vector2i) -> void: if not threaded: super(actor_position) else: - var _job:Callable = func (): + var job: Callable = func (): super._update_loading(actor_position) if _task > -1: - _queued = _job + _queued = job else: - run_job(_job) + run_job(job) -func run_job(_job:Callable): - if _job: - _task = WorkerThreadPool.add_task(_job, false, "Load/Unload Chunks") +func run_job(job: Callable): + if job: + _task = WorkerThreadPool.add_task(job, false, "Load/Unload Chunks") diff --git a/addons/gaea/nodes/renderers/gridmap_renderer.gd b/addons/gaea/nodes/renderers/gridmap_renderer.gd index c4f3b40a4..5504285b0 100644 --- a/addons/gaea/nodes/renderers/gridmap_renderer.gd +++ b/addons/gaea/nodes/renderers/gridmap_renderer.gd @@ -4,13 +4,14 @@ extends GaeaRenderer ## Renders [GridMapGaeaMaterial]s to a [GridMap]. +## Should match the size of the [member generator]'s [member GaeaGraph.layers] array. Will +## try to match any generated layers and render it using the corresponding [GridMap]. +@export var grid_maps: Array[GridMap] = [] + ## The [GridMap] this will try to render on. ## @deprecated: Use [member grid_maps] instead var gridmap: GridMap -## Should match the size of the [member generator]'s [member GaeaGraph.layers] array. Will -## try to match any generated layers and render it using the corresponding [GridMap]. -@export var grid_maps: Array[GridMap] = [] ## Used to migrate gridmap reference func _enter_tree() -> void: diff --git a/addons/gaea/nodes/renderers/renderer.gd b/addons/gaea/nodes/renderers/renderer.gd index bdc577fba..077d7e920 100644 --- a/addons/gaea/nodes/renderers/renderer.gd +++ b/addons/gaea/nodes/renderers/renderer.gd @@ -50,13 +50,13 @@ func _connect_signals() -> void: func render(grid: GaeaGrid) -> void: _render(grid) render_finished.emit() - + ## Public version of [method _reset]. func reset() -> void: _reset() render_reset.emit() - + ## Public version of [method _erase_area]. func erase_area(area: AABB) -> void: diff --git a/addons/gaea/resources/gaea_graph.gd b/addons/gaea/resources/gaea_graph.gd index 2cf04ccea..21d3516f9 100644 --- a/addons/gaea/resources/gaea_graph.gd +++ b/addons/gaea/resources/gaea_graph.gd @@ -4,8 +4,6 @@ class_name GaeaGraph extends Resource ## Resource that holds the saved data for a Gaea graph. -## Current save version used for [GaeaGraphMigration]. -const CURRENT_SAVE_VERSION := 4 ## Emitted when the size of [member layers] is changed, or when one of its values is changed. signal layer_count_modified @@ -24,6 +22,9 @@ enum NodeType { FRAME } +## Current save version used for [GaeaGraphMigration]. +const CURRENT_SAVE_VERSION := 4 + ## [GaeaLayer]s as seen in the Output node in the graph. Can be used ## to allow more than one [GaeaMaterial] in a single tile. @export var layers: Array[GaeaLayer] = [GaeaLayer.new()] : @@ -31,50 +32,55 @@ enum NodeType { layers = value layer_count_modified.emit() emit_changed() + @export_group("Debug") ## Selection of what to print in the Output console during generation. See [enum Log]. @export_flags("Execute", "Traverse", "Data", "Args") var logging:int = Log.NONE + +## The current save version, used for migrating checks. +@export_storage var save_version: int = -1 ## List of all connections between nodes. They're saved with the format ## "from_node-from_port-to_node-to_port" (ex.: 1-0-2-1). That format ## can be converted into a connections dictionary using various methods in this class.[br] ## [br][color=yellow][b]Warning:[/b][/color] Setting this directly can break your saved graph. @export_storage var _connections: Array[StringName] +## Saved data for each [GaeaNodeResource] such as position in the graph and changed arguments. +## [br][color=yellow][b]Warning:[/b][/color] Setting this directly can break your saved graph. +@export_storage var _node_data: Dictionary[int, Dictionary] +## List of parameters created with [GaeaNodeParameter]. +## [br][color=yellow][b]Warning:[/b][/color] Setting this directly can break your saved graph. +## Use [method set_parameter] instead. +@export_storage var _parameters: Dictionary[StringName, Variant] : get = get_parameter_list + ## @deprecated: Kept for migration of old save data. var connections: Array[Dictionary] ## @deprecated: Kept for migration of old save data. var resource_uids: Array[String] ## @deprecated: Kept for migration of old save data. var resources: Array[GaeaNodeResource] -## Used during generation to keep track of node resources. -var _resources: Dictionary[int, GaeaNodeResource] -## Saved data for each [GaeaNodeResource] such as position in the graph and changed arguments. -## [br][color=yellow][b]Warning:[/b][/color] Setting this directly can break your saved graph. -@export_storage var _node_data: Dictionary[int, Dictionary] ## @deprecated: Kept for migration of old save data. var node_data: Array[Dictionary] -## List of parameters created with [GaeaNodeParameter]. -## [br][color=yellow][b]Warning:[/b][/color] Setting this directly can break your saved graph. -## Use [method set_parameter] instead. -@export_storage var _parameters: Dictionary[StringName, Variant] : get = get_parameter_list ## @deprecated: Kept for migration of old save data. var parameters: Dictionary[StringName, Variant] ## @deprecated: Kept for migration of old save data. var other: Dictionary -## The current save version, used for migrating checks. -@export_storage var save_version: int = -1 + ## The graph's [member GraphEdit.scroll_offset]. Only saved ## in the current session. var scroll_offset: Vector2 = Vector2(NAN, NAN) ## The graph's [member GraphEdit.zoom]. Only saved ## in the current session. var zoom: float = 1.0 - ## The currently related generator. var generator: GaeaGenerator ## Cache used during generation to avoid recalculating data unnecessarily. ## The inner dictionary keys are the slot output port names, and the values are the cached data. var cache: Dictionary[GaeaNodeResource, Dictionary] = {} +## Used during generation to keep track of node resources. +var _resources: Dictionary[int, GaeaNodeResource] + + func _init() -> void: resource_local_to_scene = true @@ -209,11 +215,11 @@ func get_ids() -> Array[int]: ## Returns an available id. func get_next_available_id() -> int: - var _ids := get_ids() - var _next_id := _ids.size() - while _next_id in _ids: - _next_id += 1 - return _next_id + var ids := get_ids() + var next_id := ids.size() + while next_id in ids: + next_id += 1 + return next_id ## Attempts to connect the specified nodes and ports. If the connection already exists or is invalid, diff --git a/addons/gaea/resources/gaea_graph_migration.gd b/addons/gaea/resources/gaea_graph_migration.gd index 5f8f0c66e..54f4e9a92 100644 --- a/addons/gaea/resources/gaea_graph_migration.gd +++ b/addons/gaea/resources/gaea_graph_migration.gd @@ -50,6 +50,7 @@ static func _process_migration(data: GaeaGraph, node_map: Dictionary[String, Var ## Migrate data from rework [url=https://github.com/gaea-godot/gaea/pull/344]#344[/url]. static func _migration_step_from_beta(data: GaeaGraph): + #gdlint:disable = max-line-length var node_map: Dictionary[String, Variant] = { "bbkdvyxkj2slo": "dol7xviglksx4", #output_node_resource.tres "kdn03ei2yp6e": "bgqqucap4kua4", #reroute_node_resource.tres @@ -136,6 +137,7 @@ static func _migration_step_from_beta(data: GaeaGraph): "cgd05tlepxucw": ["bclwjwmoudxkh", {&"enums": [GaeaNodeVectorBase.VectorType.VECTOR2, GaeaNodeVectorOp.Operation.DIVIDE]}], #root/vector/operations/divide_vector2.tres "hut3x2e74y85": ["bclwjwmoudxkh", {&"enums": [GaeaNodeVectorBase.VectorType.VECTOR3, GaeaNodeVectorOp.Operation.DIVIDE]}], #root/vector/operations/divide_vector3.tres } + #gdlint:enable = max-line-length _process_migration(data, node_map, 2) @@ -152,20 +154,20 @@ static func _migration_step_material_merge(data: GaeaGraph): static func _migration_step_node_ids(data: GaeaGraph): if not data.node_data.is_empty(): for idx in data.node_data.size(): - var _node_data = data.node_data[idx] - var _resource: GaeaNodeResource = load(data.resource_uids[idx]).new() - var _position: Vector2 = _node_data.get("position", Vector2.ZERO) - data.add_node(_resource, _position, idx) - data.set_node_data_value(idx, &"salt", _node_data.get(&"salt", data.get_node_data(idx)[&"salt"])) - for arg_name: StringName in _node_data.get(&"arguments", {}): - var _value: Variant = _node_data.get(&"arguments").get(arg_name) - data.set_node_argument(idx, arg_name, _value) + var node_data = data.node_data[idx] + var resource: GaeaNodeResource = load(data.resource_uids[idx]).new() + var position: Vector2 = node_data.get("position", Vector2.ZERO) + data.add_node(resource, position, idx) + data.set_node_data_value(idx, &"salt", node_data.get(&"salt", data.get_node_data(idx)[&"salt"])) + for arg_name: StringName in node_data.get(&"arguments", {}): + var value: Variant = node_data.get(&"arguments").get(arg_name) + data.set_node_argument(idx, arg_name, value) - for enum_idx: int in _node_data.get(&"enums", []).size(): - data.set_node_enum(idx, enum_idx, _node_data.get(&"enums")[enum_idx]) + for enum_idx: int in node_data.get(&"enums", []).size(): + data.set_node_enum(idx, enum_idx, node_data.get(&"enums")[enum_idx]) - if _node_data.has("type"): - data.set_node_data_value(idx, &"reroute_type", _node_data.get("type")) + if node_data.has("type"): + data.set_node_data_value(idx, &"reroute_type", node_data.get("type")) if not data.connections.is_empty(): for connection in data.connections: @@ -181,19 +183,19 @@ static func _migration_step_node_ids(data: GaeaGraph): data.connections.clear() data.parameters.clear() - var _frames: Dictionary[int, Dictionary] + var frames: Dictionary[int, Dictionary] for frame_data: Dictionary in data.other.get(&"frames", []): - var _frame_id: int = data.add_frame(frame_data[&"position"]) - data.set_node_data_value(_frame_id, &"tint_color_enabled", frame_data.get(&"tint_color_enabled", false)) - data.set_node_data_value(_frame_id, &"tint_color", frame_data.get(&"tint_color", Color("4d4d4dbf"))) - data.set_node_data_value(_frame_id, &"autoshrink", frame_data.get(&"autoshrink", true)) - data.set_node_data_value(_frame_id, &"title", frame_data.get(&"title", "Title")) - _frames[_frame_id] = frame_data + var frame_id: int = data.add_frame(frame_data[&"position"]) + data.set_node_data_value(frame_id, &"tint_color_enabled", frame_data.get(&"tint_color_enabled", false)) + data.set_node_data_value(frame_id, &"tint_color", frame_data.get(&"tint_color", Color("4d4d4dbf"))) + data.set_node_data_value(frame_id, &"autoshrink", frame_data.get(&"autoshrink", true)) + data.set_node_data_value(frame_id, &"title", frame_data.get(&"title", "Title")) + frames[frame_id] = frame_data - for frame_id in _frames.keys(): - var _frame_data := _frames[frame_id] - for attached_name: StringName in _frame_data.get(&"attached"): + for frame_id in frames.keys(): + var frame_data := frames[frame_id] + for attached_name: StringName in frame_data.get(&"attached"): var node_data_idx: int = data.node_data.find_custom( func(node_data: Dictionary): return node_data.get(&"name", &"") == attached_name ) @@ -201,12 +203,12 @@ static func _migration_step_node_ids(data: GaeaGraph): var id: int = data._node_data.find_key(data._node_data.values()[node_data_idx]) data.attach_node_to_frame(id, frame_id) else: - var _frame_data_idx: int = _frames.values().find_custom( + var frame_data_idx: int = frames.values().find_custom( func(node_data: Dictionary): return node_data.get(&"name", &"") == attached_name ) - var _other_frame_id: int = _frames.keys()[_frame_data_idx] - if _other_frame_id != -1: - data.attach_node_to_frame(_other_frame_id, frame_id) + var other_frame_id: int = frames.keys()[frame_data_idx] + if other_frame_id != -1: + data.attach_node_to_frame(other_frame_id, frame_id) data.other.clear() data.save_version = 4 diff --git a/addons/gaea/resources/gaea_value.gd b/addons/gaea/resources/gaea_value.gd index a19b36fb6..62c430a57 100644 --- a/addons/gaea/resources/gaea_value.gd +++ b/addons/gaea/resources/gaea_value.gd @@ -1,5 +1,6 @@ @tool -class_name GaeaValue extends RefCounted +class_name GaeaValue +extends RefCounted ## Holds information about value types in Gaea. ## ## @tutorial(Anatomy of a Graph#Slot Types): https://gaea-godot.github.io/gaea-docs/#/2.0/tutorials/anatomy-of-a-graph?id=slot-types @@ -118,7 +119,8 @@ static func from_variant_type(type: Variant.Type, _hint: PropertyHint = PROPERTY TYPE_OBJECT: if hint_string == "GaeaMaterial": return Type.MATERIAL - elif hint_string.begins_with("Texture"): + + if hint_string.begins_with("Texture"): return Type.TEXTURE return Type.NULL @@ -230,7 +232,8 @@ static func get_default_slot_icon(type: Type) -> Texture2D: return load("uid://yo87adchyr3w") Type.MAP: return load("uid://d2rmsal7c6sdi") - return load("uid://dqob6v3dudlri") + push_warning("No slot icon found for type %s" % type) + return null static func get_editor_for_type(for_type: GaeaValue.Type) -> PackedScene: diff --git a/addons/gaea/resources/gaea_value_cast.gd b/addons/gaea/resources/gaea_value_cast.gd index 90b00bd95..7a89e649b 100644 --- a/addons/gaea/resources/gaea_value_cast.gd +++ b/addons/gaea/resources/gaea_value_cast.gd @@ -1,5 +1,6 @@ @tool -class_name GaeaValueCast extends RefCounted +class_name GaeaValueCast +extends RefCounted ## List of casting methods, the first Dictionary key is "from type" and the second is "to type" ## and the value is the transform [Callable]. diff --git a/addons/gaea/resources/materials/data/tilemap_material.gd b/addons/gaea/resources/materials/data/tilemap_material.gd index 18e08ca5f..e47146379 100644 --- a/addons/gaea/resources/materials/data/tilemap_material.gd +++ b/addons/gaea/resources/materials/data/tilemap_material.gd @@ -4,9 +4,13 @@ extends GaeaMaterial ## Resource used to tell the [TileMapGaeaRenderer] which tile from a [TileMapLayer] to place. enum Type { - SINGLE_CELL, ## Tile is just a single cell in the TileMap. Requires a [param source_id] and a [param atlas_coord]. Can optionally be an [param alternative_tile]. - TERRAIN, ## Tile is a terrain from a terrain set. Allows for autotiling. Requires a [param terrain_set] and a [param terrain] - PATTERN ## Tile is a pattern of cell. Requires a [param pattern_index] and a [param pattern_offset]. + ## Tile is just a single cell in the TileMap. + ## Requires a [param source_id] and a [param atlas_coord]. Can optionally be an [param alternative_tile]. + SINGLE_CELL, + ## Tile is a terrain from a terrain set. Allows for autotiling. Requires a [param terrain_set] and a [param terrain] + TERRAIN, + ## Tile is a pattern of cell. Requires a [param pattern_index] and a [param pattern_offset]. + PATTERN } ## Determines how the [TileMapGaeaRenderer] uses this material. diff --git a/addons/gaea/resources/materials/gaea_material.gd b/addons/gaea/resources/materials/gaea_material.gd index 849cc419d..62328d754 100644 --- a/addons/gaea/resources/materials/gaea_material.gd +++ b/addons/gaea/resources/materials/gaea_material.gd @@ -29,7 +29,8 @@ func is_sampled() -> bool: ## Whether or not this material is sampled for each cell. -@abstract func _is_sampled() -> bool +@abstract +func _is_sampled() -> bool ## Public version of [method _is_data]. Prefer overriding that method instead of this one. @@ -38,7 +39,8 @@ func is_data() -> bool: ## Whether or not this material is a valid data material for the renderer. -@abstract func _is_data() -> bool +@abstract +func _is_data() -> bool ## Public version of [method _get_sampled_resource]. Prefer overriding that method instead of this one. diff --git a/scenes/walker_demo/floor_walker.tres b/scenes/walker_demo/floor_walker.tres index f82754918..f1bbc1d82 100644 --- a/scenes/walker_demo/floor_walker.tres +++ b/scenes/walker_demo/floor_walker.tres @@ -115,6 +115,7 @@ metadata/_custom_type_script = "uid://3qsmwhn2sk47" resource_local_to_scene = true script = ExtResource("5_mui55") layers = Array[ExtResource("2_mfpnn")]([SubResource("Resource_nr2x3"), SubResource("Resource_entu7"), SubResource("Resource_q5q5d")]) +save_version = 4 _connections = Array[StringName]([&"4-0-2-1", &"23-0-21-1", &"28-0-21-0", &"31-0-25-1", &"25-0-27-0", &"30-0-6-1", &"26-0-7-1", &"29-0-15-1", &"15-0-16-0", &"27-0-5-1", &"22-0-5-2", &"8-0-25-0", &"9-0-8-0", &"9-0-7-0", &"10-0-15-0", &"11-0-12-0", &"12-0-5-0", &"24-0-13-0", &"2-0-11-0", &"3-0-24-0", &"3-0-2-0", &"14-0-22-0", &"16-0-22-1", &"21-0-22-2", &"9-0-1-0", &"1-0-6-0", &"13-0-9-0", &"7-0-27-1", &"6-0-27-2", &"20-0-0-1", &"0-0-14-0", &"17-0-18-0", &"18-0-19-0", &"19-0-0-0", &"3-0-17-0", &"18-0-28-0", &"13-0-10-0"]) _node_data = Dictionary[int, Dictionary]({ 0: { @@ -504,7 +505,6 @@ _parameters = Dictionary[StringName, Variant]({ "value": SubResource("Resource_kk1e5") } }) -save_version = 4 Chest = SubResource("Resource_j6vep") FloorMaterial = SubResource("Resource_e1h74") SpikyVegetation = SubResource("Resource_y3srg") diff --git a/testing/rendering/gridmap_test_scene.tscn b/testing/rendering/gridmap_test_scene.tscn index 0143391f7..07c337867 100644 --- a/testing/rendering/gridmap_test_scene.tscn +++ b/testing/rendering/gridmap_test_scene.tscn @@ -29,6 +29,7 @@ metadata/_custom_type_script = "uid://3qsmwhn2sk47" resource_local_to_scene = true script = ExtResource("5_3nkuh") layers = Array[ExtResource("3_jjey7")]([SubResource("Resource_yypbs"), SubResource("Resource_6wvsa")]) +save_version = 4 _connections = Array[StringName]([&"1-0-2-0", &"1-0-3-0", &"5-0-2-1", &"4-0-3-1", &"3-0-0-1", &"2-0-0-0"]) _node_data = Dictionary[int, Dictionary]({ 0: { @@ -109,7 +110,6 @@ _parameters = Dictionary[StringName, Variant]({ "value": SubResource("Resource_hwmwi") } }) -save_version = 4 [sub_resource type="BoxMesh" id="BoxMesh_ipl51"] diff --git a/testing/rendering/tilemap_test_scene.tscn b/testing/rendering/tilemap_test_scene.tscn index 599a2b8ff..12e749a08 100644 --- a/testing/rendering/tilemap_test_scene.tscn +++ b/testing/rendering/tilemap_test_scene.tscn @@ -30,6 +30,7 @@ metadata/_custom_type_script = "uid://3qsmwhn2sk47" resource_local_to_scene = true script = ExtResource("5_kmg7b") layers = Array[ExtResource("3_frm4e")]([SubResource("Resource_yypbs"), SubResource("Resource_6wvsa")]) +save_version = 4 _connections = Array[StringName]([&"1-0-2-0", &"1-0-3-0", &"4-0-2-1", &"5-0-3-1", &"2-0-0-0", &"3-0-0-1"]) _node_data = Dictionary[int, Dictionary]({ 0: { @@ -47,10 +48,12 @@ _node_data = Dictionary[int, Dictionary]({ }, 2: { &"arguments": { +&"material": null, &"range": { "max": 1.0, "min": 0.5 -} +}, +&"reference_data": Dictionary[Vector3i, float]({}) }, &"position": Vector2(-500, -180), &"salt": 3380315837, @@ -59,10 +62,12 @@ _node_data = Dictionary[int, Dictionary]({ }, 3: { &"arguments": { +&"material": null, &"range": { "max": 0.5, "min": 0.0 -} +}, +&"reference_data": Dictionary[Vector3i, float]({}) }, &"position": Vector2(-500, 80), &"salt": 3647513594, @@ -106,7 +111,6 @@ _parameters = Dictionary[StringName, Variant]({ "value": SubResource("Resource_cxykr") } }) -save_version = 4 [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ljnpl"] texture = ExtResource("7_q3jyc")