示例#1
0
        public void AddPlaceObject(int depth, int?character)
        {
            if (_placeObjects.ContainsKey(depth))
            {
                throw new AptEditorException(ErrorType.PlaceObjectDepthAlreadyTaken);
            }
            var                currentIndex = CurrentItems.Count;
            FrameItem?         created;
            LogicalPlaceObject?logicalPO;

            if (character is int index)
            {
                var po = PlaceObject.Create(depth, index);
                created   = po;
                logicalPO = new LogicalPlaceObject(EditAndUpdate, po);
            }
            else
            {
                created   = RemoveObject.Create(depth);
                logicalPO = null;
            }

            void Add()
            {
                CurrentItems.Add(created);
                _placeObjects.Add(depth, logicalPO);
            }

            void Remove()
            {
                CurrentItems.RemoveAt(currentIndex);
                _placeObjects.Remove(depth);
            }

            EditAndUpdate(new EditAction(Add, Remove, "Add PlaceObject"));
        }