Exemplo n.º 1
0
        /// <summary>
        ///     Queues a load of the background for a map
        /// </summary>
        public static void Load(Map map) => ThreadScheduler.Run(async() =>
        {
            Source.Cancel();
            Source.Dispose();
            Source = new CancellationTokenSource();

            Map       = map;
            var token = Source.Token;

            token.ThrowIfCancellationRequested();

            try
            {
                var oldRawTexture     = RawTexture;
                var oldBlurredTexture = BlurredTexture;

                var path = MapManager.GetBackgroundPath(map);

                var tex    = File.Exists(path) ? AssetLoader.LoadTexture2DFromFile(path) : UserInterface.MenuBackgroundRaw;
                RawTexture = tex;

                ThreadScheduler.RunAfter(() =>
                {
                    if (oldRawTexture != null && oldRawTexture != UserInterface.MenuBackgroundRaw)
                    {
                        oldRawTexture?.Dispose();
                        oldBlurredTexture?.Dispose();
                    }
                }, 500);

                token.ThrowIfCancellationRequested();

                await Task.Delay(100, token);
                ShouldBlur = true;
                Loaded?.Invoke(typeof(BackgroundHelper), new BackgroundLoadedEventArgs(map, tex));
            }
            catch (OperationCanceledException e)
            {
                // ignored
            }
            catch (Exception e)
            {
                Logger.Error(e, LogType.Runtime);
            }
        });
Exemplo n.º 2
0
        /// <summary>
        ///     Called when a new steam avatar is loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSteamAvatarLoaded(object sender, SteamAvatarLoadedEventArgs e)
        {
            // If it doesn't apply to this message.
            if (e.SteamId != (ulong)Message.Sender.OnlineUser.SteamId)
            {
                return;
            }

            try
            {
                Avatar.Animations.Clear();
                Avatar.Animations.Add(new Animation(AnimationProperty.Alpha, Easing.Linear, 0, 1, 300));
                Avatar.Image = e.Texture;
            }
            catch (Exception exception)
            {
                Logger.Error(exception, LogType.Runtime);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Exports the entire mapset to a zip (.qp) file.
        /// </summary>
        public void ExportToZip()
        {
            var exportsDir = $"{ConfigManager.DataDirectory}/Exports/";

            System.IO.Directory.CreateDirectory(exportsDir);

            var tempFolder = $"{ConfigManager.DataDirectory}/temp/{GameBase.Game.TimeRunning}/";

            System.IO.Directory.CreateDirectory(tempFolder);

            using (var archive = ZipArchive.Create())
            {
                foreach (var map in Maps)
                {
                    try
                    {
                        switch (map.Game)
                        {
                        case MapGame.Quaver:
                            var path = $"{ConfigManager.SongDirectory.Value}/{map.Directory}/{map.Path}";
                            File.Copy(path, $"{tempFolder}/{map.Path}");
                            break;

                        // Map is from osu!, so we need to convert it to .qua format
                        case MapGame.Osu:
                            var osuPath = $"{MapManager.OsuSongsFolder}{map.Directory}/{map.Path}";

                            var osu = new OsuBeatmap(osuPath);
                            map.BackgroundPath = osu.Background;

                            var name     = StringHelper.FileNameSafeString($"{map.Artist} - {map.Title} [{map.DifficultyName}].qua");
                            var savePath = $"{tempFolder}/{name}";

                            osu.ToQua().Save(savePath);

                            Logger.Debug($"Successfully converted osu beatmap: {osuPath}", LogType.Runtime);
                            break;
                        }

                        // Copy over audio file if necessary
                        if (File.Exists(MapManager.GetAudioPath(map)) && !File.Exists($"{tempFolder}/{map.AudioPath}"))
                        {
                            File.Copy(MapManager.GetAudioPath(map), $"{tempFolder}/{map.AudioPath}");
                        }

                        // Copy over background file if necessary
                        if (File.Exists(MapManager.GetBackgroundPath(map)) && !File.Exists($"{tempFolder}/{map.BackgroundPath}"))
                        {
                            File.Copy(MapManager.GetBackgroundPath(map), $"{tempFolder}/{map.BackgroundPath}");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error(e, LogType.Runtime);
                    }
                }

                archive.AddAllFromDirectory(tempFolder);

                var outputPath = exportsDir +
                                 $"{StringHelper.FileNameSafeString(Artist + " - " + Title + " - " + GameBase.Game.TimeRunning)}.qp";

                archive.SaveTo(outputPath, CompressionType.Deflate);

                Utils.NativeUtils.HighlightInFileManager(outputPath);
            }

            System.IO.Directory.Delete(tempFolder, true);
        }