Skip to content

Commit

Permalink
Merge pull request #15 from aaronfranke/format
Browse files Browse the repository at this point in the history
Format files and add file formatting checks
  • Loading branch information
willnationsdev authored Apr 21, 2021
2 parents e41fc33 + 4ced5a5 commit 35829c3
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 113 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Normalize EOL for all files that Git considers text files.
* text=auto eol=lf

# Ignore everything outside of the addons folder when exporting.
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/file_format.sh export-ignore
/icon.png export-ignore
/icon.png.import export-ignore
/LICENSE.md export-ignore
/project.godot export-ignore
/README.md export-ignore
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
19 changes: 19 additions & 0 deletions .github/workflows/static_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 📊 Static Checks
on: [push, pull_request]

jobs:
format:
name: File formatting (file_format.sh)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qq dos2unix recode
- name: File formatting checks (file_format.sh)
run: |
bash ./file_format.sh
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Godot 4+ specific ignores
.godot/

# Godot-specific ignores
.import/
export.cfg
export_presets.cfg

# Imported translations (automatically generated from CSV files)
*.translation

# Mono-specific ignores
.mono/
data_*/
mono_crash.*.json

# System/tool-specific ignores
.directory
*~
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Will Nations
Copyright (c) 2018-2021 Will Nations

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 21 additions & 0 deletions addons/godot-plugin-refresher/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018-2021 Will Nations

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.
9 changes: 7 additions & 2 deletions addons/godot-plugin-refresher/plugin_refresher.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ signal confirm_refresh_plugin(p_name)
onready var options = $OptionButton

func _ready():
$RefreshButton.icon = get_icon('Reload', 'EditorIcons')
$RefreshButton.icon = get_icon("Reload", "EditorIcons")


func update_items(p_plugins):
if not options:
Expand All @@ -20,6 +21,7 @@ func update_items(p_plugins):
options.add_item(plugin_name, idx)
options.set_item_metadata(idx, plugin_dirname)


func select_plugin(p_name):
if not options:
return
Expand All @@ -32,6 +34,7 @@ func select_plugin(p_name):
options.selected = options.get_item_id(idx)
break


func _on_RefreshButton_pressed():
if options.selected == -1:
return # nothing selected
Expand All @@ -41,13 +44,15 @@ func _on_RefreshButton_pressed():
return
emit_signal("request_refresh_plugin", plugin)


func show_warning(p_name):
$ConfirmationDialog.dialog_text = """
Plugin `%s` is currently disabled.\n
Do you want to enable it now?
""" % [p_name]
$ConfirmationDialog.popup_centered()


func _on_ConfirmationDialog_confirmed():
var plugin = options.get_item_metadata(options.selected)
emit_signal('confirm_refresh_plugin', plugin)
emit_signal("confirm_refresh_plugin", plugin)
3 changes: 3 additions & 0 deletions addons/godot-plugin-refresher/plugin_refresher.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="VSeparator" type="VSeparator" parent="."]
margin_right = 4.0
Expand Down
19 changes: 15 additions & 4 deletions addons/godot-plugin-refresher/plugin_refresher_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ tool
extends EditorPlugin

const ADDONS_PATH = "res://addons/"
const PLUGIN_CONFIG_DIR = 'plugins/plugin_refresher'
const PLUGIN_CONFIG = 'settings.cfg'
const SETTINGS = 'settings'
const SETTING_RECENT = 'recently_used'
const PLUGIN_CONFIG_DIR = "plugins/plugin_refresher"
const PLUGIN_CONFIG = "settings.cfg"
const SETTINGS = "settings"
const SETTING_RECENT = "recently_used"

var plugin_config = ConfigFile.new()
var refresher
Expand All @@ -24,10 +24,12 @@ func _enter_tree():
_reload_plugins_list()
_load_settings()


func _exit_tree():
remove_control_from_container(CONTAINER_TOOLBAR, refresher)
refresher.free()


func _reload_plugins_list():
var refresher_dir = get_plugin_path().get_file()
var plugins = {}
Expand Down Expand Up @@ -64,6 +66,7 @@ func _reload_plugins_list():

refresher.update_items(plugins)


func _load_settings():
var path = get_config_path()

Expand All @@ -76,28 +79,33 @@ func _load_settings():
else:
plugin_config.load(path)


func _save_settings():
plugin_config.save(get_config_path())


func get_config_path():
var dir = get_editor_interface().get_editor_settings().get_project_settings_dir()
var home = dir.plus_file(PLUGIN_CONFIG_DIR)
var path = home.plus_file(PLUGIN_CONFIG)

return path


func _on_filesystem_changed():
if refresher:
_reload_plugins_list()
refresher.select_plugin(get_recent_plugin())


func get_recent_plugin():
if not plugin_config.has_section_key(SETTINGS, SETTING_RECENT):
return null # not saved yet

var recent = plugin_config.get_value(SETTINGS, SETTING_RECENT)
return recent


func _on_request_refresh_plugin(p_name):
assert(not p_name.empty())

Expand All @@ -107,12 +115,15 @@ func _on_request_refresh_plugin(p_name):
else:
refresh_plugin(p_name)


func _on_confirm_refresh_plugin(p_name):
refresh_plugin(p_name)


func get_plugin_path():
return get_script().resource_path.get_base_dir()


func refresh_plugin(p_name):
print("Refreshing plugin: ", p_name)

Expand Down
102 changes: 0 additions & 102 deletions default_env.tres

This file was deleted.

39 changes: 39 additions & 0 deletions file_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# This script ensures proper POSIX text file formatting and a few other things.

set -uo pipefail
IFS=$'\n\t'

# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
# Ensure that files have LF line endings and do not contain a BOM.
dos2unix "$f" 2> /dev/null
# Remove trailing space characters and ensures that files end
# with newline characters. -l option handles newlines conveniently.
perl -i -ple 's/\s*$//g' "$f"
# Remove the character sequence "== true" if it has a leading space.
perl -i -pe 's/\x20== true//g' "$f"
done

git diff > patch.patch
FILESIZE="$(stat -c%s patch.patch)"
MAXSIZE=5

# If no patch has been generated all is OK, clean up, and exit.
if (( FILESIZE < MAXSIZE )); then
printf "Files in this commit comply with the formatting rules.\n"
rm -f patch.patch
exit 0
fi

# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1
4 changes: 0 additions & 4 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,3 @@ ui_end={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777230,"unicode":0,"echo":false,"script":null)
]
}

[rendering]

environment/default_environment="res://default_env.tres"

0 comments on commit 35829c3

Please sign in to comment.