From c9b75431f313fae16e9f4c9e60d7f5eaed0aaec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 28 Mar 2022 15:48:38 +0200 Subject: Refactor GDScript/C# script templates logic to be editor-only Not a full refactor as it still goes through ScriptLanguage so it's hacky, but at least it can now compile without this. --- modules/gdscript/SCsub | 5 ++- .../CharacterBody2D/basic_movement.gd | 30 +++++++++++++ .../CharacterBody3D/basic_movement.gd | 33 ++++++++++++++ .../editor/script_templates/EditorPlugin/plugin.gd | 13 ++++++ .../EditorScript/basic_editor_script.gd | 8 ++++ .../editor/script_templates/Node/default.gd | 13 ++++++ .../editor/script_templates/Object/empty.gd | 3 ++ modules/gdscript/editor/script_templates/SCsub | 16 +++++++ .../VisualShaderNodeCustom/basic.gd | 50 ++++++++++++++++++++++ .../CharacterBody2D/basic_movement.gd | 30 ------------- .../CharacterBody3D/basic_movement.gd | 33 -------------- .../editor_templates/EditorPlugin/plugin.gd | 13 ------ .../EditorScript/basic_editor_script.gd | 8 ---- modules/gdscript/editor_templates/Node/default.gd | 13 ------ modules/gdscript/editor_templates/Object/empty.gd | 3 -- modules/gdscript/editor_templates/SCsub | 16 ------- .../VisualShaderNodeCustom/basic.gd | 50 ---------------------- modules/gdscript/gdscript_editor.cpp | 19 +++----- 18 files changed, 176 insertions(+), 180 deletions(-) create mode 100644 modules/gdscript/editor/script_templates/CharacterBody2D/basic_movement.gd create mode 100644 modules/gdscript/editor/script_templates/CharacterBody3D/basic_movement.gd create mode 100644 modules/gdscript/editor/script_templates/EditorPlugin/plugin.gd create mode 100644 modules/gdscript/editor/script_templates/EditorScript/basic_editor_script.gd create mode 100644 modules/gdscript/editor/script_templates/Node/default.gd create mode 100644 modules/gdscript/editor/script_templates/Object/empty.gd create mode 100644 modules/gdscript/editor/script_templates/SCsub create mode 100644 modules/gdscript/editor/script_templates/VisualShaderNodeCustom/basic.gd delete mode 100644 modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd delete mode 100644 modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd delete mode 100644 modules/gdscript/editor_templates/EditorPlugin/plugin.gd delete mode 100644 modules/gdscript/editor_templates/EditorScript/basic_editor_script.gd delete mode 100644 modules/gdscript/editor_templates/Node/default.gd delete mode 100644 modules/gdscript/editor_templates/Object/empty.gd delete mode 100644 modules/gdscript/editor_templates/SCsub delete mode 100644 modules/gdscript/editor_templates/VisualShaderNodeCustom/basic.gd (limited to 'modules/gdscript') diff --git a/modules/gdscript/SCsub b/modules/gdscript/SCsub index c6121ec7fe..2f507db548 100644 --- a/modules/gdscript/SCsub +++ b/modules/gdscript/SCsub @@ -10,6 +10,8 @@ env_gdscript.add_source_files(env.modules_sources, "*.cpp") if env["tools"]: env_gdscript.add_source_files(env.modules_sources, "./editor/*.cpp") + SConscript("editor/script_templates/SCsub") + # Those two modules are required for the language server protocol if env["module_jsonrpc_enabled"] and env["module_websocket_enabled"]: env_gdscript.add_source_files(env.modules_sources, "./language_server/*.cpp") @@ -18,8 +20,7 @@ if env["tools"]: # in regular builds where all modules are enabled. env_gdscript.Append(CPPDEFINES=["GDSCRIPT_NO_LSP"]) + if env["tests"]: env_gdscript.Append(CPPDEFINES=["TESTS_ENABLED"]) env_gdscript.add_source_files(env.modules_sources, "./tests/*.cpp") - -SConscript("editor_templates/SCsub") diff --git a/modules/gdscript/editor/script_templates/CharacterBody2D/basic_movement.gd b/modules/gdscript/editor/script_templates/CharacterBody2D/basic_movement.gd new file mode 100644 index 0000000000..a379d915a9 --- /dev/null +++ b/modules/gdscript/editor/script_templates/CharacterBody2D/basic_movement.gd @@ -0,0 +1,30 @@ +# meta-description: Classic movement for gravity games (platformer, ...) + +extends _BASE_ + + +const SPEED = 300.0 +const JUMP_VELOCITY = -400.0 + +# Get the gravity from the project settings to be synced with RigidDynamicBody nodes. +var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") + + +func _physics_process(delta: float) -> void: + # Add the gravity. + if not is_on_floor(): + velocity.y += gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var direction := Input.get_axis("ui_left", "ui_right") + if direction: + velocity.x = direction * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + + move_and_slide() diff --git a/modules/gdscript/editor/script_templates/CharacterBody3D/basic_movement.gd b/modules/gdscript/editor/script_templates/CharacterBody3D/basic_movement.gd new file mode 100644 index 0000000000..360b199e56 --- /dev/null +++ b/modules/gdscript/editor/script_templates/CharacterBody3D/basic_movement.gd @@ -0,0 +1,33 @@ +# meta-description: Classic movement for gravity games (FPS, TPS, ...) + +extends _BASE_ + + +const SPEED = 5.0 +const JUMP_VELOCITY = 4.5 + +# Get the gravity from the project settings to be synced with RigidDynamicBody nodes. +var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") + + +func _physics_process(delta: float) -> void: + # Add the gravity. + if not is_on_floor(): + velocity.y -= gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") + var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + if direction: + velocity.x = direction.x * SPEED + velocity.z = direction.z * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + velocity.z = move_toward(velocity.z, 0, SPEED) + + move_and_slide() diff --git a/modules/gdscript/editor/script_templates/EditorPlugin/plugin.gd b/modules/gdscript/editor/script_templates/EditorPlugin/plugin.gd new file mode 100644 index 0000000000..b27b3e5655 --- /dev/null +++ b/modules/gdscript/editor/script_templates/EditorPlugin/plugin.gd @@ -0,0 +1,13 @@ +# meta-description: Basic plugin template +@tool +extends EditorPlugin + + +func _enter_tree() -> void: + # Initialization of the plugin goes here. + pass + + +func _exit_tree() -> void: + # Clean-up of the plugin goes here. + pass diff --git a/modules/gdscript/editor/script_templates/EditorScript/basic_editor_script.gd b/modules/gdscript/editor/script_templates/EditorScript/basic_editor_script.gd new file mode 100644 index 0000000000..fdb8550d43 --- /dev/null +++ b/modules/gdscript/editor/script_templates/EditorScript/basic_editor_script.gd @@ -0,0 +1,8 @@ +# meta-description: Basic editor script template +@tool +extends EditorScript + + +# Called when the script is executed (using File -> Run in Script Editor). +func _run() -> void: + pass diff --git a/modules/gdscript/editor/script_templates/Node/default.gd b/modules/gdscript/editor/script_templates/Node/default.gd new file mode 100644 index 0000000000..cb96a21537 --- /dev/null +++ b/modules/gdscript/editor/script_templates/Node/default.gd @@ -0,0 +1,13 @@ +# meta-description: Base template for Node with default Godot cycle methods + +extends _BASE_ + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass diff --git a/modules/gdscript/editor/script_templates/Object/empty.gd b/modules/gdscript/editor/script_templates/Object/empty.gd new file mode 100644 index 0000000000..387786b0a4 --- /dev/null +++ b/modules/gdscript/editor/script_templates/Object/empty.gd @@ -0,0 +1,3 @@ +# meta-description: Empty template suitable for all Objects + +extends _BASE_ diff --git a/modules/gdscript/editor/script_templates/SCsub b/modules/gdscript/editor/script_templates/SCsub new file mode 100644 index 0000000000..2266ef2d01 --- /dev/null +++ b/modules/gdscript/editor/script_templates/SCsub @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +Import("env") + +import editor.template_builders as build_template_gd + +env["BUILDERS"]["MakeGDTemplateBuilder"] = Builder( + action=env.Run(build_template_gd.make_templates, "Generating GDScript templates header."), + suffix=".h", + src_suffix=".gd", +) + +# Template files +templates_sources = Glob("*/*.gd") + +env.Alias("editor_template_gd", [env.MakeGDTemplateBuilder("templates.gen.h", templates_sources)]) diff --git a/modules/gdscript/editor/script_templates/VisualShaderNodeCustom/basic.gd b/modules/gdscript/editor/script_templates/VisualShaderNodeCustom/basic.gd new file mode 100644 index 0000000000..283a95d3b4 --- /dev/null +++ b/modules/gdscript/editor/script_templates/VisualShaderNodeCustom/basic.gd @@ -0,0 +1,50 @@ +# meta-description: Visual shader's node plugin template + +@tool +class_name VisualShaderNode_CLASS_ +extends _BASE_ + + +func _get_name() -> String: + return "_CLASS_" + + +func _get_category() -> String: + return "" + + +func _get_description() -> String: + return "" + + +func _get_return_icon_type() -> int: + return PORT_TYPE_SCALAR + + +func _get_input_port_count() -> int: + return 0 + + +func _get_input_port_name(port: int) -> String: + return "" + + +func _get_input_port_type(port: int) -> int: + return PORT_TYPE_SCALAR + + +func _get_output_port_count() -> int: + return 1 + + +func _get_output_port_name(port: int) -> String: + return "result" + + +func _get_output_port_type(port: int) -> int: + return PORT_TYPE_SCALAR + + +func _get_code(input_vars: Array[String], output_vars: Array[String], + mode: int, type: int) -> String: + return output_vars[0] + " = 0.0;" diff --git a/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd b/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd deleted file mode 100644 index a379d915a9..0000000000 --- a/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd +++ /dev/null @@ -1,30 +0,0 @@ -# meta-description: Classic movement for gravity games (platformer, ...) - -extends _BASE_ - - -const SPEED = 300.0 -const JUMP_VELOCITY = -400.0 - -# Get the gravity from the project settings to be synced with RigidDynamicBody nodes. -var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") - - -func _physics_process(delta: float) -> void: - # Add the gravity. - if not is_on_floor(): - velocity.y += gravity * delta - - # Handle Jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY - - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var direction := Input.get_axis("ui_left", "ui_right") - if direction: - velocity.x = direction * SPEED - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - - move_and_slide() diff --git a/modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd b/modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd deleted file mode 100644 index 360b199e56..0000000000 --- a/modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd +++ /dev/null @@ -1,33 +0,0 @@ -# meta-description: Classic movement for gravity games (FPS, TPS, ...) - -extends _BASE_ - - -const SPEED = 5.0 -const JUMP_VELOCITY = 4.5 - -# Get the gravity from the project settings to be synced with RigidDynamicBody nodes. -var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity") - - -func _physics_process(delta: float) -> void: - # Add the gravity. - if not is_on_floor(): - velocity.y -= gravity * delta - - # Handle Jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY - - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") - var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() - if direction: - velocity.x = direction.x * SPEED - velocity.z = direction.z * SPEED - else: - velocity.x = move_toward(velocity.x, 0, SPEED) - velocity.z = move_toward(velocity.z, 0, SPEED) - - move_and_slide() diff --git a/modules/gdscript/editor_templates/EditorPlugin/plugin.gd b/modules/gdscript/editor_templates/EditorPlugin/plugin.gd deleted file mode 100644 index b27b3e5655..0000000000 --- a/modules/gdscript/editor_templates/EditorPlugin/plugin.gd +++ /dev/null @@ -1,13 +0,0 @@ -# meta-description: Basic plugin template -@tool -extends EditorPlugin - - -func _enter_tree() -> void: - # Initialization of the plugin goes here. - pass - - -func _exit_tree() -> void: - # Clean-up of the plugin goes here. - pass diff --git a/modules/gdscript/editor_templates/EditorScript/basic_editor_script.gd b/modules/gdscript/editor_templates/EditorScript/basic_editor_script.gd deleted file mode 100644 index fdb8550d43..0000000000 --- a/modules/gdscript/editor_templates/EditorScript/basic_editor_script.gd +++ /dev/null @@ -1,8 +0,0 @@ -# meta-description: Basic editor script template -@tool -extends EditorScript - - -# Called when the script is executed (using File -> Run in Script Editor). -func _run() -> void: - pass diff --git a/modules/gdscript/editor_templates/Node/default.gd b/modules/gdscript/editor_templates/Node/default.gd deleted file mode 100644 index cb96a21537..0000000000 --- a/modules/gdscript/editor_templates/Node/default.gd +++ /dev/null @@ -1,13 +0,0 @@ -# meta-description: Base template for Node with default Godot cycle methods - -extends _BASE_ - - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass diff --git a/modules/gdscript/editor_templates/Object/empty.gd b/modules/gdscript/editor_templates/Object/empty.gd deleted file mode 100644 index 387786b0a4..0000000000 --- a/modules/gdscript/editor_templates/Object/empty.gd +++ /dev/null @@ -1,3 +0,0 @@ -# meta-description: Empty template suitable for all Objects - -extends _BASE_ diff --git a/modules/gdscript/editor_templates/SCsub b/modules/gdscript/editor_templates/SCsub deleted file mode 100644 index 2266ef2d01..0000000000 --- a/modules/gdscript/editor_templates/SCsub +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python - -Import("env") - -import editor.template_builders as build_template_gd - -env["BUILDERS"]["MakeGDTemplateBuilder"] = Builder( - action=env.Run(build_template_gd.make_templates, "Generating GDScript templates header."), - suffix=".h", - src_suffix=".gd", -) - -# Template files -templates_sources = Glob("*/*.gd") - -env.Alias("editor_template_gd", [env.MakeGDTemplateBuilder("templates.gen.h", templates_sources)]) diff --git a/modules/gdscript/editor_templates/VisualShaderNodeCustom/basic.gd b/modules/gdscript/editor_templates/VisualShaderNodeCustom/basic.gd deleted file mode 100644 index 283a95d3b4..0000000000 --- a/modules/gdscript/editor_templates/VisualShaderNodeCustom/basic.gd +++ /dev/null @@ -1,50 +0,0 @@ -# meta-description: Visual shader's node plugin template - -@tool -class_name VisualShaderNode_CLASS_ -extends _BASE_ - - -func _get_name() -> String: - return "_CLASS_" - - -func _get_category() -> String: - return "" - - -func _get_description() -> String: - return "" - - -func _get_return_icon_type() -> int: - return PORT_TYPE_SCALAR - - -func _get_input_port_count() -> int: - return 0 - - -func _get_input_port_name(port: int) -> String: - return "" - - -func _get_input_port_type(port: int) -> int: - return PORT_TYPE_SCALAR - - -func _get_output_port_count() -> int: - return 1 - - -func _get_output_port_name(port: int) -> String: - return "result" - - -func _get_output_port_type(port: int) -> int: - return PORT_TYPE_SCALAR - - -func _get_code(input_vars: Array[String], output_vars: Array[String], - mode: int, type: int) -> String: - return output_vars[0] + " = 0.0;" diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 4a6e1eb497..fd8fcea7b3 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -33,7 +33,6 @@ #include "core/config/engine.h" #include "core/core_constants.h" #include "core/io/file_access.h" -#include "editor_templates/templates.gen.h" #include "gdscript_analyzer.h" #include "gdscript_compiler.h" #include "gdscript_parser.h" @@ -44,6 +43,7 @@ #include "core/config/project_settings.h" #include "editor/editor_file_system.h" #include "editor/editor_settings.h" +#include "editor/script_templates/templates.gen.h" #endif void GDScriptLanguage::get_comment_delimiters(List *p_delimiters) const { @@ -64,8 +64,11 @@ Ref