Skip to content
Merged
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
40 changes: 40 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Checks

on:
pull_request:
push:
branches:
- main

jobs:
pre-commit:
name: Linting and Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected]

tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Godot
uses: chickensoft-games/[email protected]
with:
version: 4.2.2
use-dotnet: false
- name: Initialize Godot
run: |
godot --path . --headless --import
- name: Run tests
run: |
godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit
21 changes: 0 additions & 21 deletions .github/workflows/pre-commit.yaml

This file was deleted.

6 changes: 6 additions & 0 deletions .gutconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dirs": [
"res://tests"
],
"include_subdirs": true
}
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ repos:
hooks:
- id: gdformat
args: [--line-length=200]
files:
^addons/block_code/(?!lib/).*$
files: ^(addons/block_code/(?!lib/).*|tests/.*)$
6 changes: 6 additions & 0 deletions addons/block_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ pre-commit install
```

Now `pre-commit` will run automatically on `git commit`!

## Testing

This plugin uses the [Godot Unit Test](https://gut.readthedocs.io/en/latest/)
(GUT) plugin for testing. In the editor, click on the GUT tab in the bottom
panel to open the test panel. Then click Run All to run the tests.
127 changes: 127 additions & 0 deletions addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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():
set_font_size(100)
_normal_gui.get_textbox().text = "hello world, how are you doing?"

# ------------------------
# Private
# ------------------------
func _set_gut(val):
if(_normal_gui.get_gut() == val):
return
_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):
var rtl = _normal_gui.get_textbox()

rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size)
rtl.set('theme_override_font_sizes/bold_font_size', new_size)
rtl.set('theme_override_font_sizes/italics_font_size', new_size)
rtl.set('theme_override_font_sizes/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.remove_theme_font_override(custom_name)
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 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 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 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