style: apply gdformat formatting across the entire project

Auto-format all GDScript files using gdformat from gdtoolkit.
This is a baseline formatting pass to ensure consistent style:

- Normalizes indentation and spacing
- Wraps long lines to 100 characters
- Removes trailing whitespace
- Standardizes blank lines between functions

68 files reformatted, 8 files left unchanged (3rd-party addon files
with parse errors excluded).
This commit is contained in:
2026-07-05 23:06:23 +02:00
parent 28a2e42c41
commit 4463e524aa
69 changed files with 2253 additions and 1647 deletions
+121 -78
View File
@@ -3,7 +3,6 @@
@tool
extends EditorPlugin
# Includes
const UI: Script = preload("res://addons/terrain_3d/src/ui.gd")
const RegionGizmo: Script = preload("res://addons/terrain_3d/src/region_gizmo.gd")
@@ -14,7 +13,7 @@ var modifier_ctrl: bool
var modifier_alt: bool
var modifier_shift: bool
var _last_modifiers: int = 0
var _input_mode: int = 0 # -1: camera move, 0: none, 1: operating
var _input_mode: int = 0 # -1: camera move, 0: none, 1: operating
var rmb_release_time: int = 0
var _use_meta: bool = false
@@ -22,26 +21,26 @@ var terrain: Terrain3D
var _last_terrain: Terrain3D
var nav_region: NavigationRegion3D
var debug: int = 0 # Set in _edit()
var debug: int = 0 # Set in _edit()
var editor: Terrain3DEditor
var editor_settings: EditorSettings
var ui: Node # Terrain3DUI see Godot #75388
var ui: Node # Terrain3DUI see Godot #75388
var asset_dock: PanelContainer
var region_gizmo: RegionGizmo
var current_region_position: Vector2
var mouse_global_position: Vector3 = Vector3.ZERO
var godot_editor_window: Window # The Godot Editor window
var godot_editor_window: Window # The Godot Editor window
func _init() -> void:
if OS.get_name() == "macOS":
_use_meta = true
# Get the Godot Editor window. Structure is root:Window/EditorNode/Base Control
godot_editor_window = EditorInterface.get_base_control().get_parent().get_parent()
godot_editor_window.focus_entered.connect(_on_godot_focus_entered)
func _enter_tree() -> void:
editor = Terrain3DEditor.new()
setup_editor_settings()
@@ -77,7 +76,7 @@ func _on_godot_focus_entered() -> void:
## EditorPlugin selection function call chain isn't consistent. Here's the map of calls:
## Assume we handle Terrain3D and NavigationRegion3D
## Assume we handle Terrain3D and NavigationRegion3D
# Click Terrain3D: _handles(Terrain3D), _make_visible(true), _edit(Terrain3D)
# Deselect: _make_visible(false), _edit(null)
# Click other node: _handles(OtherNode)
@@ -89,14 +88,14 @@ func _handles(p_object: Object) -> bool:
return true
elif p_object is NavigationRegion3D and is_instance_valid(_last_terrain):
return true
# Terrain3DObjects requires access to EditorUndoRedoManager. The only way to make sure it
# always has it, is to pass it in here. _edit is NOT called if the node is cut and pasted.
elif p_object is Terrain3DObjects:
p_object.editor_setup(self)
elif p_object is Node3D and p_object.get_parent() is Terrain3DObjects:
p_object.get_parent().editor_setup(self)
return false
@@ -119,7 +118,7 @@ func _edit(p_object: Object) -> void:
_last_terrain = terrain
terrain.set_plugin(self)
terrain.set_editor(editor)
debug = terrain.debug_level
debug = terrain.debug_level
editor.set_terrain(terrain)
region_gizmo.set_node_3d(terrain)
terrain.add_gizmo(region_gizmo)
@@ -144,18 +143,18 @@ func _edit(p_object: Object) -> void:
else:
nav_region = null
func _clear() -> void:
if is_terrain_valid():
if terrain.data.region_map_changed.is_connected(update_region_grid):
terrain.data.region_map_changed.disconnect(update_region_grid)
terrain.clear_gizmos()
terrain = null
editor.set_terrain(null)
ui.clear_picking()
region_gizmo.clear()
@@ -167,13 +166,13 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
if continue_input != AFTER_GUI_INPUT_CUSTOM:
return continue_input
ui.update_decal()
## Setup active camera & viewport
# Always update this for all inputs, as the mouse position can move without
# necessarily being a InputEventMouseMotion object. get_intersection() also
# returns the last frame position, and should be updated more frequently.
# Snap terrain to current camera
# Snap terrain to current camera
terrain.set_camera(p_viewport_camera)
# Detect if viewport is set to half_resolution
@@ -193,19 +192,23 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
var t = -Vector3(0, 1, 0).dot(camera_pos) / Vector3(0, 1, 0).dot(camera_dir)
mouse_global_position = (camera_pos + t * camera_dir)
else:
#Else look for intersection with terrain
#Else look for intersection with terrain
var intersection_point: Vector3 = terrain.get_intersection(camera_pos, camera_dir, true)
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
if intersection_point.z > 3.4e38 or is_nan(intersection_point.y): # max double or nan
return AFTER_GUI_INPUT_PASS
mouse_global_position = intersection_point
## Handle mouse movement
if p_event is InputEventMouseMotion:
if _input_mode != -1: # Not cam rotation
if _input_mode != -1: # Not cam rotation
## Update region highlight
var region_position: Vector2 = ( Vector2(mouse_global_position.x, mouse_global_position.z) \
/ (terrain.get_region_size() * terrain.get_vertex_spacing()) ).floor()
var region_position: Vector2 = (
(
Vector2(mouse_global_position.x, mouse_global_position.z)
/ (terrain.get_region_size() * terrain.get_vertex_spacing())
)
. floor()
)
if current_region_position != region_position:
current_region_position = region_position
update_region_grid()
@@ -216,7 +219,7 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
return AFTER_GUI_INPUT_STOP
return AFTER_GUI_INPUT_PASS
if p_event is InputEventMouseButton and _input_mode > 0:
@@ -226,31 +229,35 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
ui.pick(mouse_global_position)
if not ui.operation_builder or not ui.operation_builder.is_ready():
return AFTER_GUI_INPUT_STOP
if modifier_ctrl and editor.get_tool() == Terrain3DEditor.HEIGHT:
var height: float = terrain.data.get_height(mouse_global_position)
ui.brush_data["height"] = height
ui.tool_settings.set_setting("height", height)
# If adjusting regions
if editor.get_tool() == Terrain3DEditor.REGION:
# Skip regions that already exist or don't
var has_region: bool = terrain.data.has_regionp(mouse_global_position)
var op: int = editor.get_operation()
if ( has_region and op == Terrain3DEditor.ADD) or \
( not has_region and op == Terrain3DEditor.SUBTRACT ):
if (
(has_region and op == Terrain3DEditor.ADD)
or (not has_region and op == Terrain3DEditor.SUBTRACT)
):
return AFTER_GUI_INPUT_STOP
# If an automatic operation is ready to go (e.g. gradient)
if ui.operation_builder and ui.operation_builder.is_ready():
ui.operation_builder.apply_operation(editor, mouse_global_position, p_viewport_camera.rotation.y)
ui.operation_builder.apply_operation(
editor, mouse_global_position, p_viewport_camera.rotation.y
)
return AFTER_GUI_INPUT_STOP
# Mouse clicked, start editing
editor.start_operation(mouse_global_position)
editor.operate(mouse_global_position, p_viewport_camera.rotation.y)
return AFTER_GUI_INPUT_STOP
# _input_apply released, save undo data
elif editor.is_operating():
editor.stop_operation()
@@ -261,66 +268,97 @@ func _forward_3d_gui_input(p_viewport_camera: Camera3D, p_event: InputEvent) ->
func _read_input(p_event: InputEvent = null) -> AfterGUIInput:
## Determine if user is moving camera or applying
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) or \
p_event is InputEventMouseButton and p_event.is_released() and \
p_event.get_button_index() == MOUSE_BUTTON_LEFT:
_input_mode = 1
if (
Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
or (
p_event is InputEventMouseButton
and p_event.is_released()
and p_event.get_button_index() == MOUSE_BUTTON_LEFT
)
):
_input_mode = 1
else:
_input_mode = 0
_input_mode = 0
match get_setting("editors/3d/navigation/navigation_scheme", 0):
2, 1: # Modo, Maya
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
( Input.is_key_pressed(KEY_ALT) and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) ):
_input_mode = -1
if p_event is InputEventMouseButton and p_event.is_released() and \
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
( Input.is_key_pressed(KEY_ALT) and p_event.get_button_index() == MOUSE_BUTTON_LEFT )):
rmb_release_time = Time.get_ticks_msec()
0, _: # Godot
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT) or \
Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
_input_mode = -1
if p_event is InputEventMouseButton and p_event.is_released() and \
( p_event.get_button_index() == MOUSE_BUTTON_RIGHT or \
p_event.get_button_index() == MOUSE_BUTTON_MIDDLE ):
rmb_release_time = Time.get_ticks_msec()
2, 1: # Modo, Maya
if (
Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
or (
Input.is_key_pressed(KEY_ALT)
and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)
)
):
_input_mode = -1
if (
p_event is InputEventMouseButton
and p_event.is_released()
and (
p_event.get_button_index() == MOUSE_BUTTON_RIGHT
or (
Input.is_key_pressed(KEY_ALT)
and p_event.get_button_index() == MOUSE_BUTTON_LEFT
)
)
):
rmb_release_time = Time.get_ticks_msec()
0, _: # Godot
if (
Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
or Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)
):
_input_mode = -1
if (
p_event is InputEventMouseButton
and p_event.is_released()
and (
p_event.get_button_index() == MOUSE_BUTTON_RIGHT
or p_event.get_button_index() == MOUSE_BUTTON_MIDDLE
)
):
rmb_release_time = Time.get_ticks_msec()
if _input_mode < 0:
# Camera is moving, skip input
return AFTER_GUI_INPUT_PASS
## Determine modifiers pressed
modifier_shift = Input.is_key_pressed(KEY_SHIFT)
# Editor responds to modifier_ctrl so we must register touchscreen Invert
# Editor responds to modifier_ctrl so we must register touchscreen Invert
if _use_meta:
modifier_ctrl = Input.is_key_pressed(KEY_META) || ui.inverted_input
else:
modifier_ctrl = Input.is_key_pressed(KEY_CTRL) || ui.inverted_input
# Keybind enum: Alt,Space,Meta,Capslock
var alt_key: int
match get_setting("terrain3d/config/alt_key_bind", 0):
3: alt_key = KEY_CAPSLOCK
2: alt_key = KEY_META
1: alt_key = KEY_SPACE
0, _: alt_key = KEY_ALT
3:
alt_key = KEY_CAPSLOCK
2:
alt_key = KEY_META
1:
alt_key = KEY_SPACE
0, _:
alt_key = KEY_ALT
modifier_alt = Input.is_key_pressed(alt_key)
var current_mods: int = int(modifier_shift) | int(modifier_ctrl) << 1 | int(modifier_alt) << 2
## Process Hotkeys
if p_event is InputEventKey and \
current_mods == 0 and \
p_event.is_pressed() and \
not p_event.is_echo() and \
consume_hotkey(p_event.keycode):
if (
p_event is InputEventKey
and current_mods == 0
and p_event.is_pressed()
and not p_event.is_echo()
and consume_hotkey(p_event.keycode)
):
# Hotkey found, consume event, and stop input processing
EditorInterface.get_editor_viewport_3d().set_input_as_handled()
return AFTER_GUI_INPUT_STOP
# Brush data is cleared on set_tool, or clicking textures in the asset dock
# Update modifiers if changed or missing
if _last_modifiers != current_mods or not ui.brush_data.has("modifier_shift"):
if _last_modifiers != current_mods or not ui.brush_data.has("modifier_shift"):
_last_modifiers = current_mods
ui.brush_data["modifier_shift"] = modifier_shift
ui.brush_data["modifier_ctrl"] = modifier_ctrl
@@ -337,7 +375,7 @@ func consume_hotkey(keycode: int) -> bool:
KEY_1, KEY_KP_1:
terrain.material.set_show_region_grid(!terrain.material.get_show_region_grid())
KEY_2, KEY_KP_2:
terrain.label_distance = 4096.0 if is_zero_approx(terrain.label_distance) else 0.0
terrain.label_distance = 4096.0 if is_zero_approx(terrain.label_distance) else 0.0
KEY_3, KEY_KP_3:
terrain.material.set_show_contours(!terrain.material.get_show_contours())
KEY_4, KEY_KP_4:
@@ -384,10 +422,10 @@ func update_region_grid() -> void:
region_gizmo.region_position = current_region_position
region_gizmo.region_size = terrain.get_region_size() * terrain.get_vertex_spacing()
region_gizmo.grid = terrain.get_data().get_region_locations()
terrain.update_gizmos()
return
region_gizmo.show_rect = false
region_gizmo.region_size = 1024
region_gizmo.grid = [Vector2i.ZERO]
@@ -396,7 +434,7 @@ func update_region_grid() -> void:
func _on_scene_changed(scene_root: Node) -> void:
if not scene_root:
return
for node in scene_root.find_children("", "Terrain3DObjects"):
node.editor_setup(self)
@@ -426,10 +464,15 @@ func is_terrain_valid(p_terrain: Terrain3D = null) -> bool:
func is_selected() -> bool:
var selected: Array[Node] = EditorInterface.get_selection().get_selected_nodes()
for node in selected:
if ( is_instance_valid(_last_terrain) and node.get_instance_id() == _last_terrain.get_instance_id() ) or \
node is Terrain3D:
return true
return false
if (
(
is_instance_valid(_last_terrain)
and node.get_instance_id() == _last_terrain.get_instance_id()
)
or node is Terrain3D
):
return true
return false
func select_terrain() -> void:
@@ -453,7 +496,7 @@ func setup_editor_settings() -> void:
"hint_string": "Alt,Space,Meta,Capslock"
}
editor_settings.add_property_info(property_info)
func set_setting(p_str: String, p_value: Variant) -> void:
editor_settings.set_setting(p_str, p_value)