defaultEntityFromJsonFunction function

Entity defaultEntityFromJsonFunction(
  1. Map<String, dynamic> json,
  2. EntitySystem system
)

Implementation

Entity defaultEntityFromJsonFunction(Map<String, dynamic> json, EntitySystem system) {
  var e = Entity(json['guid'], system);
  if (json['components'] != null) {
    final comps = json['components'] as List<dynamic>;
    for (var compData in comps) {
      final data = compData as Map<String, dynamic>;
      Component? c = componentFromJson(data);
      // if not contained in default system, check serializers.
      if (c == null) {
        for (var serializer in system.deserializers) {
          c = serializer.call(data);
        }
      }

      /// If we actually got a component, add it.
      if (c != null) {
        e += c;
      }
    }
  }

  return e;
}