Skip to content

Commit

Permalink
Register notification function
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed Oct 13, 2024
1 parent c03b3eb commit d521847
Show file tree
Hide file tree
Showing 21 changed files with 580 additions and 567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/AnonymousPro-Bold.ttf-9d8fef4d357af5b52cd60af
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/AnonymousPro-BoldItalic.ttf-4274bf704d3d6b9cd
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/AnonymousPro-Italic.ttf-9989590b02137b799e13d
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/AnonymousPro-Regular.ttf-856c843fd6f89964d2ca
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/CourierPrime-Bold.ttf-1f003c66d63ebed70964e77
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/CourierPrime-BoldItalic.ttf-65ebcc61dd5e1dfa8
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/CourierPrime-Italic.ttf-baa9156a73770735a0f72
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/CourierPrime-Regular.ttf-3babe7e4a7a588dfc9a8
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
1 change: 1 addition & 0 deletions harness/tests/addons/gut/fonts/LobsterTwo-Bold.ttf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/LobsterTwo-Bold.ttf-7c7f734103b58a32491a47881
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/LobsterTwo-BoldItalic.ttf-227406a33e84448e6aa
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/LobsterTwo-Italic.ttf-f93abf6c25390c85ad5fb6c
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/LobsterTwo-Regular.ttf-f3fcfa01cd671c8da433dd
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
260 changes: 130 additions & 130 deletions harness/tests/addons/gut/strutils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,172 +7,172 @@ var _utils = load('res://addons/gut/utils.gd').get_instance()
var types = {}

func _init_types_dictionary():
types[TYPE_AABB] = 'AABB'
types[TYPE_ARRAY] = 'ARRAY'
types[TYPE_BASIS] = 'BASIS'
types[TYPE_BOOL] = 'BOOL'
types[TYPE_CALLABLE] = 'CALLABLE'
types[TYPE_COLOR] = 'COLOR'
types[TYPE_DICTIONARY] = 'DICTIONARY'
types[TYPE_FLOAT] = 'FLOAT'
types[TYPE_INT] = 'INT'
types[TYPE_MAX] = 'MAX'
types[TYPE_NODE_PATH] = 'NODE_PATH'
types[TYPE_OBJECT] = 'OBJECT'
types[TYPE_PACKED_BYTE_ARRAY] = 'PACKED_BYTE_ARRAY'
types[TYPE_PACKED_COLOR_ARRAY] = 'PACKED_COLOR_ARRAY'
types[TYPE_PACKED_FLOAT32_ARRAY] = 'PACKED_FLOAT32_ARRAY'
types[TYPE_PACKED_FLOAT64_ARRAY] = 'PACKED_FLOAT64_ARRAY'
types[TYPE_PACKED_INT32_ARRAY] = 'PACKED_INT32_ARRAY'
types[TYPE_PACKED_INT64_ARRAY] = 'PACKED_INT64_ARRAY'
types[TYPE_PACKED_STRING_ARRAY] = 'PACKED_STRING_ARRAY'
types[TYPE_PACKED_VECTOR2_ARRAY] = 'PACKED_VECTOR2_ARRAY'
types[TYPE_PACKED_VECTOR3_ARRAY] = 'PACKED_VECTOR3_ARRAY'
types[TYPE_PLANE] = 'PLANE'
types[TYPE_PROJECTION] = 'PROJECTION'
types[TYPE_QUATERNION] = 'QUATERNION'
types[TYPE_RECT2] = 'RECT2'
types[TYPE_RECT2I] = 'RECT2I'
types[TYPE_RID] = 'RID'
types[TYPE_SIGNAL] = 'SIGNAL'
types[TYPE_STRING_NAME] = 'STRING_NAME'
types[TYPE_STRING] = 'STRING'
types[TYPE_TRANSFORM2D] = 'TRANSFORM2D'
types[TYPE_TRANSFORM3D] = 'TRANSFORM3D'
types[TYPE_VECTOR2] = 'VECTOR2'
types[TYPE_VECTOR2I] = 'VECTOR2I'
types[TYPE_VECTOR3] = 'VECTOR3'
types[TYPE_VECTOR3I] = 'VECTOR3I'
types[TYPE_VECTOR4] = 'VECTOR4'
types[TYPE_VECTOR4I] = 'VECTOR4I'
types[TYPE_AABB] = 'AABB'
types[TYPE_ARRAY] = 'ARRAY'
types[TYPE_BASIS] = 'BASIS'
types[TYPE_BOOL] = 'BOOL'
types[TYPE_CALLABLE] = 'CALLABLE'
types[TYPE_COLOR] = 'COLOR'
types[TYPE_DICTIONARY] = 'DICTIONARY'
types[TYPE_FLOAT] = 'FLOAT'
types[TYPE_INT] = 'INT'
types[TYPE_MAX] = 'MAX'
types[TYPE_NODE_PATH] = 'NODE_PATH'
types[TYPE_OBJECT] = 'OBJECT'
types[TYPE_PACKED_BYTE_ARRAY] = 'PACKED_BYTE_ARRAY'
types[TYPE_PACKED_COLOR_ARRAY] = 'PACKED_COLOR_ARRAY'
types[TYPE_PACKED_FLOAT32_ARRAY] = 'PACKED_FLOAT32_ARRAY'
types[TYPE_PACKED_FLOAT64_ARRAY] = 'PACKED_FLOAT64_ARRAY'
types[TYPE_PACKED_INT32_ARRAY] = 'PACKED_INT32_ARRAY'
types[TYPE_PACKED_INT64_ARRAY] = 'PACKED_INT64_ARRAY'
types[TYPE_PACKED_STRING_ARRAY] = 'PACKED_STRING_ARRAY'
types[TYPE_PACKED_VECTOR2_ARRAY] = 'PACKED_VECTOR2_ARRAY'
types[TYPE_PACKED_VECTOR3_ARRAY] = 'PACKED_VECTOR3_ARRAY'
types[TYPE_PLANE] = 'PLANE'
types[TYPE_PROJECTION] = 'PROJECTION'
types[TYPE_QUATERNION] = 'QUATERNION'
types[TYPE_RECT2] = 'RECT2'
types[TYPE_RECT2I] = 'RECT2I'
types[TYPE_RID] = 'RID'
types[TYPE_SIGNAL] = 'SIGNAL'
types[TYPE_STRING_NAME] = 'STRING_NAME'
types[TYPE_STRING] = 'STRING'
types[TYPE_TRANSFORM2D] = 'TRANSFORM2D'
types[TYPE_TRANSFORM3D] = 'TRANSFORM3D'
types[TYPE_VECTOR2] = 'VECTOR2'
types[TYPE_VECTOR2I] = 'VECTOR2I'
types[TYPE_VECTOR3] = 'VECTOR3'
types[TYPE_VECTOR3I] = 'VECTOR3I'
types[TYPE_VECTOR4] = 'VECTOR4'
types[TYPE_VECTOR4I] = 'VECTOR4I'

# Types to not be formatted when using _str
var _str_ignore_types = [
TYPE_INT, TYPE_FLOAT, TYPE_STRING,
TYPE_NIL, TYPE_BOOL
TYPE_INT, TYPE_FLOAT, TYPE_STRING,
TYPE_NIL, TYPE_BOOL
]

func _init():
_init_types_dictionary()
_init_types_dictionary()

# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
func _get_filename(path):
return path.split('/')[-1]
return path.split('/')[-1]

# ------------------------------------------------------------------------------
# Gets the filename of an object passed in. This does not return the
# full path to the object, just the filename.
# ------------------------------------------------------------------------------
func _get_obj_filename(thing):
var filename = null

if(thing == null or
_utils.is_native_class(thing) or
!is_instance_valid(thing) or
str(thing) == '<Object#null>' or
typeof(thing) != TYPE_OBJECT or
_utils.is_double(thing)):
return

if(thing.get_script() == null):
if(thing is PackedScene):
filename = _get_filename(thing.resource_path)
else:
# If it isn't a packed scene and it doesn't have a script then
# we do nothing. This just reads better.
pass
elif(!_utils.is_native_class(thing)):
var dict = inst_to_dict(thing)
filename = _get_filename(dict['@path'])
if(str(dict['@subpath']) != ''):
filename += str('/', dict['@subpath'])

return filename
var filename = null

if(thing == null or
_utils.is_native_class(thing) or
!is_instance_valid(thing) or
str(thing) == '<Object#null>' or
typeof(thing) != TYPE_OBJECT or
_utils.is_double(thing)):
return

if(thing.get_script() == null):
if(thing is PackedScene):
filename = _get_filename(thing.resource_path)
else:
# If it isn't a packed scene and it doesn't have a script then
# we do nothing. This just reads better.
pass
elif(!_utils.is_native_class(thing)):
var dict = inst_to_dict(thing)
filename = _get_filename(dict['@path'])
if(str(dict['@subpath']) != ''):
filename += str('/', dict['@subpath'])

return filename

# ------------------------------------------------------------------------------
# Better object/thing to string conversion. Includes extra details about
# whatever is passed in when it can/should.
# ------------------------------------------------------------------------------
func type2str(thing):
var filename = _get_obj_filename(thing)
var str_thing = str(thing)

if(thing == null):
# According to str there is a difference between null and an Object
# that is somehow null. To avoid getting '[Object:null]' as output
# always set it to str(null) instead of str(thing). A null object
# will pass typeof(thing) == TYPE_OBJECT check so this has to be
# before that.
str_thing = str(null)
elif(typeof(thing) == TYPE_FLOAT):
if(!'.' in str_thing):
str_thing += '.0'
elif(typeof(thing) == TYPE_STRING):
str_thing = str('"', thing, '"')
elif(typeof(thing) in _str_ignore_types):
# do nothing b/c we already have str(thing) in
# to_return. I think this just reads a little
# better this way.
pass
elif(typeof(thing) == TYPE_OBJECT):
if(_utils.is_native_class(thing)):
str_thing = _utils.get_native_class_name(thing)
elif(_utils.is_double(thing)):
var double_path = _get_filename(thing.__gutdbl.thepath)
if(thing.__gutdbl.subpath != ''):
double_path += str('/', thing.__gutdbl.subpath)
elif(thing.__gutdbl.from_singleton != ''):
double_path = thing.__gutdbl.from_singleton + " Singleton"

var double_type = "double"
if(thing.__gutdbl.is_partial):
double_type = "partial-double"

str_thing += str("(", double_type, " of ", double_path, ")")

filename = null
elif(types.has(typeof(thing))):
if(!str_thing.begins_with('(')):
str_thing = '(' + str_thing + ')'
str_thing = str(types[typeof(thing)], str_thing)

if(filename != null):
str_thing += str('(', filename, ')')
return str_thing
var filename = _get_obj_filename(thing)
var str_thing = str(thing)

if(thing == null):
# According to str there is a difference between null and an Object
# that is somehow null. To avoid getting '[Object:null]' as output
# always set it to str(null) instead of str(thing). A null object
# will pass typeof(thing) == TYPE_OBJECT check so this has to be
# before that.
str_thing = str(null)
elif(typeof(thing) == TYPE_FLOAT):
if(!'.' in str_thing):
str_thing += '.0'
elif(typeof(thing) == TYPE_STRING):
str_thing = str('"', thing, '"')
elif(typeof(thing) in _str_ignore_types):
# do nothing b/c we already have str(thing) in
# to_return. I think this just reads a little
# better this way.
pass
elif(typeof(thing) == TYPE_OBJECT):
if(_utils.is_native_class(thing)):
str_thing = _utils.get_native_class_name(thing)
elif(_utils.is_double(thing)):
var double_path = _get_filename(thing.__gutdbl.thepath)
if(thing.__gutdbl.subpath != ''):
double_path += str('/', thing.__gutdbl.subpath)
elif(thing.__gutdbl.from_singleton != ''):
double_path = thing.__gutdbl.from_singleton + " Singleton"

var double_type = "double"
if(thing.__gutdbl.is_partial):
double_type = "partial-double"

str_thing += str("(", double_type, " of ", double_path, ")")

filename = null
elif(types.has(typeof(thing))):
if(!str_thing.begins_with('(')):
str_thing = '(' + str_thing + ')'
str_thing = str(types[typeof(thing)], str_thing)

if(filename != null):
str_thing += str('(', filename, ')')
return str_thing

# ------------------------------------------------------------------------------
# Returns the string truncated with an '...' in it. Shows the start and last
# 10 chars. If the string is smaller than max_size the entire string is
# returned. If max_size is -1 then truncation is skipped.
# ------------------------------------------------------------------------------
func truncate_string(src, max_size):
var to_return = src
if(src.length() > max_size - 10 and max_size != -1):
to_return = str(src.substr(0, max_size - 10), '...', src.substr(src.length() - 10, src.length()))
return to_return
var to_return = src
if(src.length() > max_size - 10 and max_size != -1):
to_return = str(src.substr(0, max_size - 10), '...', src.substr(src.length() - 10, src.length()))
return to_return


func _get_indent_text(times, pad):
var to_return = ''
for i in range(times):
to_return += pad
var to_return = ''
for i in range(times):
to_return += pad

return to_return
return to_return

func indent_text(text, times, pad):
if(times == 0):
return text
if(times == 0):
return text

var to_return = text
var ending_newline = ''
var to_return = text
var ending_newline = ''

if(text.ends_with("\n")):
ending_newline = "\n"
to_return = to_return.left(to_return.length() -1)
if(text.ends_with("\n")):
ending_newline = "\n"
to_return = to_return.left(to_return.length() -1)

var padding = _get_indent_text(times, pad)
to_return = to_return.replace("\n", "\n" + padding)
to_return += ending_newline
var padding = _get_indent_text(times, pad)
to_return = to_return.replace("\n", "\n" + padding)
to_return += ending_newline

return padding + to_return
return padding + to_return
Loading

0 comments on commit d521847

Please sign in to comment.