Exemple #1
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                EntitySerializationContainer container =
                    (EntitySerializationContainer)existingValue ?? new EntitySerializationContainer();

                var serializedEntities = serializer.Deserialize <List <ContentEntitySerializationFormat> >(reader);

                // We need to get our conversion context
                GeneralStreamingContext generalContext    = (GeneralStreamingContext)serializer.Context.Context;
                EntityConversionContext conversionContext = generalContext.Get <EntityConversionContext>();
                GameEngineContext       engineContext     = generalContext.Get <GameEngineContext>();

                // There is only an EventDispatcherContext when we have a GameEngineContext
                IEventDispatcher eventDispatcher = null;

                if (engineContext.GameEngine.Exists)
                {
                    EventDispatcherContext eventContext = generalContext.Get <EventDispatcherContext>();
                    eventDispatcher = eventContext.Dispatcher;
                }

                // Restore our created entity instances
                List <IEntity> restored = new List <IEntity>();

                foreach (ContentEntitySerializationFormat format in serializedEntities)
                {
                    int     entityId = format.UniqueId;
                    IEntity entity   = conversionContext.GetEntityInstance(entityId, engineContext);
                    restored.Add(entity);

                    if (entity is ContentEntity)
                    {
                        ((ContentEntity)entity).Initialize(format);
                    }
                    else
                    {
                        ((RuntimeEntity)entity).Initialize(format, eventDispatcher);
                    }
                }

                container.Entities = restored;
                return(container);
            }
Exemple #2
0
 /// <summary>
 /// Called to set up a destination from a source.
 /// </summary>
 public void Convert(EntityConversionContext <TSource, TDestination> conversionContext)
 {
     throw new System.NotImplementedException();
 }