Godot test scene addon

This commit is contained in:
Marco 2025-04-17 15:47:32 +02:00
commit 594406243d
6 changed files with 174 additions and 0 deletions

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="16"
height="16"
version="1.1"
id="svg1"
sodipodi:docname="icon.svg"
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs1" />
<sodipodi:namedview
id="namedview1"
pagecolor="#505050"
bordercolor="#ffffff"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#505050"
inkscape:zoom="40.717089"
inkscape:cx="6.8767196"
inkscape:cy="10.22912"
inkscape:window-width="1920"
inkscape:window-height="974"
inkscape:window-x="-11"
inkscape:window-y="-11"
inkscape:window-maximized="1"
inkscape:current-layer="svg1" />
<path
id="path1"
style="stroke:none;fill:#e0e0e0;fill-opacity:1"
d="M 14.564453 2 L 12.320312 2.328125 L 13.138672 4.2285156 L 14.853516 3.9785156 L 14.564453 2 z M 10.341797 2.6152344 L 8.3632812 2.9042969 L 9.1816406 4.8066406 L 11.160156 4.5175781 L 10.341797 2.6152344 z M 6.3828125 3.1933594 L 4.4042969 3.4824219 L 5.2226562 5.3847656 L 7.2011719 5.0957031 L 6.3828125 3.1933594 z M 2.4257812 3.7714844 L 0.7109375 4.0214844 L 1 6 L 3.2441406 5.671875 L 2.4257812 3.7714844 z M 1 7 L 1 13 A 2 2 0 0 0 3 15 L 15 15 L 15 7 L 1 7 z M 7.4453125 8.1640625 L 8.8359375 8.1640625 L 8.8359375 10.310547 L 10.951172 13.964844 L 5.3183594 13.970703 L 7.4453125 10.275391 L 7.4453125 8.1640625 z " />
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -0,0 +1,37 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://njcc6c8v1kun"
path="res://.godot/imported/icon.svg-d1d1f081d7c5acf717aa1e16720054d7.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/godot_test_scene/icon.svg"
dest_files=["res://.godot/imported/icon.svg-d1d1f081d7c5acf717aa1e16720054d7.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View file

@ -0,0 +1,7 @@
[plugin]
name="Test scene"
description="A simple Godot addon that adds a extra run mode to the editor. This extra mode allows you to run a test scene linked to the current scene your are editing."
author="Douwe Ravers"
version="1.0"
script="plugin.gd"

View file

@ -0,0 +1,25 @@
@tool
extends EditorPlugin
var play_test_button:Button
func _enter_tree() -> void:
add_play_test_scene_button()
func _exit_tree() -> void:
play_test_button.queue_free()
func add_play_test_scene_button()->void:
var play_current_button := search_play_current_button(EditorInterface.get_base_control())
var play_test_button_scene := load("res://addons/godot_test_scene/test_scene_button.tscn") as PackedScene
play_test_button = play_test_button_scene.instantiate()
play_current_button.add_sibling(play_test_button)
func search_play_current_button(node:Node)->Button:
if node is Button and (node as Button).tooltip_text == "Play the edited scene.":
return (node as Button)
for child in node.get_children():
var button := search_play_current_button(child)
if button is Button:
return button as Button
return null

View file

@ -0,0 +1,40 @@
@tool
extends Button
const META_NAME := "test_scene"
func _on_pressed() -> void:
var current_scene := EditorInterface.get_edited_scene_root()
if current_scene.has_meta(META_NAME):
run_test_scene()
else:
show_selection_window("Select test scene path")
func _on_gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton\
and event.pressed\
and event.button_index == MOUSE_BUTTON_RIGHT:
show_selection_window("Select test scene path")
func run_test_scene():
var current_scene := EditorInterface.get_edited_scene_root()
var test_scene_path := current_scene.get_meta(META_NAME)
if ResourceLoader.exists(test_scene_path):
EditorInterface.play_custom_scene(test_scene_path)
else:
current_scene.remove_meta(META_NAME)
show_selection_window("No scene exists at saved path, select new path")
func show_selection_window(message:String):
var file_dialog := FileDialog.new()
file_dialog.mode_overrides_title = true
file_dialog.title = message
file_dialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
file_dialog.filters = ["*.tscn","*.scn"]
file_dialog.connect("file_selected", set_test_scene_path)
EditorInterface.popup_dialog_centered(file_dialog, Vector2i(300, 400))
func set_test_scene_path(path:String):
var current_scene := EditorInterface.get_edited_scene_root()
current_scene.set_meta(META_NAME, path)
run_test_scene()

View file

@ -0,0 +1,28 @@
[gd_scene load_steps=6 format=3 uid="uid://dbjvqwv7nf7e"]
[ext_resource type="Texture2D" uid="uid://njcc6c8v1kun" path="res://addons/godot_test_scene/icon.svg" id="1_aa2ip"]
[ext_resource type="Script" path="res://addons/godot_test_scene/test_scene_button.gd" id="2_78f3v"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_k6kmm"]
bg_color = Color(0.239216, 0.258824, 0.290196, 1)
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_opnre"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ocjw8"]
[node name="TestSceneButton" type="Button"]
physics_interpolation_mode = 0
offset_right = 16.0
offset_bottom = 16.0
tooltip_text = "Run Test Scene
Play the linked test scene."
focus_mode = 0
theme_override_colors/icon_pressed_color = Color(0.435294, 0.717647, 0.960784, 1)
theme_override_styles/hover = SubResource("StyleBoxFlat_k6kmm")
theme_override_styles/pressed = SubResource("StyleBoxEmpty_opnre")
theme_override_styles/normal = SubResource("StyleBoxEmpty_ocjw8")
icon = ExtResource("1_aa2ip")
script = ExtResource("2_78f3v")
[connection signal="gui_input" from="." to="." method="_on_gui_input"]
[connection signal="pressed" from="." to="." method="_on_pressed"]