Ejemplo n.º 1
0
 public void EditCollection(CollectionEditArgs args)
 {
     EditCollection(args, false);
 }
Ejemplo n.º 2
0
        /*
         * add collection
         * remove collection
         * edit collection name
         * merge x collections
         * clear collections
         * add beatmaps to collection
         * remove beatmaps from collection
         */

        private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false)
        {
            var action = args.Action;

            if (action == CollectionEdit.Add)
            {
                foreach (var collection in args.Collections)
                {
                    collection.Name = GetValidCollectionName(collection.Name);
                }
                LoadedCollections.AddRange(args.Collections);
            }
            else if (action == CollectionEdit.AddOrMergeIfExists)
            {
                foreach (var collection in args.Collections)
                {
                    if (CollectionNameExists(collection.Name))
                    {
                        EditCollection(CollectionEditArgs.MergeCollections(
                                           new Collections()
                        {
                            GetCollectionByName(collection.Name), collection
                        }, collection.Name), true);
                    }
                    else
                    {
                        EditCollection(CollectionEditArgs.AddCollections(new Collections()
                        {
                            collection
                        }), true);
                    }
                }
            }
            else if (action == CollectionEdit.Remove)
            {
                foreach (var collectionName in args.CollectionNames)
                {
                    var collection = GetCollectionByName(collectionName);
                    if (collection != null)
                    {
                        LoadedCollections.SilentRemove(collection);
                    }
                }
            }
            else if (action == CollectionEdit.Merge)
            {
                var collections       = args.Collections;
                var newCollectionName = args.NewName;
                if (collections.Count > 0)
                {
                    var masterCollection = collections[0];
                    for (int i = 1; i < collections.Count; i++)
                    {
                        var collectionToMerge = collections[i];
                        foreach (var beatmap in collectionToMerge.AllBeatmaps())
                        {
                            masterCollection.AddBeatmap(beatmap);
                        }
                        LoadedCollections.SilentRemove(collectionToMerge);
                    }
                    LoadedCollections.SilentRemove(masterCollection);

                    masterCollection.Name = GetValidCollectionName(newCollectionName);
                    EditCollection(CollectionEditArgs.AddCollections(new Collections()
                    {
                        masterCollection
                    }), true);
                }
            }
            else if (action == CollectionEdit.Clear)
            {
                LoadedCollections.Clear();
            }
            else
            {
                var collection = GetCollectionByName(args.OrginalName);

                if (action == CollectionEdit.Rename)
                {
                    collection.Name = GetValidCollectionName(args.NewName);
                }
                else if (action == CollectionEdit.AddBeatmaps)
                {
                    if (collection != null)
                    {
                        foreach (var beatmap in args.Beatmaps)
                        {
                            collection.AddBeatmap(beatmap);
                        }
                    }
                }
                else if (action == CollectionEdit.RemoveBeatmaps)
                {
                    if (collection != null)
                    {
                        foreach (var beatmap in args.Beatmaps)
                        {
                            collection.RemoveBeatmap(beatmap.Md5);
                        }
                    }
                }
            }
            if (!suspendRefresh)
            {
                AfterCollectionsEdit();
            }
        }
        /*
         * add collection
         * remove collection
         * edit collection name
         * merge x collections
         * intersect x collections
         * clear collections
         * add beatmaps to collection
         * remove beatmaps from collection
         */

        private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false)
        {
            var action = args.Action;

            if (action == CollectionEdit.Add)
            {
                List <string> collectionNames = new List <string>();
                foreach (var collection in args.Collections)
                {
                    var name = GetValidCollectionName(collection.Name, collectionNames);

                    collection.Name = name;
                    collectionNames.Add(name);
                }
                LoadedCollections.AddRange(args.Collections);
            }
            else if (action == CollectionEdit.AddOrMergeIfExists)
            {
                foreach (var collection in args.Collections)
                {
                    if (CollectionNameExists(collection.Name))
                    {
                        EditCollection(CollectionEditArgs.MergeCollections(
                                           new Collections()
                        {
                            GetCollectionByName(collection.Name), collection
                        }, collection.Name), true);
                    }
                    else
                    {
                        EditCollection(CollectionEditArgs.AddCollections(new Collections()
                        {
                            collection
                        }), true);
                    }
                }
            }
            else if (action == CollectionEdit.Remove)
            {
                foreach (var collectionName in args.CollectionNames)
                {
                    var collection = GetCollectionByName(collectionName);
                    if (collection != null)
                    {
                        LoadedCollections.SilentRemove(collection);
                    }
                }
            }
            else if (action == CollectionEdit.Merge)
            {
                var collections       = args.Collections;
                var newCollectionName = args.NewName;
                if (collections.Count > 0)
                {
                    var masterCollection = collections[0];
                    for (int i = 1; i < collections.Count; i++)
                    {
                        var collectionToMerge = collections[i];
                        foreach (var beatmap in collectionToMerge.AllBeatmaps())
                        {
                            masterCollection.AddBeatmap(beatmap);
                        }
                        LoadedCollections.SilentRemove(collectionToMerge);
                    }
                    LoadedCollections.SilentRemove(masterCollection);

                    masterCollection.Name = GetValidCollectionName(newCollectionName);
                    EditCollection(CollectionEditArgs.AddCollections(new Collections()
                    {
                        masterCollection
                    }), true);
                }
            }
            else if (action == CollectionEdit.Intersect)
            {
                var targetCollection = args.Collections.Last();
                args.Collections.RemoveAt(args.Collections.Count - 1);
                var mainCollection = args.Collections[0];
                args.Collections.RemoveAt(0);
                var beatmaps = mainCollection.AllBeatmaps().ToList();
                foreach (var collection in args.Collections)
                {
                    beatmaps = beatmaps.Intersect(collection.AllBeatmaps(), new CollectionBeatmapComparer()).ToList();
                }

                foreach (var beatmap in beatmaps)
                {
                    targetCollection.AddBeatmap(beatmap);
                }

                EditCollection(CollectionEditArgs.AddCollections(new Collections()
                {
                    targetCollection
                }), true);
            }
            else if (action == CollectionEdit.Clear)
            {
                LoadedCollections.Clear();
            }
            else
            {
                var collection = GetCollectionByName(args.OrginalName);

                if (action == CollectionEdit.Rename)
                {
                    collection.Name = GetValidCollectionName(args.NewName);
                }
                else if (action == CollectionEdit.AddBeatmaps)
                {
                    if (collection != null)
                    {
                        foreach (var beatmap in args.Beatmaps)
                        {
                            collection.AddBeatmap(beatmap);
                        }
                    }
                }
                else if (action == CollectionEdit.RemoveBeatmaps)
                {
                    if (collection != null)
                    {
                        foreach (var beatmap in args.Beatmaps)
                        {
                            collection.RemoveBeatmap(beatmap.Md5);
                        }
                    }
                }
                else if (action == CollectionEdit.Duplicate)
                {
                    throw new NotImplementedException("Call AddCollections followed with AddBeatmaps instead");
                }
            }
            if (!suspendRefresh)
            {
                AfterCollectionsEdit();
            }
        }