Compare commits
2 commits
75575991fa
...
4218e2099d
Author | SHA1 | Date | |
---|---|---|---|
4218e2099d | |||
4adff6e9b8 |
8 changed files with 90 additions and 16 deletions
|
@ -3,5 +3,5 @@
|
|||
name="Simple Format On Save"
|
||||
description="Combination of simple gdscript formatter & Format On Save with extra rules for beatiful formatting...maybe"
|
||||
author="VitSoonYoung"
|
||||
version="0.1"
|
||||
version="0.2"
|
||||
script="simple_format_on_save.gd"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
class_name RuleBlankLines
|
||||
|
||||
var FORMAT_ACTION := "simple_format_on_save/format_code"
|
||||
const FORMAT_ACTION := "simple_format_on_save/format_code"
|
||||
var format_key: InputEventKey
|
||||
|
||||
var _EditorSettings = EditorInterface.get_editor_settings()
|
||||
|
||||
|
||||
static func apply(code: String) -> String:
|
||||
var trim1_regex = RegEx.create_from_string("\n{2,}")
|
||||
|
@ -28,14 +30,11 @@ static func _blank_for_func_class(code: String) -> String:
|
|||
if func_class_regex.search(line):
|
||||
if modified_lines.size() > 0:
|
||||
var i := modified_lines.size() - 1
|
||||
|
||||
while i > 0 and comment_line_regex.search(modified_lines[i]):
|
||||
i -= 1
|
||||
|
||||
if i == 0:
|
||||
modified_lines.append(line)
|
||||
continue
|
||||
|
||||
modified_lines.insert(i + 1, "")
|
||||
modified_lines.insert(i + 1, "")
|
||||
|
||||
|
@ -43,22 +42,19 @@ static func _blank_for_func_class(code: String) -> String:
|
|||
if statement_regex.search(line):
|
||||
if modified_lines.size() > 0:
|
||||
var i := modified_lines.size() - 1
|
||||
|
||||
if assignment_regex.search(modified_lines[i]) and not statement_regex.search(modified_lines[i]) and not statement_regex.search(line):
|
||||
modified_lines.insert(i + 1, "")
|
||||
else:
|
||||
pass
|
||||
|
||||
# Space after a code block (Doesn't work with spaces for now)
|
||||
if EditorInterface.get_editor_settings().get_setting(FormatOnSavePlugin.SETTING_PREFIX+"blank_after_dedent"):
|
||||
var indent_count := line.count("\t")
|
||||
|
||||
if indent_count and not misc_statement_regex.search(line) and not statement_regex.search(line):
|
||||
if modified_lines.size() > 0:
|
||||
var i := modified_lines.size() - 1
|
||||
|
||||
if modified_lines[i].count("\t") > indent_count:
|
||||
modified_lines.insert(i + 1, "")
|
||||
|
||||
modified_lines.append(line)
|
||||
|
||||
return "\n".join(modified_lines)
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
@tool
|
||||
extends EditorPlugin
|
||||
class_name FormatOnSavePlugin
|
||||
|
||||
var FORMAT_ACTION := "simple_format_on_save/format_code"
|
||||
const FORMAT_ACTION := "simple_format_on_save/format_code"
|
||||
const SETTING_PREFIX = "text_editor/format_on_save/"
|
||||
var format_key: InputEventKey
|
||||
var formatter: Formatter
|
||||
|
||||
|
||||
## Create an editor setting so users can toggle features
|
||||
func _set_default_setting(setting:String,default_value:Variant):
|
||||
var _EditorSettings = EditorInterface.get_editor_settings()
|
||||
if not _EditorSettings.has_setting(SETTING_PREFIX+setting):
|
||||
_EditorSettings.set_setting(SETTING_PREFIX+setting, default_value)
|
||||
_EditorSettings.set_initial_value(SETTING_PREFIX+setting, default_value,false)
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
_set_default_setting("blank_after_dedent",false)
|
||||
|
||||
add_tool_menu_item("Format (Ctrl+Alt+L)", _on_format_code)
|
||||
|
||||
if InputMap.has_action(FORMAT_ACTION):
|
||||
|
|
38
assetloader/assetloader.gd
Normal file
38
assetloader/assetloader.gd
Normal file
|
@ -0,0 +1,38 @@
|
|||
extends Object
|
||||
class_name AssetLoader
|
||||
|
||||
const DEFAULT_ASSETS_PATH = "res://mods"
|
||||
|
||||
## Path to the mods folder : [param res://mods] by default
|
||||
## [br]
|
||||
## (is not a const but should be treated as such, so the uppercase)
|
||||
var ASSETS_PATH
|
||||
|
||||
var critical_error := false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
ASSETS_PATH = ProjectSettings.get_setting("game/mods/mod_path", DEFAULT_ASSETS_PATH)
|
||||
var dir := DirAccess.open(ASSETS_PATH)
|
||||
if not dir:
|
||||
push_error("AssetLoader: Mods folder not found at '%s'" % ASSETS_PATH)
|
||||
_show_error_popup("Mods folder not found at '%s'" % ASSETS_PATH)
|
||||
critical_error = true
|
||||
return
|
||||
var mod_folders := dir.get_directories()
|
||||
|
||||
if mod_folders.is_empty():
|
||||
push_error("AssetLoader: Mods folder '%s' is empty — no mods to load." % ASSETS_PATH)
|
||||
_show_error_popup("Mods folder '%s' is empty — no mods to load." % ASSETS_PATH)
|
||||
critical_error = true
|
||||
return
|
||||
|
||||
|
||||
## This will show a native MessageBox on Windows,
|
||||
## a native dialog on macOS, and GTK/QT dialog on Linux.
|
||||
func _show_error_popup(message: String) -> void:
|
||||
OS.alert("AssetLoader:"+message, "AssetLoader:Error")
|
||||
|
||||
|
||||
func load_all():
|
||||
pass
|
1
assetloader/assetloader.gd.uid
Normal file
1
assetloader/assetloader.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://qkh5uvr4st7i
|
25
autoloads/bootstrap.gd
Normal file
25
autoloads/bootstrap.gd
Normal file
|
@ -0,0 +1,25 @@
|
|||
extends Node
|
||||
## Should always be at the top of autoloads
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var loader := AssetLoader.new()
|
||||
# If there was a critical error, quit immediately
|
||||
if loader.critical_error:
|
||||
Engine.get_main_loop().quit(1)
|
||||
return
|
||||
loader.load_all() # TODO: Making it async
|
||||
|
||||
# Otherwise, continue startup
|
||||
_start_game()
|
||||
|
||||
|
||||
## This will show a native MessageBox on Windows,
|
||||
## a native dialog on macOS, and GTK/QT dialog on Linux.
|
||||
func _show_error_popup(context:String, message: String) -> void:
|
||||
OS.alert(context+":"+message, context+":Error")
|
||||
|
||||
|
||||
func _start_game() -> void:
|
||||
print("Game starting...")
|
||||
#TODO: Load main menu or world scene
|
1
autoloads/bootstrap.gd.uid
Normal file
1
autoloads/bootstrap.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bbmtxflx0ivgp
|
|
@ -21,6 +21,7 @@ config/windows_native_icon="res://4589AD_icon.ico"
|
|||
|
||||
[autoload]
|
||||
|
||||
Bootstrap="*res://autoloads/bootstrap.gd"
|
||||
DebugTools="*res://dev/debug_tools.tscn"
|
||||
|
||||
[debug]
|
||||
|
|
Loading…
Reference in a new issue