fray icon indicating copy to clipboard operation
fray copied to clipboard

FrayCompoundState : change ready ordering for substate

Open Remi123 opened this issue 1 year ago • 2 comments

Welcome back.

Didn't play too much with new features yet, but I appreciate the get_node function. Reduce my code size by a lot.

here is my change for the ready function :

func ready(context: Dictionary) -> void:
	if not context.is_read_only():
		context.make_read_only()
	_ready_impl(context) # <--- new emplacement
	for state_name in _states:
		var state: FrayState = _states[state_name]

		if state is FrayCompoundState:
			state.ready(context)
		else:
			state._ready_impl(context)
        #_ready_impl(context) # <--- Changed ordering

I use _ready_impl to create new states and keep things together in the code.

Substate are created in _ready_impl, then each of them are made ready afterward.

Thank you

Remi123 avatar Jan 30 '24 03:01 Remi123

There is a _enter_tree_impl method which is invoked when a state is added to the hierarchy. You should be able to create new sub-states within this... That is unless you're using the context as part of your setup. Though i'd argue the sub-states could just read from the context themselves.

Let me know your thoughts. I'm not opposed to changing the ready order since, at this moment, I don't see any downsides to readying the parent then the children. I just don't believe this change is necessary for what you're trying to do.

Edit: Wanted to add I think i'll note your approach in the documentation. I hadn't considered building states within states.

Pyxus avatar Feb 15 '24 23:02 Pyxus

I tried the _enter_tree_impl, however at this point not all nodes are ready, so I am missing some content when initialized. Then it become fighting my node tree order of initialization..

I tried to fixes this by modifying the _ready part, and it work correctly so I'm quite happy with this.

Remi123 avatar Feb 16 '24 04:02 Remi123