diff options
author | fabriceci <fabricecipolla@gmail.com> | 2021-10-11 11:30:59 +0200 |
---|---|---|
committer | jmb462 <jmb462@gmail.com> | 2022-01-02 21:52:09 +0100 |
commit | 9d5b80705912d85c3c7301ac0ea0afbf9372a660 (patch) | |
tree | e9528ac06fcfc29bc43846713d1c3ddb94becc22 /modules/gdscript/editor_templates | |
parent | 28174d531b7128f0281fc2b88da2f4962fd3513e (diff) |
Improve editor template workflow
Co-Authored-By: jmb462 <jmb462@gmail.com>
Diffstat (limited to 'modules/gdscript/editor_templates')
7 files changed, 109 insertions, 0 deletions
diff --git a/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd b/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd new file mode 100644 index 0000000000..0824d894c5 --- /dev/null +++ b/modules/gdscript/editor_templates/CharacterBody2D/basic_movement.gd @@ -0,0 +1,29 @@ +# meta-description: Classic movement for gravity games (platformer, ...) + +extends _BASE_ + +const SPEED: float = 300.0 +const JUMP_FORCE: float = -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(): + motion_velocity.y += gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + motion_velocity.y = JUMP_FORCE + + # 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: + motion_velocity.x = direction * SPEED + else: + motion_velocity.x = move_toward(motion_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 new file mode 100644 index 0000000000..ce6d67ae84 --- /dev/null +++ b/modules/gdscript/editor_templates/CharacterBody3D/basic_movement.gd @@ -0,0 +1,32 @@ +# meta-description: Classic movement for gravity games (FPS, TPS, ...) + +extends _BASE_ + +const SPEED: float = 5.0 +const JUMP_FORCE: float = 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(): + motion_velocity.y -= gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + motion_velocity.y = JUMP_FORCE + + # 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: + motion_velocity.x = direction.x * SPEED + motion_velocity.z = direction.z * SPEED + else: + motion_velocity.x = move_toward(motion_velocity.x, 0, SPEED) + motion_velocity.z = move_toward(motion_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 new file mode 100644 index 0000000000..8614bb8b17 --- /dev/null +++ b/modules/gdscript/editor_templates/EditorPlugin/plugin.gd @@ -0,0 +1,11 @@ +# 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 new file mode 100644 index 0000000000..fdb174c7ed --- /dev/null +++ b/modules/gdscript/editor_templates/EditorScript/basic_editor_script.gd @@ -0,0 +1,7 @@ +# meta-description: Basic editor script template +@tool +extends EditorScript + +func _run() -> void: + # Called when the script is executed (using File -> Run in Script Editor). + pass diff --git a/modules/gdscript/editor_templates/Node/default.gd b/modules/gdscript/editor_templates/Node/default.gd new file mode 100644 index 0000000000..ee5c0b99cc --- /dev/null +++ b/modules/gdscript/editor_templates/Node/default.gd @@ -0,0 +1,11 @@ +# 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 new file mode 100644 index 0000000000..387786b0a4 --- /dev/null +++ b/modules/gdscript/editor_templates/Object/empty.gd @@ -0,0 +1,3 @@ +# meta-description: Empty template suitable for all Objects + +extends _BASE_ diff --git a/modules/gdscript/editor_templates/SCsub b/modules/gdscript/editor_templates/SCsub new file mode 100644 index 0000000000..2266ef2d01 --- /dev/null +++ b/modules/gdscript/editor_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)]) |