Ejemplo n.º 1
0
        private void load()
        {
            var layoutLookups = source.GetConfig <KaraokeIndexLookup, IDictionary <int, string> >(KaraokeIndexLookup.Layout)?.Value;

            foreach (var layoutLookup in layoutLookups)
            {
                var lookup = new KaraokeSkinLookup(KaraokeSkinConfiguration.LyricLayout, layoutLookup.Key);
                var layout = source.GetConfig <KaraokeSkinLookup, LyricLayout>(lookup)?.Value;
                if (layout != null)
                {
                    Layouts.Add(layout);
                }
            }

            LoadedLayout.Value = Layouts.FirstOrDefault();
            EditLayout.Value   = Layouts.FirstOrDefault();

            var skinLookups = source.GetConfig <KaraokeIndexLookup, IDictionary <int, string> >(KaraokeIndexLookup.Style)?.Value;

            if (skinLookups == null)
            {
                return;
            }

            foreach (var(key, value) in skinLookups)
            {
                PreviewFontSelections.Add(key, value);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Posts a command locally. Commands like /help will result in a help message written in the current channel.
        /// </summary>
        /// <param name="text">the text containing the command identifier and command parameters.</param>
        /// <param name="target">An optional target channel. If null, <see cref="CurrentChannel"/> will be used.</param>
        public void PostCommand(string text, Channel target = null)
        {
            if (target == null)
            {
                target = CurrentChannel.Value;
            }

            if (target == null)
            {
                return;
            }

            var    parameters = text.Split(new[] { ' ' }, 2);
            string command    = parameters[0];
            string content    = parameters.Length == 2 ? parameters[1] : string.Empty;

            switch (command)
            {
            case "np":
                AddInternal(new NowPlayingCommand());
                break;

            case "me":
                if (string.IsNullOrWhiteSpace(content))
                {
                    target.AddNewMessages(new ErrorMessage("Usage: /me [action]"));
                    break;
                }

                PostMessage(content, true);
                break;

            case "join":
                if (string.IsNullOrWhiteSpace(content))
                {
                    target.AddNewMessages(new ErrorMessage("Usage: /join [channel]"));
                    break;
                }

                var channel = availableChannels.FirstOrDefault(c => c.Name == content || c.Name == $"#{content}");

                if (channel == null)
                {
                    target.AddNewMessages(new ErrorMessage($"Channel '{content}' not found."));
                    break;
                }

                JoinChannel(channel);
                CurrentChannel.Value = channel;
                break;

            case "help":
                target.AddNewMessages(new InfoMessage("Supported commands: /help, /me [action], /join [channel], /np"));
                break;

            default:
                target.AddNewMessages(new ErrorMessage($@"""/{command}"" is not supported! For a list of supported commands see /help"));
                break;
            }
        }
Ejemplo n.º 3
0
        public void AddOrUpdateRoom(Room room)
        {
            Debug.Assert(ThreadSafety.IsUpdateThread);
            Debug.Assert(room.RoomID.Value != null);

            if (ignoredRooms.Contains(room.RoomID.Value.Value))
            {
                return;
            }

            try
            {
                var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value);
                if (existing == null)
                {
                    rooms.Add(room);
                }
                else
                {
                    existing.CopyFrom(room);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"Failed to update room: {room.Name.Value}.");

                ignoredRooms.Add(room.RoomID.Value.Value);
                rooms.Remove(room);
            }

            notifyRoomsUpdated();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a <see cref="Room"/> to the list of available rooms.
        /// </summary>
        /// <param name="room">The <see cref="Room"/> to add.<</param>
        private void addRoom(Room room)
        {
            var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value);

            if (existing == null)
            {
                rooms.Add(room);
            }
            else
            {
                existing.CopyFrom(room);
            }
        }
Ejemplo n.º 5
0
        public void Add(ControlPoint point)
        {
            var existing = controlPoints.FirstOrDefault(p => p.GetType() == point.GetType());

            if (existing != null)
            {
                Remove(existing);
            }

            point.AttachGroup(this);

            controlPoints.Add(point);
            ItemAdded?.Invoke(point);
        }
Ejemplo n.º 6
0
        public void TestRemoveRangeNotifiesSubscribers()
        {
            bindableStringList.Add("0");
            bindableStringList.Add("1");

            List <string> itemsRemoved = null;

            bindableStringList.ItemsRemoved += i => itemsRemoved = i.ToList();
            bindableStringList.RemoveRange(1, 1);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, bindableStringList.Count);
                Assert.AreEqual("0", bindableStringList.FirstOrDefault());
                Assert.AreEqual(1, itemsRemoved.Count);
                Assert.AreEqual("1", itemsRemoved.FirstOrDefault());
            });
        }
Ejemplo n.º 7
0
        private bool postParse()
        {
            foreach (var element in projectElements)
            {
                if (!(element is IHasElements elementedElement))
                {
                    continue;
                }
                var elementQueue = elementedElement.PendingElements;

                while (elementQueue.Count > 0)
                {
                    int            nextElement    = elementQueue.Peek();
                    ProjectElement createdElement = projectElements.FirstOrDefault(e => e.ID == nextElement);

                    if (createdElement == null || createdElement.Type != elementedElement.NestedElementType)
                    {
                        return(false);
                    }

                    createdElement = elementedElement.NestedElementType switch
                    {
                        ElementType.Token => (Token)createdElement,
                        ElementType.Card => (Card)createdElement,
                        ElementType.Tile => (Tile)createdElement,
                        ElementType.Board => (Board)createdElement,
                        _ => null,
                    };

                    if (createdElement == null || createdElement.Parent != null)
                    {
                        return(false);
                    }

                    createdElement.Parent = element;

                    elementedElement.Elements.Add(createdElement);
                    elementQueue.Dequeue();
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        private void importCollections(List <BeatmapCollection> newCollections)
        {
            foreach (var newCol in newCollections)
            {
                var existing = Collections.FirstOrDefault(c => c.Name == newCol.Name);
                if (existing == null)
                {
                    Collections.Add(existing = new BeatmapCollection {
                        Name = { Value = newCol.Name.Value }
                    });
                }

                foreach (var newBeatmap in newCol.Beatmaps)
                {
                    if (!existing.Beatmaps.Contains(newBeatmap))
                    {
                        existing.Beatmaps.Add(newBeatmap);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Opens the most recently closed channel that has not already been reopened,
        /// Works similarly to reopening the last closed tab on a web browser.
        /// </summary>
        public void JoinLastClosedChannel()
        {
            // This loop could be eliminated if the join channel operation ensured that every channel joined
            // is removed from the closedChannels list, but it'd require a linear scan of closed channels on every join.
            // To keep the overhead of joining channels low, just lazily scan the list of closed channels locally.
            while (closedChannels.Count > 0)
            {
                ClosedChannel lastClosedChannel = closedChannels.Last();
                closedChannels.RemoveAt(closedChannels.Count - 1);

                // If the user has already joined the channel, try the next one
                if (joinedChannels.FirstOrDefault(lastClosedChannel.Matches) != null)
                {
                    continue;
                }

                Channel lastChannel = AvailableChannels.FirstOrDefault(lastClosedChannel.Matches);

                if (lastChannel != null)
                {
                    // Channel exists as an available channel, directly join it
                    CurrentChannel.Value = JoinChannel(lastChannel);
                }
                else if (lastClosedChannel.Type == ChannelType.PM)
                {
                    // Try to get user in order to open PM chat
                    users.GetUserAsync((int)lastClosedChannel.Id).ContinueWith(u =>
                    {
                        if (u.Result == null)
                        {
                            return;
                        }

                        Schedule(() => CurrentChannel.Value = JoinChannel(new Channel(u.Result)));
                    });
                }

                return;
            }
        }
Ejemplo n.º 10
0
        public ThemeManager(Scheduler scheduler, UserResources resources, VignetteConfigManager config)
        {
            this.scheduler = scheduler;

            UseableThemes.Add(Theme.Light);
            UseableThemes.Add(Theme.Dark);

            store              = resources.Themes;
            store.FileCreated += onFileCreated;
            store.FileDeleted += onFileDeleted;
            store.FileUpdated += onFileUpdated;
            store.FileRenamed += onFileRenamed;

            loadExistingThemes();

            themeConfig = config.GetBindable <string>(VignetteSetting.Theme);
            themeConfig.BindValueChanged(e =>
            {
                if (e.NewValue == Current.Value.Name)
                {
                    return;
                }

                Current.Value = UseableThemes.FirstOrDefault(t => t.Name == e.NewValue) ?? Theme.Light;

                SourceChanged?.Invoke();
            }, true);

            Current.BindValueChanged(e =>
            {
                if (themeConfig.Value == e.NewValue.Name)
                {
                    return;
                }

                themeConfig.Value = e.NewValue.Name;
                SourceChanged?.Invoke();
            }, true);
        }
Ejemplo n.º 11
0
        private Task importCollections(List <BeatmapCollection> newCollections)
        {
            var tcs = new TaskCompletionSource <bool>();

            Schedule(() =>
            {
                try
                {
                    foreach (var newCol in newCollections)
                    {
                        var existing = Collections.FirstOrDefault(c => c.Name.Value == newCol.Name.Value);
                        if (existing == null)
                        {
                            Collections.Add(existing = new BeatmapCollection {
                                Name = { Value = newCol.Name.Value }
                            });
                        }

                        foreach (string newBeatmap in newCol.BeatmapHashes)
                        {
                            if (!existing.BeatmapHashes.Contains(newBeatmap))
                            {
                                existing.BeatmapHashes.Add(newBeatmap);
                            }
                        }
                    }

                    tcs.SetResult(true);
                }
                catch (Exception e)
                {
                    Logger.Error(e, "Failed to import collection.");
                    tcs.SetException(e);
                }
            });

            return(tcs.Task);
        }
Ejemplo n.º 12
0
        public void AddOrUpdateRoom(Room room)
        {
            Debug.Assert(room.RoomID.Value != null);

            if (ignoredRooms.Contains(room.RoomID.Value.Value))
            {
                return;
            }

            room.Position.Value = -room.RoomID.Value.Value;

            try
            {
                foreach (var pi in room.Playlist)
                {
                    pi.MapObjects(beatmaps, rulesets);
                }

                var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value);
                if (existing == null)
                {
                    rooms.Add(room);
                }
                else
                {
                    existing.CopyFrom(room);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"Failed to update room: {room.Name.Value}.");

                ignoredRooms.Add(room.RoomID.Value.Value);
                rooms.Remove(room);
            }

            notifyRoomsUpdated();
        }
Ejemplo n.º 13
0
        private void AddMapping()
        {
            NewSegmentMappingViewModel vm = _newMappingFactory();

            vm.Segment1        = _segment1;
            vm.Segment2        = _segment2;
            vm.SegmentsEnabled = _segment1 == null && _segment2 == null;
            if (_dialogService.ShowModalDialog(this, vm) == true)
            {
                SegmentMappingViewModel mapping = _mappingFactory(vm.LeftEnvironment1 + vm.Segment1 + vm.RightEnvironment1,
                                                                  vm.LeftEnvironment2 + vm.Segment2 + vm.RightEnvironment2);
                SegmentMappingViewModel existingMapping = _mappings.FirstOrDefault(m => (m.Segment1 == mapping.Segment1 && m.Segment2 == mapping.Segment2) ||
                                                                                   (m.Segment1 == mapping.Segment2 && m.Segment2 == mapping.Segment1));
                if (existingMapping == null)
                {
                    _mappings.Add(mapping);
                }
                else
                {
                    mapping = existingMapping;
                }
                SelectedMapping = mapping;
            }
        }
Ejemplo n.º 14
0
 public MonitoredFile <T> GetReference(string name) => loaded.FirstOrDefault(f => f.Name == name);
Ejemplo n.º 15
0
        public void PostCommand(string text, Channel target = null)
        {
            target ??= CurrentChannel.Value;

            if (target == null)
            {
                return;
            }

            string[] parameters = text.Split(' ', 2);
            string   command    = parameters[0];
            string   content    = parameters.Length == 2 ? parameters[1] : string.Empty;

            switch (command)
            {
            case "np":
                AddInternal(new NowPlayingCommand(target));
                break;

            case "me":
                if (string.IsNullOrWhiteSpace(content))
                {
                    target.AddNewMessages(new ErrorMessage("Usage: /me [action]"));
                    break;
                }

                PostMessage(content, true, target);
                break;

            case "join":
                if (string.IsNullOrWhiteSpace(content))
                {
                    target.AddNewMessages(new ErrorMessage("Usage: /join [channel]"));
                    break;
                }

                var channel = availableChannels.FirstOrDefault(c => c.Name == content || c.Name == $"#{content}");

                if (channel == null)
                {
                    target.AddNewMessages(new ErrorMessage($"Channel '{content}' not found."));
                    break;
                }

                JoinChannel(channel);
                break;

            case "chat":
            case "msg":
            case "query":
                if (string.IsNullOrWhiteSpace(content))
                {
                    target.AddNewMessages(new ErrorMessage($"Usage: /{command} [user]"));
                    break;
                }

                // Check if the user has joined the requested channel already.
                // This uses the channel name for comparison as the PM user's username is unavailable after a restart.
                var privateChannel = JoinedChannels.FirstOrDefault(
                    c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Name.Equals(content, StringComparison.OrdinalIgnoreCase));

                if (privateChannel != null)
                {
                    CurrentChannel.Value = privateChannel;
                    break;
                }

                var request = new GetUserRequest(content);
                request.Success += OpenPrivateChannel;
                request.Failure += e => target.AddNewMessages(
                    new ErrorMessage(e.InnerException?.Message == @"NotFound" ? $"User '{content}' was not found." : $"Could not fetch user '{content}'."));

                api.Queue(request);
                break;

            case "help":
                target.AddNewMessages(new InfoMessage("Supported commands: /help, /me [action], /join [channel], /chat [user], /np"));
                break;

            default:
                target.AddNewMessages(new ErrorMessage($@"""/{command}"" is not supported! For a list of supported commands see /help"));
                break;
            }
        }
Ejemplo n.º 16
0
 public LoungeBackgroundScreen()
 {
     SelectedRoom.BindValueChanged(onSelectedRoomChanged);
     playlist.BindCollectionChanged((_, __) => PlaylistItem = playlist.FirstOrDefault());
 }