Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONConfigFile 2.0.0 - Godot 4.0 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[codespell]
skip = demo/addons/gut
builtin = en-GB_to_en-US
46 changes: 46 additions & 0 deletions .gdlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class-definitions-order:
- tools
- classnames
- extends
- signals
- enums
- consts
- exports
- pubvars
- prvvars
- onreadypubvars
- onreadyprvvars
- others
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
comparison-with-itself: null
constant-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
disable: []
duplicated-load: null
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
excluded_directories: !!set
.git: null
expression-not-assigned: null
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-preload-variable-name: ([A-Z][a-z0-9]*)+
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
max-file-lines: 1000
max-line-length: 100
max-public-methods: 20
max-returns: 6
mixed-tabs-and-spaces: null
no-elif-return: null
no-else-return: null
private-method-call: null
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+
tab-characters: 1
trailing-whitespace: null
unnecessary-pass: null
unused-argument: null
60 changes: 60 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: 🌟 Master

on:
pull_request:
branches: [master]

jobs:
gdscript:
name: 💅 Linting / 🤖 GDScript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: pip3 install "gdtoolkit==4.*"
- run: bash -c 'for f in ./demo/addons/json_config_file/**/*.gd; do gdlint "$f"; done'
- run: bash -c 'for f in ./demo/tests/**/*.gd; do gdlint "$f"; done'

spelling:
name: 💅 Linting / 👓 Spelling
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: codespell-project/actions-codespell@v1

unit-testing:
name: 🧪 Unit Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Download Godot
run: |
curl -O https://downloads.tuxfamily.org/godotengine/4.0.3/Godot_v4.0.3-stable_linux.x86_64.zip
unzip Godot_v4.0.3-stable_linux.x86_64.zip

- name: Execute tests
run: |
./Godot_v4.0.3-stable_linux.x86_64 --headless --path ./demo --export-release "Linux/X11" /dev/null
./Godot_v4.0.3-stable_linux.x86_64 --headless -d -s --path ./demo addons/gut/gut_cmdln.gd

package:
name: 📦 Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Create addon
run: |
mkdir addons
cp -R demo/addons/json_config_file addons
cp LICENSE.md addons/json_config_file

- name: Create package
run: |
zip -r json_config_file.zip addons

- name: Upload addon
uses: actions/upload-artifact@v3
with:
name: json_config_file
path: json_config_file.zip
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.godot
.import/
export.cfg
export_presets.cfg
2 changes: 2 additions & 0 deletions LICENSE.txt → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MIT License

Copyright (c) 2020 Tomás Espejo Gómez

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
42 changes: 42 additions & 0 deletions demo/.gut_editor_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"background_color": "262626ff",
"compact_mode": false,
"config_file": "res://.gutconfig.json",
"dirs": [
"res://tests"
],
"disable_colors": false,
"double_strategy": "partial",
"font_color": "ccccccff",
"font_name": "CourierPrime",
"font_size": 16,
"gut_on_top": true,
"hide_orphans": false,
"ignore_pause": false,
"include_subdirs": true,
"inner_class": null,
"junit_xml_file": "",
"junit_xml_timestamp": false,
"log_level": 1,
"opacity": 100,
"paint_after": 0.1,
"panel_options": {
"font_name": "CourierPrime",
"font_size": 30,
"hide_output_text": true,
"hide_result_tree": false,
"hide_settings": true,
"use_colors": false
},
"post_run_script": "",
"pre_run_script": "",
"prefix": "test_",
"selected": null,
"should_exit": false,
"should_exit_on_success": false,
"should_maximize": false,
"show_help": false,
"suffix": ".gd",
"tests": [],
"unit_test_name": null
}
12 changes: 12 additions & 0 deletions demo/.gutconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"dirs": [
"res://tests/"
],
"include_subdirs": true,
"selected": "",
"should_exit": true,
"should_maximize": false,
"tests": [],
"unit_test_name": "",
"disabled_colors": true
}
124 changes: 124 additions & 0 deletions demo/addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
extends Node2D
# ##############################################################################
# This is a wrapper around the normal and compact gui controls and serves as
# the interface between gut.gd and the gui. The GutRunner creates an instance
# of this and then this takes care of managing the different GUI controls.
# ##############################################################################
@onready var _normal_gui = $Normal
@onready var _compact_gui = $Compact
var gut = null :
set(val):
gut = val
_set_gut(val)


func _ready():
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))

_normal_gui.set_title("GUT")
_compact_gui.set_title("GUT")

_normal_gui.align_right()
_compact_gui.to_bottom_right()

use_compact_mode(false)

if(get_parent() == get_tree().root):
_test_running_setup()

func _test_running_setup():
_normal_gui.get_textbox().text = "hello world, how are you doing?"

# ------------------------
# Private
# ------------------------
func _set_gut(val):
_normal_gui.set_gut(val)
_compact_gui.set_gut(val)

val.start_run.connect(_on_gut_start_run)
val.end_run.connect(_on_gut_end_run)
val.start_pause_before_teardown.connect(_on_gut_pause)
val.end_pause_before_teardown.connect(_on_pause_end)

func _set_both_titles(text):
_normal_gui.set_title(text)
_compact_gui.set_title(text)


# ------------------------
# Events
# ------------------------
func _on_gut_start_run():
_set_both_titles('Running')

func _on_gut_end_run():
_set_both_titles('Finished')

func _on_gut_pause():
_set_both_titles('-- Paused --')

func _on_pause_end():
_set_both_titles('Running')


# ------------------------
# Public
# ------------------------
func get_textbox():
return _normal_gui.get_textbox()


func set_font_size(new_size):
return
var rtl = _normal_gui.get_textbox()
if(rtl.get('custom_fonts/normal_font') != null):
rtl.get('custom_fonts/bold_italics_font').size = new_size
rtl.get('custom_fonts/bold_font').size = new_size
rtl.get('custom_fonts/italics_font').size = new_size
rtl.get('custom_fonts/normal_font').size = new_size


func set_font(font_name):
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)


func _set_font(rtl, font_name, custom_name):
if(font_name == null):
rtl.add_theme_font_override(custom_name, null)
else:
var dyn_font = FontFile.new()
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
rtl.add_theme_font_override(custom_name, dyn_font)


func _set_all_fonts_in_rtl(rtl, base_name):
if(base_name == 'Default'):
_set_font(rtl, null, 'normal_font')
_set_font(rtl, null, 'bold_font')
_set_font(rtl, null, 'italics_font')
_set_font(rtl, null, 'bold_italics_font')
else:
_set_font(rtl, base_name + '-Regular', 'normal_font')
_set_font(rtl, base_name + '-Bold', 'bold_font')
_set_font(rtl, base_name + '-Italic', 'italics_font')
_set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font')


func set_default_font_color(color):
_normal_gui.get_textbox().set('custom_colors/default_color', color)


func set_background_color(color):
_normal_gui.set_bg_color(color)


func use_compact_mode(should=true):
_compact_gui.visible = should
_normal_gui.visible = !should


func set_opacity(val):
_normal_gui.modulate.a = val
_compact_gui.modulate.a = val
16 changes: 16 additions & 0 deletions demo/addons/gut/GutScene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://m28heqtswbuq"]

[ext_resource type="Script" path="res://addons/gut/GutScene.gd" id="1_b4m8y"]
[ext_resource type="PackedScene" uid="uid://duxblir3vu8x7" path="res://addons/gut/gui/NormalGui.tscn" id="2_j6ywb"]
[ext_resource type="PackedScene" uid="uid://cnqqdfsn80ise" path="res://addons/gut/gui/MinGui.tscn" id="3_3glw1"]

[node name="GutScene" type="Node2D"]
script = ExtResource("1_b4m8y")

[node name="Normal" parent="." instance=ExtResource("2_j6ywb")]

[node name="Compact" parent="." instance=ExtResource("3_3glw1")]
offset_left = 5.0
offset_top = 273.0
offset_right = 265.0
offset_bottom = 403.0
22 changes: 22 additions & 0 deletions demo/addons/gut/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)
=====================

Copyright (c) 2018 Tom "Butch" Wesley

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.
52 changes: 52 additions & 0 deletions demo/addons/gut/UserFileViewer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
extends Window

@onready var rtl = $TextDisplay/RichTextLabel

func _get_file_as_text(path):
var to_return = null
var f = FileAccess.open(path, FileAccess.READ)
if(f != null):
to_return = f.get_as_text()
else:
to_return = str('ERROR: Could not open file. Error code ', FileAccess.get_open_error())
return to_return

func _ready():
rtl.clear()

func _on_OpenFile_pressed():
$FileDialog.popup_centered()

func _on_FileDialog_file_selected(path):
show_file(path)

func _on_Close_pressed():
self.hide()

func show_file(path):
var text = _get_file_as_text(path)
if(text == ''):
text = '<Empty File>'
rtl.set_text(text)
self.window_title = path

func show_open():
self.popup_centered()
$FileDialog.popup_centered()

func get_rich_text_label():
return $TextDisplay/RichTextLabel

func _on_Home_pressed():
rtl.scroll_to_line(0)

func _on_End_pressed():
rtl.scroll_to_line(rtl.get_line_count() -1)

func _on_Copy_pressed():
return
# OS.clipboard = rtl.text

func _on_file_dialog_visibility_changed():
if rtl.text.length() == 0 and not $FileDialog.visible:
self.hide()
Loading