fromJson static method

EntityKindHints fromJson(
  1. Object? json
)

What json holds, as toJson writes it. Throws a DocumentFormatException for anything else.

Implementation

static EntityKindHints fromJson(Object? json) {
  if (json is! Map) {
    throw DocumentFormatException('an entity kind\'s hints are a map: $json');
  }
  final type = _named(json, 'type', 'an entity kind');
  return EntityKindHints(
    type: type,
    label: switch (json['label']) {
      final String label => label,
      _ => null,
    },
    tint: switch (json['tint']) {
      null => null,
      [final num r, final num g, final num b] => LinearColor(
        r.toDouble(),
        g.toDouble(),
        b.toDouble(),
      ),
      final other => throw DocumentFormatException(
        'the entity kind "$type" has "tint" $other, which is not three '
        'numbers',
      ),
    },
    fields: _fieldsOf(json['fields'], 'the entity kind "$type"'),
    components: _wordsOf(
      json['components'],
      'the entity kind "$type"',
      'components',
    ),
  );
}