/// <summary>
 /// Initializes a new instance of the <see cref="LottieComposition"/> class.
 /// </summary>
 /// <param name="name">The name of the composition.</param>
 /// <param name="width">Width of animation canvas as specified in After Effects.</param>
 /// <param name="height">Height of animation canvas as specified in After Effects.</param>
 /// <param name="inPoint">Frame at which animation begins as specified in After Effects.</param>
 /// <param name="outPoint">Frame at which animation ends as specified in After Effects.</param>
 /// <param name="framesPerSecond">FrameRate (frames per second) at which animation data was generated in After Effects.</param>
 /// <param name="is3d">True if the composition is 3d.</param>
 /// <param name="version">The version of the schema of the composition.</param>
 /// <param name="assets">Assets that are part of the composition.</param>
 /// <param name="chars">Character definitions that are part of the composition.</param>
 /// <param name="fonts">Font definitions that are part of the composition.</param>
 /// <param name="layers">The layers in the composition.</param>
 /// <param name="markers">Markers that define named portions of the composition.</param>
 /// <param name="extraData">Extra data that is related to the composition but is not part of the BodyMovin schema.</param>
 public LottieComposition(
     string name,
     double width,
     double height,
     double inPoint,
     double outPoint,
     double framesPerSecond,
     bool is3d,
     Version version,
     AssetCollection assets,
     IEnumerable <Char> chars,
     IEnumerable <Font> fonts,
     LayerCollection layers,
     IEnumerable <Marker> markers,
     GenericDataMap extraData)
     : base(name)
 {
     Is3d            = is3d;
     Width           = width;
     Height          = height;
     InPoint         = inPoint;
     OutPoint        = outPoint;
     FramesPerSecond = framesPerSecond;
     Duration        = TimeSpan.FromSeconds((outPoint - inPoint) / framesPerSecond);
     Version         = version;
     Layers          = layers;
     Assets          = assets;
     Chars           = chars.ToArray();
     ExtraData       = extraData;
     Fonts           = fonts.ToArray();
     Markers         = markers.ToArray();
 }
Esempio n. 2
0
 internal TranslationResult(
     Visual rootVisual,
     IEnumerable <TranslationIssue> translationIssues,
     uint minimumRequiredUapVersion,
     GenericDataMap sourceMetadata)
 {
     RootVisual                = rootVisual;
     TranslationIssues         = translationIssues.ToArray();
     MinimumRequiredUapVersion = minimumRequiredUapVersion;
     SourceMetadata            = sourceMetadata;
 }
        internal static GenericDataObject JTokenToGenericData(JToken token)
        {
            switch (token.Type)
            {
            case JTokenType.Object:
                var jobject = (IEnumerable <KeyValuePair <string, JToken> >)token;
                return(GenericDataMap.Create(jobject.ToDictionary(field => field.Key, field => JTokenToGenericData(field.Value))));

            case JTokenType.Array:
                return(GenericDataList.Create(((JArray)token).Select(item => JTokenToGenericData(item))));

            case JTokenType.Integer:
                return(GenericDataNumber.Create((long)token));

            case JTokenType.Float:
                return(GenericDataNumber.Create((double)token));

            case JTokenType.String:
                return(GenericDataString.Create((string)token));

            case JTokenType.Boolean:
                return(GenericDataBool.Create((bool)token));

            case JTokenType.Null:
                return(null);

            // Currently unsupported types.
            case JTokenType.None:
            case JTokenType.Constructor:
            case JTokenType.Property:
            case JTokenType.Comment:
            case JTokenType.Undefined:
            case JTokenType.Date:
            case JTokenType.Raw:
            case JTokenType.Bytes:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.TimeSpan:
                throw new InvalidOperationException($"Unsupported JSON token type: {token.Type}");

            default:
                throw new InvalidOperationException("Unreachable code executed.");
            }
        }
            internal GenericDataObject ToGenericDataObject()
            {
                switch (Kind)
                {
                case JsonValueKind.Object:

                    var obj  = AsObject().Value;
                    var dict = new Dictionary <string, GenericDataObject>();
                    foreach (var property in obj)
                    {
                        dict.Add(property.Key, property.Value.ToGenericDataObject());
                    }

                    return(GenericDataMap.Create(dict));

                case JsonValueKind.Array:
                    return(GenericDataList.Create(AsArray().Value.Select <GenericDataObject>(elem => elem.ToGenericDataObject())));

                case JsonValueKind.String:
                    return(GenericDataString.Create(AsString()));

                case JsonValueKind.Number:
                    return(GenericDataNumber.Create(AsDouble().Value));

                case JsonValueKind.True:
                    return(GenericDataBool.True);

                case JsonValueKind.False:
                    return(GenericDataBool.False);

                case JsonValueKind.Null:
                    return(null);

                default:
                    throw Exceptions.Unreachable;
                }
            }