Пример #1
0
        public void Initialize(ContentEntitySerializationFormat format, IEventDispatcher eventDispatcher)
        {
            _eventDispatcher = eventDispatcher;
            _uniqueId        = format.UniqueId;
            PrettyName       = format.PrettyName ?? "";

            foreach (ContentEntity.DataInstance data in format.Data)
            {
                DataAccessor accessor = new DataAccessor(data.CurrentData);

                if (data.WasAdded)
                {
                    _toAddStage1.Add(data.CurrentData);
                }

                else
                {
                    if (data.CurrentData is Data.NonVersioned)
                    {
                        _data[accessor.Id] = new NonVersionedDataContainer(
                            (Data.NonVersioned)data.CurrentData);
                    }

                    else
                    {
                        _data[accessor.Id] = new VersionedDataContainer(
                            (Data.IVersioned)data.PreviousData,
                            (Data.IVersioned)data.CurrentData,
                            (Data.IVersioned)data.CurrentData.Duplicate());
                    }

                    // There is going to be an ApplyModification call before systems actually view
                    // this Entity instance. With that in mind, we can treat our data initialization
                    // as if if were operating on the previous frame.

                    if (data.WasModified)
                    {
                        // This is kind of an ugly hack, because to get the correct Previous/Current
                        // data we need to move Previous into Current so that Previous will reflect
                        // the true Previous value, not the Current one.

                        // Internal signal that a modification is going to take place
                        Modify(accessor);

                        if (data.CurrentData is Data.IVersioned)
                        {
                            // Move Previous into Current, so that after the ApplyModification we
                            // have the correct data values
                            var container = (VersionedDataContainer)_data[accessor.Id];
                            container.Current.CopyFrom(container.Previous);
                        }
                    }

                    if (data.WasRemoved)
                    {
                        RemoveData(accessor);
                    }
                }
            }
        }
Пример #2
0
        public void Initialize(ContentEntitySerializationFormat format, IEventDispatcher eventDispatcher) {
            _eventDispatcher = eventDispatcher;
            _uniqueId = format.UniqueId;
            PrettyName = format.PrettyName ?? "";

            foreach (ContentEntity.DataInstance data in format.Data) {
                DataAccessor accessor = new DataAccessor(data.CurrentData);

                if (data.WasAdded) {
                    _toAddStage1.Add(data.CurrentData);
                }

                else {
                    if (data.CurrentData is Data.NonVersioned) {
                        _data[accessor.Id] = new NonVersionedDataContainer(
                            (Data.NonVersioned)data.CurrentData);
                    }

                    else {
                        _data[accessor.Id] = new VersionedDataContainer(
                            (Data.IVersioned)data.PreviousData,
                            (Data.IVersioned)data.CurrentData,
                            (Data.IVersioned)data.CurrentData.Duplicate());
                    }

                    // There is going to be an ApplyModification call before systems actually view
                    // this Entity instance. With that in mind, we can treat our data initialization
                    // as if if were operating on the previous frame.

                    if (data.WasModified) {
                        // This is kind of an ugly hack, because to get the correct Previous/Current
                        // data we need to move Previous into Current so that Previous will reflect
                        // the true Previous value, not the Current one.

                        // Internal signal that a modification is going to take place
                        Modify(accessor);

                        if (data.CurrentData is Data.IVersioned) {
                            // Move Previous into Current, so that after the ApplyModification we
                            // have the correct data values
                            var container = (VersionedDataContainer)_data[accessor.Id];
                            container.Current.CopyFrom(container.Previous);
                        }
                    }

                    if (data.WasRemoved) {
                        RemoveData(accessor);
                    }
                }
            }
        }