Made CallableNode wait until its designated parent is in the tree and it itself is not. (Before, it only checked if it itself was in the tree, and handled it by removing itself from the tree instead of by waiting.) Fixed variable shadowing warnings.
This commit is contained in:
parent
47b4c1f17a
commit
ac3a57dc05
|
@ -11,7 +11,11 @@ var result: Variant = null
|
||||||
## Calls the CallableNode, waits for it to finish, and returns its result.
|
## Calls the CallableNode, waits for it to finish, and returns its result.
|
||||||
##
|
##
|
||||||
## When a CallableNode is called, the following sequence of events occurs:
|
## When a CallableNode is called, the following sequence of events occurs:
|
||||||
## 1. if the CallableNode is in the tree, it is removed;
|
## 1. we wait for the parent node to be in the tree
|
||||||
|
## and self to be out of the tree at the same time
|
||||||
|
## (if this never happens, then the function will never terminate,
|
||||||
|
## and thus any await subscribers will never be notified
|
||||||
|
## and will themselves never terminate);
|
||||||
## 2. the CallableNode is passed the given args and opts;
|
## 2. the CallableNode is passed the given args and opts;
|
||||||
## 3. the CallableNode is requested to call _ready,
|
## 3. the CallableNode is requested to call _ready,
|
||||||
## and then added as a child to the parent;
|
## and then added as a child to the parent;
|
||||||
|
@ -34,8 +38,9 @@ func invoke_existing(
|
||||||
var prev_process_mode := process_mode
|
var prev_process_mode := process_mode
|
||||||
var parent_prev_process_mode := parent.process_mode
|
var parent_prev_process_mode := parent.process_mode
|
||||||
# step 1
|
# step 1
|
||||||
if is_inside_tree():
|
var ok := func() -> bool:
|
||||||
get_parent().remove_child(self)
|
return parent.is_inside_tree() and not is_inside_tree()
|
||||||
|
await Wait.until(ok)
|
||||||
# step 2
|
# step 2
|
||||||
args = p_args
|
args = p_args
|
||||||
opts = p_opts
|
opts = p_opts
|
||||||
|
@ -76,18 +81,18 @@ func invoke_existing(
|
||||||
static func invoke(
|
static func invoke(
|
||||||
what: Variant,
|
what: Variant,
|
||||||
parent: Node,
|
parent: Node,
|
||||||
args: Array = [],
|
p_args: Array = [],
|
||||||
opts: Dictionary = {}
|
p_opts: Dictionary = {}
|
||||||
) -> Variant:
|
) -> Variant:
|
||||||
if what is CallableNode:
|
if what is CallableNode:
|
||||||
return await what.invoke_existing(parent, args, opts)
|
return await what.invoke_existing(parent, p_args, p_opts)
|
||||||
elif what is PackedScene:
|
elif what is PackedScene:
|
||||||
var inst := what.instantiate() as Node
|
var inst := what.instantiate() as Node
|
||||||
var cn := inst as CallableNode
|
var cn := inst as CallableNode
|
||||||
if cn:
|
if cn:
|
||||||
var result = await cn.invoke_existing(parent, args, opts)
|
var p_result = await cn.invoke_existing(parent, p_args, p_opts)
|
||||||
cn.queue_free()
|
cn.queue_free()
|
||||||
return result
|
return p_result
|
||||||
elif inst:
|
elif inst:
|
||||||
push_error(
|
push_error(
|
||||||
"Tried to invoke a PackedScene " +
|
"Tried to invoke a PackedScene " +
|
||||||
|
@ -102,9 +107,9 @@ static func invoke(
|
||||||
var inst = what.new()
|
var inst = what.new()
|
||||||
var cn := inst as CallableNode
|
var cn := inst as CallableNode
|
||||||
if cn:
|
if cn:
|
||||||
var result = await cn.invoke_existing(parent, args, opts)
|
var p_result = await cn.invoke_existing(parent, p_args, p_opts)
|
||||||
cn.queue_free()
|
cn.queue_free()
|
||||||
return result
|
return p_result
|
||||||
elif inst:
|
elif inst:
|
||||||
push_error(
|
push_error(
|
||||||
"Tried to invoke a GDScript not derived from CallableNode: " +
|
"Tried to invoke a GDScript not derived from CallableNode: " +
|
||||||
|
@ -116,7 +121,7 @@ static func invoke(
|
||||||
else:
|
else:
|
||||||
return null
|
return null
|
||||||
elif what is String:
|
elif what is String:
|
||||||
return await CallableNode.invoke(load(what), parent, args, opts)
|
return await CallableNode.invoke(load(what), parent, p_args, p_opts)
|
||||||
else:
|
else:
|
||||||
push_error("No way to infer a CallableNode from value: %s" % what)
|
push_error("No way to infer a CallableNode from value: %s" % what)
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue