WorldBehavior.fromJson constructor
WorldBehavior.fromJson(
- Map<String, dynamic> json
)
Implementation
factory WorldBehavior.fromJson(Map<String, dynamic> json) {
final id = json['id'] as String? ?? '';
final touchpoint = json['touchpoint'] as String? ?? '';
final method = json['method'] as String? ?? '';
if (id.isEmpty || touchpoint.isEmpty || method.isEmpty) {
throw const WorldManifestError(
'behavior without id/touchpoint/method --> fix: every behaviors[] '
'entry needs "id", "driver", "touchpoint", and "method".',
);
}
return WorldBehavior(
id: id,
driver: json['driver'] as String? ?? 'invoke',
touchpoint: touchpoint,
method: method,
args: Map<String, dynamic>.from(
json['args'] as Map? ?? const <String, dynamic>{},
),
maxAttempts: (json['maxAttempts'] as num?)?.toInt() ?? 3,
backoffBaseMs: (json['backoffBaseMs'] as num?)?.toInt() ?? 50,
backoffFactor: (json['backoffFactor'] as num?)?.toDouble() ?? 2.0,
expect: json['expect'] as String? ?? 'green',
);
}