-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0aab01
commit 5822c2b
Showing
70 changed files
with
10,526 additions
and
1,735 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
extends WindowDialog | ||
|
||
onready var rtl = $TextDisplay/RichTextLabel | ||
var _has_opened_file = false | ||
|
||
func _get_file_as_text(path): | ||
var to_return = null | ||
var f = File.new() | ||
var result = f.open(path, f.READ) | ||
if(result == OK): | ||
to_return = f.get_as_text() | ||
f.close() | ||
else: | ||
to_return = str('ERROR: Could not open file. Error code ', result) | ||
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 _on_FileDialog_popup_hide(): | ||
if(rtl.text.length() == 0): | ||
self.hide() | ||
|
||
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(): | ||
OS.clipboard = rtl.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/gut/UserFileViewer.gd" type="Script" id=1] | ||
|
||
[node name="UserFileViewer" type="WindowDialog"] | ||
margin_top = 20.0 | ||
margin_right = 800.0 | ||
margin_bottom = 450.0 | ||
rect_min_size = Vector2( 800, 180 ) | ||
popup_exclusive = true | ||
window_title = "View File" | ||
resizable = true | ||
script = ExtResource( 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="FileDialog" type="FileDialog" parent="."] | ||
margin_right = 416.0 | ||
margin_bottom = 184.0 | ||
rect_min_size = Vector2( 400, 140 ) | ||
rect_scale = Vector2( 2, 2 ) | ||
popup_exclusive = true | ||
window_title = "Open a File" | ||
resizable = true | ||
mode = 0 | ||
access = 1 | ||
show_hidden_files = true | ||
current_dir = "user://" | ||
current_path = "user://" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="TextDisplay" type="ColorRect" parent="."] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = 8.0 | ||
margin_right = -10.0 | ||
margin_bottom = -65.0 | ||
color = Color( 0.2, 0.188235, 0.188235, 1 ) | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="RichTextLabel" type="RichTextLabel" parent="TextDisplay"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
focus_mode = 2 | ||
text = "In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used before final copy is available, but it may also be used to temporarily replace copy in a process called greeking, which allows designers to consider form without the meaning of the text influencing the design. | ||
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a first-century BCE text by the Roman statesman and philosopher Cicero, with words altered, added, and removed to make it nonsensical, improper Latin. | ||
Versions of the Lorem ipsum text have been used in typesetting at least since the 1960s, when it was popularized by advertisements for Letraset transfer sheets. Lorem ipsum was introduced to the digital world in the mid-1980s when Aldus employed it in graphic and word-processing templates for its desktop publishing program PageMaker. Other popular word processors including Pages and Microsoft Word have since adopted Lorem ipsum as well." | ||
selection_enabled = true | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="OpenFile" type="Button" parent="."] | ||
anchor_left = 1.0 | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = -158.0 | ||
margin_top = -50.0 | ||
margin_right = -84.0 | ||
margin_bottom = -30.0 | ||
rect_scale = Vector2( 2, 2 ) | ||
text = "Open File" | ||
|
||
[node name="Home" type="Button" parent="."] | ||
anchor_left = 1.0 | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = -478.0 | ||
margin_top = -50.0 | ||
margin_right = -404.0 | ||
margin_bottom = -30.0 | ||
rect_scale = Vector2( 2, 2 ) | ||
text = "Home" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="Copy" type="Button" parent="."] | ||
anchor_top = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = 160.0 | ||
margin_top = -50.0 | ||
margin_right = 234.0 | ||
margin_bottom = -30.0 | ||
rect_scale = Vector2( 2, 2 ) | ||
text = "Copy" | ||
__meta__ = { | ||
"_edit_use_anchors_": false | ||
} | ||
|
||
[node name="End" type="Button" parent="."] | ||
anchor_left = 1.0 | ||
anchor_top = 1.0 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = -318.0 | ||
margin_top = -50.0 | ||
margin_right = -244.0 | ||
margin_bottom = -30.0 | ||
rect_scale = Vector2( 2, 2 ) | ||
text = "End" | ||
|
||
[node name="Close" type="Button" parent="."] | ||
anchor_top = 1.0 | ||
anchor_bottom = 1.0 | ||
margin_left = 10.0 | ||
margin_top = -50.0 | ||
margin_right = 80.0 | ||
margin_bottom = -30.0 | ||
rect_scale = Vector2( 2, 2 ) | ||
text = "Close" | ||
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"] | ||
[connection signal="popup_hide" from="FileDialog" to="." method="_on_FileDialog_popup_hide"] | ||
[connection signal="pressed" from="OpenFile" to="." method="_on_OpenFile_pressed"] | ||
[connection signal="pressed" from="Home" to="." method="_on_Home_pressed"] | ||
[connection signal="pressed" from="Copy" to="." method="_on_Copy_pressed"] | ||
[connection signal="pressed" from="End" to="." method="_on_End_pressed"] | ||
[connection signal="pressed" from="Close" to="." method="_on_Close_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# ############################################################################## | ||
#(G)odot (U)nit (T)est class | ||
# | ||
# ############################################################################## | ||
# The MIT License (MIT) | ||
# ===================== | ||
# | ||
# Copyright (c) 2020 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. | ||
# | ||
# ############################################################################## | ||
# Class used to keep track of objects to be freed and utilities to free them. | ||
# ############################################################################## | ||
var _to_free = [] | ||
var _to_queue_free = [] | ||
|
||
func add_free(thing): | ||
if(typeof(thing) == TYPE_OBJECT): | ||
if(!thing is Reference): | ||
_to_free.append(thing) | ||
|
||
func add_queue_free(thing): | ||
_to_queue_free.append(thing) | ||
|
||
func get_queue_free_count(): | ||
return _to_queue_free.size() | ||
|
||
func get_free_count(): | ||
return _to_free.size() | ||
|
||
func free_all(): | ||
for i in range(_to_free.size()): | ||
if(is_instance_valid(_to_free[i])): | ||
_to_free[i].free() | ||
_to_free.clear() | ||
|
||
for i in range(_to_queue_free.size()): | ||
if(is_instance_valid(_to_queue_free[i])): | ||
_to_queue_free[i].queue_free() | ||
_to_queue_free.clear() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
var _utils = load('res://addons/gut/utils.gd').get_instance() | ||
var _strutils = _utils.Strutils.new() | ||
var _max_length = 100 | ||
var _should_compare_int_to_float = true | ||
|
||
const MISSING = '|__missing__gut__compare__value__|' | ||
const DICTIONARY_DISCLAIMER = 'Dictionaries are compared-by-ref. See assert_eq in wiki.' | ||
|
||
func _cannot_comapre_text(v1, v2): | ||
return str('Cannot compare ', _strutils.types[typeof(v1)], ' with ', | ||
_strutils.types[typeof(v2)], '.') | ||
|
||
func _make_missing_string(text): | ||
return '<missing ' + text + '>' | ||
|
||
func _create_missing_result(v1, v2, text): | ||
var to_return = null | ||
var v1_str = format_value(v1) | ||
var v2_str = format_value(v2) | ||
|
||
if(typeof(v1) == TYPE_STRING and v1 == MISSING): | ||
v1_str = _make_missing_string(text) | ||
to_return = _utils.CompareResult.new() | ||
elif(typeof(v2) == TYPE_STRING and v2 == MISSING): | ||
v2_str = _make_missing_string(text) | ||
to_return = _utils.CompareResult.new() | ||
|
||
if(to_return != null): | ||
to_return.summary = str(v1_str, ' != ', v2_str) | ||
to_return.are_equal = false | ||
|
||
return to_return | ||
|
||
|
||
func simple(v1, v2, missing_string=''): | ||
var missing_result = _create_missing_result(v1, v2, missing_string) | ||
if(missing_result != null): | ||
return missing_result | ||
|
||
var result = _utils.CompareResult.new() | ||
var cmp_str = null | ||
var extra = '' | ||
|
||
if(_should_compare_int_to_float and [2, 3].has(typeof(v1)) and [2, 3].has(typeof(v2))): | ||
result.are_equal = v1 == v2 | ||
|
||
elif(_utils.are_datatypes_same(v1, v2)): | ||
result.are_equal = v1 == v2 | ||
if(typeof(v1) == TYPE_DICTIONARY): | ||
if(result.are_equal): | ||
extra = '. Same dictionary ref. ' | ||
else: | ||
extra = '. Different dictionary refs. ' | ||
extra += DICTIONARY_DISCLAIMER | ||
|
||
if(typeof(v1) == TYPE_ARRAY): | ||
var array_result = _utils.DiffTool.new(v1, v2, _utils.DIFF.SHALLOW) | ||
result.summary = array_result.get_short_summary() | ||
if(!array_result.are_equal()): | ||
extra = ".\n" + array_result.get_short_summary() | ||
|
||
else: | ||
cmp_str = '!=' | ||
result.are_equal = false | ||
extra = str('. ', _cannot_comapre_text(v1, v2)) | ||
|
||
cmp_str = get_compare_symbol(result.are_equal) | ||
if(typeof(v1) != TYPE_ARRAY): | ||
result.summary = str(format_value(v1), ' ', cmp_str, ' ', format_value(v2), extra) | ||
|
||
return result | ||
|
||
|
||
func shallow(v1, v2): | ||
var result = null | ||
|
||
if(_utils.are_datatypes_same(v1, v2)): | ||
if(typeof(v1) in [TYPE_ARRAY, TYPE_DICTIONARY]): | ||
result = _utils.DiffTool.new(v1, v2, _utils.DIFF.SHALLOW) | ||
else: | ||
result = simple(v1, v2) | ||
else: | ||
result = simple(v1, v2) | ||
|
||
return result | ||
|
||
|
||
func deep(v1, v2): | ||
var result = null | ||
|
||
if(_utils.are_datatypes_same(v1, v2)): | ||
if(typeof(v1) in [TYPE_ARRAY, TYPE_DICTIONARY]): | ||
result = _utils.DiffTool.new(v1, v2, _utils.DIFF.DEEP) | ||
else: | ||
result = simple(v1, v2) | ||
else: | ||
result = simple(v1, v2) | ||
|
||
return result | ||
|
||
|
||
func format_value(val, max_val_length=_max_length): | ||
return _strutils.truncate_string(_strutils.type2str(val), max_val_length) | ||
|
||
|
||
func compare(v1, v2, diff_type=_utils.DIFF.SIMPLE): | ||
var result = null | ||
if(diff_type == _utils.DIFF.SIMPLE): | ||
result = simple(v1, v2) | ||
elif(diff_type == _utils.DIFF.SHALLOW): | ||
result = shallow(v1, v2) | ||
elif(diff_type == _utils.DIFF.DEEP): | ||
result = deep(v1, v2) | ||
|
||
return result | ||
|
||
|
||
func get_should_compare_int_to_float(): | ||
return _should_compare_int_to_float | ||
|
||
|
||
func set_should_compare_int_to_float(should_compare_int_float): | ||
_should_compare_int_to_float = should_compare_int_float | ||
|
||
|
||
func get_compare_symbol(is_equal): | ||
if(is_equal): | ||
return '==' | ||
else: | ||
return '!=' |
Oops, something went wrong.