summaryrefslogtreecommitdiff
path: root/addons/gut/method_maker.gd
diff options
context:
space:
mode:
Diffstat (limited to 'addons/gut/method_maker.gd')
-rw-r--r--addons/gut/method_maker.gd55
1 files changed, 42 insertions, 13 deletions
diff --git a/addons/gut/method_maker.gd b/addons/gut/method_maker.gd
index a807e26..11586b9 100644
--- a/addons/gut/method_maker.gd
+++ b/addons/gut/method_maker.gd
@@ -58,6 +58,7 @@ const PARAM_PREFIX = 'p_'
# TYPE_RID = 16 — Variable is of type RID.
# TYPE_INT_ARRAY = 21 — Variable is of type PoolIntArray.
# TYPE_REAL_ARRAY = 22 — Variable is of type PoolRealArray.
+ # TYPE_STRING_ARRAY = 23 — Variable is of type PoolStringArray.
# TYPE_PLANE = 9 — Variable is of type Plane.
@@ -66,7 +67,6 @@ const PARAM_PREFIX = 'p_'
# TYPE_BASIS = 12 — Variable is of type Basis.
# TYPE_NODE_PATH = 15 — Variable is of type NodePath.
# TYPE_RAW_ARRAY = 20 — Variable is of type PoolByteArray.
-# TYPE_STRING_ARRAY = 23 — Variable is of type PoolStringArray.
# TYPE_VECTOR3_ARRAY = 25 — Variable is of type PoolVector3Array.
# TYPE_COLOR_ARRAY = 26 — Variable is of type PoolColorArray.
# TYPE_MAX = 27 — Marker for end of type constants.
@@ -98,14 +98,16 @@ func _init():
_supported_defaults[TYPE_TRANSFORM] = 'Transform'
_supported_defaults[TYPE_INT_ARRAY] = 'PoolIntArray'
_supported_defaults[TYPE_REAL_ARRAY] = 'PoolRealArray'
+ _supported_defaults[TYPE_STRING_ARRAY] = 'PoolStringArray'
# ###############
# Private
# ###############
var _func_text = _utils.get_file_as_text('res://addons/gut/double_templates/function_template.txt')
+var _init_text = _utils.get_file_as_text('res://addons/gut/double_templates/init_template.txt')
func _is_supported_default(type_flag):
- return type_flag >= 0 and type_flag < _supported_defaults.size() and [type_flag] != null
+ return type_flag >= 0 and type_flag < _supported_defaults.size() and _supported_defaults[type_flag] != null
func _make_stub_default(method, index):
@@ -139,7 +141,7 @@ func _make_arg_array(method_meta, override_size):
else:
dflt_text = str(_supported_defaults[t], str(method_meta.default_args[dflt_idx]).to_lower())
elif(t == TYPE_TRANSFORM):
- #value will be 4 Vector3 and look like: 1, 0, 0, 0, 1, 0, 0, 0, 1 - 0, 0, 0
+ # value will be 4 Vector3 and look like: 1, 0, 0, 0, 1, 0, 0, 0, 1 - 0, 0, 0
var sections = str(method_meta.default_args[dflt_idx]).split("-")
var vecs = sections[0].split(",")
vecs.append_array(sections[1].split(","))
@@ -157,10 +159,9 @@ func _make_arg_array(method_meta, override_size):
dflt_text = str(_supported_defaults[t], "(", vectors, ")")
elif(t == TYPE_RID):
dflt_text = str(_supported_defaults[t], 'null')
- elif(t in [TYPE_REAL_ARRAY, TYPE_INT_ARRAY]):
+ elif(t in [TYPE_REAL_ARRAY, TYPE_INT_ARRAY, TYPE_STRING_ARRAY]):
dflt_text = str(_supported_defaults[t], "()")
-
- # Everything else puts the prefix (if one is there) form _supported_defaults
+ # Everything else puts the prefix (if one is there) from _supported_defaults
# in front. The to_lower is used b/c for some reason the defaults for
# null, true, false are all "Null", "True", "False".
else:
@@ -230,10 +231,35 @@ func _get_spy_call_parameters_text(args):
# Public
# ###############
+func _get_init_text(meta, args, method_params, param_array):
+ var text = null
+
+ var decleration = str('func ', meta.name, '(', method_params, ')')
+ var super_params = ''
+ if(args.size() > 0):
+ super_params = '.('
+ for i in range(args.size()):
+ super_params += args[i].p_name
+ if(i != args.size() -1):
+ super_params += ', '
+ super_params += ')'
+
+ text = _init_text.format({
+ "func_decleration":decleration,
+ "super_params":super_params,
+ "param_array":param_array,
+ "method_name":meta.name
+ })
+
+ return text
+
+
# Creates a delceration for a function based off of function metadata. All
# types whose defaults are supported will have their values. If a datatype
# is not supported and the parameter has a default, a warning message will be
# printed and the declaration will return null.
+#
+# path is no longer used
func get_function_text(meta, path=null, override_size=null, super_name=""):
var method_params = ''
var text = null
@@ -255,13 +281,16 @@ func get_function_text(meta, path=null, override_size=null, super_name=""):
param_array = '[]'
if(method_params != null):
- var decleration = str('func ', meta.name, '(', method_params, '):')
- text = _func_text.format({
- "func_decleration":decleration,
- "method_name":meta.name,
- "param_array":param_array,
- "super_call":_get_super_call_text(meta.name, args, super_name)
- })
+ if(meta.name == '_init'):
+ text = _get_init_text(meta, args, method_params, param_array)
+ else:
+ var decleration = str('func ', meta.name, '(', method_params, '):')
+ text = _func_text.format({
+ "func_decleration":decleration,
+ "method_name":meta.name,
+ "param_array":param_array,
+ "super_call":_get_super_call_text(meta.name, args, super_name)
+ })
return text