restoreFrom method
Restores this logic block's state and blackboard from another logic
block of the same type.
Stops this logic block first, then copies the blackboard and state from
the source. Throws a StateError if logic has not been started.
Implementation
void restoreFrom(LogicBlock<TState> logic) {
final state = logic.valueAsObject ?? logic._restoredState;
if (state == null) {
throw StateError(
"Cannot restore from the logic block $logic that hasn't been started "
'yet.',
);
}
stop();
for (final type in logic.blackboard.types) {
blackboard.overwriteObject(type, logic.blackboard.getObject(type));
}
final stateType = state.runtimeType;
blackboard.overwriteObject(stateType, state);
restoreState(state);
}