Use vscode for script editing

The `format_on_save` plugin isn't needed anymore.
This commit is contained in:
Jarrod Doyle 2024-02-24 13:21:09 +00:00
parent 4d95b7d9d1
commit 89ec939325
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
5 changed files with 19 additions and 98 deletions

18
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "GDScript: Launch Project",
"type": "godot",
"request": "launch",
"project": "${workspaceFolder}",
"debug_collisions": false,
"debug_paths": false,
"debug_navigation": false,
"additional_options": ""
}
]
}

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2023 Ryan Haskell-Glatz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,70 +0,0 @@
@tool
class_name FormatOnSave extends EditorPlugin
const SUCCESS: int = 0
const AUTO_RELOAD_SETTING: String = "text_editor/behavior/files/auto_reload_scripts_on_external_change"
var original_auto_reload_setting: bool
# LIFECYCLE EVENTS
func _enter_tree():
activate_auto_reload_setting()
resource_saved.connect(on_resource_saved)
func _exit_tree():
resource_saved.disconnect(on_resource_saved)
restore_original_auto_reload_setting()
# CALLED WHEN A SCRIPT IS SAVED
func on_resource_saved(resource: Resource):
if resource is Script:
var script: Script = resource
var current_script = get_editor_interface().get_script_editor().get_current_script()
var text_edit: CodeEdit = (
get_editor_interface().get_script_editor().get_current_editor().get_base_editor()
)
# Prevents other unsaved scripts from overwriting the active one
if current_script == script:
var filepath: String = ProjectSettings.globalize_path(resource.resource_path)
# Run gdformat
var exit_code = OS.execute("gdformat", [filepath])
# Replace source_code with formatted source_code
if exit_code == SUCCESS:
var formatted_source = FileAccess.get_file_as_string(resource.resource_path)
FormatOnSave.reload_script(text_edit, formatted_source)
# Workaround until this PR is merged:
# https://github.com/godotengine/godot/pull/83267
# Thanks, @KANAjetzt 💖
static func reload_script(text_edit: TextEdit, source_code: String) -> void:
var column := text_edit.get_caret_column()
var row := text_edit.get_caret_line()
var scroll_position_h := text_edit.get_h_scroll_bar().value
var scroll_position_v := text_edit.get_v_scroll_bar().value
text_edit.text = source_code
text_edit.set_caret_column(column)
text_edit.set_caret_line(row)
text_edit.scroll_horizontal = scroll_position_h
text_edit.scroll_vertical = scroll_position_v
text_edit.tag_saved_version()
# For this workaround to work, we need to disable the "Reload/Resave" pop-up
func activate_auto_reload_setting():
var settings := get_editor_interface().get_editor_settings()
original_auto_reload_setting = settings.get(AUTO_RELOAD_SETTING)
settings.set(AUTO_RELOAD_SETTING, true)
# If the plugin is disabled, let's attempt to restore the original editor setting
func restore_original_auto_reload_setting():
var settings := get_editor_interface().get_editor_settings()
settings.set(AUTO_RELOAD_SETTING, original_auto_reload_setting)

View File

@ -1,6 +0,0 @@
[plugin]
name="Format on Save"
description="Runs `gdformat` on save to automatically format your GD script as you code."
author="Ryan Haskell-Glatz"
version="1.2.0"
script="format_on_save.gd"

View File

@ -29,7 +29,7 @@ project/assembly_name="Character Controller"
[editor_plugins]
enabled=PackedStringArray("res://addons/format_on_save/plugin.cfg", "res://addons/godot_state_charts/plugin.cfg", "res://addons/qodot/plugin.cfg")
enabled=PackedStringArray("res://addons/godot_state_charts/plugin.cfg", "res://addons/qodot/plugin.cfg")
[input]