示例#1
0
        public PasteSpecial(IEnumerable <MapObject> objectsToPaste, int numCopies,
                            PasteSpecialStartPoint startPoint, PasteSpecialGrouping grouping,
                            Coordinate offset, Coordinate rotation, bool makeEntitesUnique,
                            bool prefixEntityNames, string entityNamePrefix)
        {
            _objectsToPaste    = objectsToPaste;
            _numCopies         = numCopies;
            _startPoint        = startPoint;
            _grouping          = grouping;
            _offset            = offset;
            _rotation          = rotation;
            _makeEntitesUnique = makeEntitesUnique;
            _prefixEntityNames = prefixEntityNames;
            _entityNamePrefix  = entityNamePrefix;
            _firstRun          = true;

            if (_numCopies == 1 && grouping == PasteSpecialGrouping.All)
            {
                // Only one copy - individual will give the same result (this makes the below comparison easier)
                _grouping = PasteSpecialGrouping.Individual;
            }
            if (_objectsToPaste.Count() == 1 && _grouping == PasteSpecialGrouping.Individual)
            {
                // Only one object - no need to group.
                _grouping = PasteSpecialGrouping.None;
            }
        }
示例#2
0
        public PasteSpecial(IEnumerable<MapObject> objectsToPaste, int numCopies,
            PasteSpecialStartPoint startPoint, PasteSpecialGrouping grouping,
            Coordinate offset, Coordinate rotation, bool makeEntitesUnique,
            bool prefixEntityNames, string entityNamePrefix)
        {
            _objectsToPaste = objectsToPaste;
            _numCopies = numCopies;
            _startPoint = startPoint;
            _grouping = grouping;
            _offset = offset;
            _rotation = rotation;
            _makeEntitesUnique = makeEntitesUnique;
            _prefixEntityNames = prefixEntityNames;
            _entityNamePrefix = entityNamePrefix;
            _firstRun = true;

            if (_numCopies == 1 && grouping == PasteSpecialGrouping.All)
            {
                // Only one copy - individual will give the same result (this makes the below comparison easier)
                _grouping = PasteSpecialGrouping.Individual;
            }
            if (_objectsToPaste.Count() == 1 && _grouping == PasteSpecialGrouping.Individual)
            {
                // Only one object - no need to group.
                _grouping = PasteSpecialGrouping.None;
            }
        }
示例#3
0
        public override void Perform(Documents.Document document)
        {
            if (_firstRun)
            {
                var origin  = GetPasteOrigin(document);
                var objects = new List <MapObject>();

                if (_objectsToPaste.Count() == 1)
                {
                    // Only one object - no need to group.
                    _grouping = PasteSpecialGrouping.None;
                }

                Group allGroup = null;
                if (_grouping == PasteSpecialGrouping.All)
                {
                    // Use one group for all copies
                    allGroup = new Group(document.Map.IDGenerator.GetNextObjectID());
                    // Add the group to the tree
                    objects.Add(allGroup);
                }

                // Get a list of all entity names if needed
                var names = new List <string>();
                if (_makeEntitesUnique)
                {
                    names = document.Map.WorldSpawn.Find(x => x is Entity)
                            .Select(x => x.GetEntityData())
                            .Where(x => x != null)
                            .Select(x => x.Properties.FirstOrDefault(y => y.Key == "targetname"))
                            .Where(x => x != null)
                            .Select(x => x.Value)
                            .ToList();
                }

                // Start at i = 1 so the original isn't duped with no offets
                for (var i = 1; i <= _numCopies; i++)
                {
                    var copyOrigin   = origin + (_offset * i);
                    var copyRotation = _rotation * i;
                    var copy         = CreateCopy(document.Map.IDGenerator, copyOrigin, copyRotation, names, document.Map.GetTransformFlags()).ToList();
                    var grouped      = GroupCopy(document.Map.IDGenerator, allGroup, copy);
                    objects.AddRange(grouped);
                }

                // Mark the objects to be created
                Create(document.Map.WorldSpawn.ID, objects);

                // We don't need to calculate this again.
                _firstRun       = false;
                _objectsToPaste = null;
            }
            base.Perform(document);
        }
示例#4
0
        public override void Perform(Documents.Document document)
        {
            if (_firstRun)
            {
                var origin = GetPasteOrigin(document);
                var objects = new List<MapObject>();

                if (_objectsToPaste.Count() == 1)
                {
                    // Only one object - no need to group.
                    _grouping = PasteSpecialGrouping.None;
                }

                Group allGroup = null;
                if (_grouping == PasteSpecialGrouping.All)
                {
                    // Use one group for all copies
                    allGroup = new Group(document.Map.IDGenerator.GetNextObjectID());
                    // Add the group to the tree
                    objects.Add(allGroup);
                }

                // Get a list of all entity names if needed
                var names = new List<string>();
                if (_makeEntitesUnique)
                {
                    names = document.Map.WorldSpawn.Find(x => x is Entity)
                        .Select(x => x.GetEntityData())
                        .Where(x => x != null)
                        .Select(x => x.Properties.FirstOrDefault(y => y.Key == "targetname"))
                        .Where(x => x != null)
                        .Select(x => x.Value)
                        .ToList();
                }

                // Start at i = 1 so the original isn't duped with no offets
                for (var i = 1; i <= _numCopies; i++)
                {
                    var copyOrigin = origin + (_offset * i);
                    var copyRotation = _rotation * i;
                    var copy = CreateCopy(document.Map.IDGenerator, copyOrigin, copyRotation, names, document.Map.GetTransformFlags()).ToList();
                    var grouped = GroupCopy(document.Map.IDGenerator, allGroup, copy);
                    objects.AddRange(grouped);
                }

                // Mark the objects to be created
                Create(objects);

                // We don't need to calculate this again.
                _firstRun = false;
                _objectsToPaste = null;
            }
            base.Perform(document);
        }