fromJSON method

  1. @override
Think fromJSON(
  1. Map<String, dynamic> json
)
override

Restores this instance from the given JSON object.

Implementation

@override
Think fromJSON(Map<String,dynamic> json ) {
	super.fromJSON( json );

	final typesMap = _typesMap;

	evaluators.length = 0;
	terminate();

	// evaluators
	for ( int i = 0, l = json['evaluators'].length; i < l; i ++ ) {
		final evaluatorJSON = json['evaluators'][ i ];
		final type = evaluatorJSON['type'];
		final ctor = typesMap[type];

		if ( ctor != null ) {
			final evaluator = ctor().fromJSON( evaluatorJSON );
			evaluators.add( evaluator );
		}
      else {
			yukaConsole.warning( 'YUKA.Think: Unsupported goal evaluator type: $type');
			continue;
		}
	}

	// goals
	parseGoal(Map<String,dynamic> goalJSON ) {
		final type = goalJSON['type'];
		final ctor = typesMap[type];

		if ( ctor != null ) {
			final goal = ctor().fromJSON( goalJSON );
			final subgoalsJSON = goalJSON['subgoals'];

			if ( subgoalsJSON != null ) {

				// composite goal
				for ( int i = 0, l = subgoalsJSON.length; i < l; i ++ ) {
					final subgoal = parseGoal( subgoalsJSON[ i ] );
					if ( subgoal ) goal.subgoals.add( subgoal );
				}
			}

			return goal;
		}
      else {
			yukaConsole.warning( 'YUKA.Think: Unsupported goal evaluator type: $type' );
			return;
		}
	}

	for ( int i = 0, l = json['subgoals'].length; i < l; i ++ ) {
		final subgoal = parseGoal( json['subgoals'][ i ] );
		if ( subgoal ) subgoals.add( subgoal );
	}

	return this;
}