Пример #1
0
        public override void Reset()
        {
            base.Reset();

            //ensure we are at offset 0
            Clock = new FramedClock();

            List<HitObject> objects = new List<HitObject>();

            int time = 500;
            for (int i = 0; i < 100; i++)
            {
                objects.Add(new HitCircle()
                {
                    StartTime = time,
                    Position = new Vector2(RNG.Next(0, 512), RNG.Next(0, 384)),
                    Scale = RNG.NextSingle(0.5f, 1.0f),
                });

                time += RNG.Next(50, 500);
            }

            Beatmap beatmap = new Beatmap
            {
                HitObjects = objects
            };

            Add(new Drawable[]
            {
                new OsuHitRenderer
                {
                    Objects = beatmap.HitObjects,
                    Scale = new Vector2(0.5f),
                    Anchor = Anchor.TopLeft,
                    Origin = Anchor.TopLeft
                },
                new TaikoHitRenderer
                {
                    Objects = beatmap.HitObjects,
                    Scale = new Vector2(0.5f),
                    Anchor = Anchor.TopRight,
                    Origin = Anchor.TopRight
                },
                new CatchHitRenderer
                {
                    Objects = beatmap.HitObjects,
                    Scale = new Vector2(0.5f),
                    Anchor = Anchor.BottomLeft,
                    Origin = Anchor.BottomLeft
                },
                new ManiaHitRenderer
                {
                    Objects = beatmap.HitObjects,
                    Scale = new Vector2(0.5f),
                    Anchor = Anchor.BottomRight,
                    Origin = Anchor.BottomRight
                }
            });
        }
Пример #2
0
        private ProcessorWorkingBeatmap(osu.Game.Beatmaps.Beatmap beatmap, int?beatmapId = null) : base(beatmap.BeatmapInfo, null)
        {
            this.beatmap = beatmap;

            if (beatmapId.HasValue)
            {
                beatmap.BeatmapInfo.OnlineBeatmapID = beatmapId;
            }
        }
Пример #3
0
 public LegacyFilesystemReader(string path)
 {
     basePath = path;
     beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
     if (beatmaps.Length == 0)
         throw new FileNotFoundException(@"This directory contains no beatmaps");
     using (var stream = new StreamReader(GetStream(beatmaps[0])))
     {
         var decoder = BeatmapDecoder.GetDecoder(stream);
         firstMap = decoder.Decode(stream);
     }
 }
Пример #4
0
        public override void Reset()
        {
            base.Reset();

            //ensure we are at offset 0
            Clock = new FramedClock();

            if (beatmap == null)
            {

                var objects = new List<HitObject>();

                int time = 1500;
                for (int i = 0; i < 50; i++)
                {
                    objects.Add(new HitCircle()
                    {
                        StartTime = time,
                        Position = new Vector2(i % 4 == 0 || i % 4 == 2 ? 0 : 512,
                        i % 4 < 2 ? 0 : 384),
                        NewCombo = i % 4 == 0
                    });

                    time += 500;
                }

                var decoder = new ConstructableBeatmapDecoder();

                Beatmap b = new Beatmap
                {
                    HitObjects = objects
                };

                decoder.Process(b);

                beatmap = new WorkingBeatmap(b);
            }

            Add(new Box
            {
                RelativeSizeAxes = Framework.Graphics.Axes.Both,
                Colour = Color4.Gray,
            });

            Add(new Player
            {
                PreferredPlayMode = PlayMode.Osu,
                Beatmap = beatmap
            });
        }
Пример #5
0
 public WorkingBeatmap(Beatmap beatmap)
 {
     this.beatmap = beatmap;
 }
Пример #6
0
        public override void SetDefaultsFromBeatmap(Beatmap beatmap)
        {
            base.SetDefaultsFromBeatmap(beatmap);

            Velocity = 100 / beatmap.BeatLengthAt(StartTime, true) * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier;
        }
Пример #7
0
 public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => null;
Пример #8
0
        /// <summary>
        /// Import a beamap into our local <see cref="FileStore"/> storage.
        /// If the beatmap is already imported, the existing instance will be returned.
        /// </summary>
        /// <param name="files">The store to import beatmap files to.</param>
        /// <param name="beatmaps">The store to import beatmaps to.</param>
        /// <param name="reader">The beatmap archive to be read.</param>
        /// <returns>The imported beatmap, or an existing instance if it is already present.</returns>
        private BeatmapSetInfo importToStorage(FileStore files, BeatmapStore beatmaps, ArchiveReader reader)
        {
            // let's make sure there are actually .osu files to import.
            string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu"));

            if (string.IsNullOrEmpty(mapName))
            {
                throw new InvalidOperationException("No beatmap files found in the map folder.");
            }

            // for now, concatenate all .osu files in the set to create a unique hash.
            MemoryStream hashable = new MemoryStream();

            foreach (string file in reader.Filenames.Where(f => f.EndsWith(".osu")))
            {
                using (Stream s = reader.GetStream(file))
                    s.CopyTo(hashable);
            }

            var hash = hashable.ComputeSHA2Hash();

            // check if this beatmap has already been imported and exit early if so.
            var beatmapSet = beatmaps.BeatmapSets.FirstOrDefault(b => b.Hash == hash);

            if (beatmapSet != null)
            {
                undelete(beatmaps, files, beatmapSet);

                // ensure all files are present and accessible
                foreach (var f in beatmapSet.Files)
                {
                    if (!storage.Exists(f.FileInfo.StoragePath))
                    {
                        using (Stream s = reader.GetStream(f.Filename))
                            files.Add(s, false);
                    }
                }

                // todo: delete any files which shouldn't exist any more.

                return(beatmapSet);
            }

            List <BeatmapSetFileInfo> fileInfos = new List <BeatmapSetFileInfo>();

            // import files to manager
            foreach (string file in reader.Filenames)
            {
                using (Stream s = reader.GetStream(file))
                    fileInfos.Add(new BeatmapSetFileInfo
                    {
                        Filename = file,
                        FileInfo = files.Add(s)
                    });
            }

            BeatmapMetadata metadata;

            using (var stream = new StreamReader(reader.GetStream(mapName)))
                metadata = Decoder.GetDecoder(stream).DecodeBeatmap(stream).Metadata;


            // check if a set already exists with the same online id.
            if (metadata.OnlineBeatmapSetID != null)
            {
                beatmapSet = beatmaps.BeatmapSets.FirstOrDefault(b => b.OnlineBeatmapSetID == metadata.OnlineBeatmapSetID);
            }

            if (beatmapSet == null)
            {
                beatmapSet = new BeatmapSetInfo
                {
                    OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
                    Beatmaps           = new List <BeatmapInfo>(),
                    Hash     = hash,
                    Files    = fileInfos,
                    Metadata = metadata
                }
            }
            ;


            var mapNames = reader.Filenames.Where(f => f.EndsWith(".osu"));

            foreach (var name in mapNames)
            {
                using (var raw = reader.GetStream(name))
                    using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit
                        using (var sr = new StreamReader(ms))
                        {
                            raw.CopyTo(ms);
                            ms.Position = 0;

                            var     decoder = Decoder.GetDecoder(sr);
                            Beatmap beatmap = decoder.DecodeBeatmap(sr);

                            beatmap.BeatmapInfo.Path    = name;
                            beatmap.BeatmapInfo.Hash    = ms.ComputeSHA2Hash();
                            beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();

                            var existing = beatmaps.Beatmaps.FirstOrDefault(b => b.Hash == beatmap.BeatmapInfo.Hash || beatmap.BeatmapInfo.OnlineBeatmapID != null && b.OnlineBeatmapID == beatmap.BeatmapInfo.OnlineBeatmapID);

                            if (existing == null)
                            {
                                // Exclude beatmap-metadata if it's equal to beatmapset-metadata
                                if (metadata.Equals(beatmap.Metadata))
                                {
                                    beatmap.BeatmapInfo.Metadata = null;
                                }

                                RulesetInfo ruleset = rulesets.GetRuleset(beatmap.BeatmapInfo.RulesetID);

                                // TODO: this should be done in a better place once we actually need to dynamically update it.
                                beatmap.BeatmapInfo.Ruleset        = ruleset;
                                beatmap.BeatmapInfo.StarDifficulty = ruleset?.CreateInstance()?.CreateDifficultyCalculator(beatmap).Calculate() ?? 0;

                                beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
                            }
                        }
            }

            return(beatmapSet);
        }
Пример #9
0
 public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => null;
Пример #10
0
 /// <summary>
 /// Converts a Beatmap using this Beatmap Converter.
 /// </summary>
 /// <param name="original">The un-converted Beatmap.</param>
 /// <returns>The converted Beatmap.</returns>
 public Beatmap <T> Convert(Beatmap original)
 {
     // We always operate on a clone of the original beatmap, to not modify it game-wide
     return(ConvertBeatmap(new Beatmap(original)));
 }
Пример #11
0
 /// <summary>
 /// Constructs a new beatmap.
 /// </summary>
 /// <param name="original">The original beatmap to use the parameters of.</param>
 public Beatmap(Beatmap original = null)
 {
     BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo;
     TimingInfo  = original?.TimingInfo ?? TimingInfo;
     ComboColors = original?.ComboColors ?? ComboColors;
 }
Пример #12
0
 /// <summary>
 /// Post-processes a Beatmap to add mode-specific components that aren't added during conversion.
 /// <para>
 /// An example of such a usage is for combo colours.
 /// </para>
 /// </summary>
 /// <param name="beatmap">The Beatmap to process.</param>
 public virtual void PostProcess(Beatmap <TObject> beatmap)
 {
 }
Пример #13
0
 public WorkingBeatmap(Beatmap beatmap)
 {
     this.beatmap   = beatmap;
     BeatmapInfo    = beatmap.BeatmapInfo;
     BeatmapSetInfo = beatmap.BeatmapInfo.BeatmapSet;
 }
Пример #14
0
 /// <summary>
 /// Performs the conversion of a hit object.
 /// This method is generally executed sequentially for all objects in a beatmap.
 /// </summary>
 /// <param name="original">The hit object to convert.</param>
 /// <param name="beatmap">The un-converted Beatmap.</param>
 /// <returns>The converted hit object.</returns>
 protected abstract IEnumerable <T> ConvertHitObject(HitObject original, Beatmap beatmap);
Пример #15
0
        /// <summary>
        /// Import a beamap into our local <see cref="FileStore"/> storage.
        /// If the beatmap is already imported, the existing instance will be returned.
        /// </summary>
        /// <param name="reader">The beatmap archive to be read.</param>
        /// <returns>The imported beatmap, or an existing instance if it is already present.</returns>
        private BeatmapSetInfo importToStorage(ArchiveReader reader)
        {
            // let's make sure there are actually .osu files to import.
            string mapName = reader.Filenames.FirstOrDefault(f => f.EndsWith(".osu"));

            if (string.IsNullOrEmpty(mapName))
            {
                throw new InvalidOperationException("No beatmap files found in the map folder.");
            }

            // for now, concatenate all .osu files in the set to create a unique hash.
            MemoryStream hashable = new MemoryStream();

            foreach (string file in reader.Filenames.Where(f => f.EndsWith(".osu")))
            {
                using (Stream s = reader.GetStream(file))
                    s.CopyTo(hashable);
            }

            var hash = hashable.ComputeSHA2Hash();

            // check if this beatmap has already been imported and exit early if so.
            BeatmapSetInfo beatmapSet;

            lock (beatmaps)
                beatmapSet = beatmaps.QueryAndPopulate <BeatmapSetInfo>(b => b.Hash == hash).FirstOrDefault();

            if (beatmapSet != null)
            {
                Undelete(beatmapSet);

                // ensure all files are present and accessible
                foreach (var f in beatmapSet.Files)
                {
                    if (!storage.Exists(f.FileInfo.StoragePath))
                    {
                        using (Stream s = reader.GetStream(f.Filename))
                            files.Add(s, false);
                    }
                }

                return(beatmapSet);
            }

            List <BeatmapSetFileInfo> fileInfos = new List <BeatmapSetFileInfo>();

            // import files to manager
            foreach (string file in reader.Filenames)
            {
                using (Stream s = reader.GetStream(file))
                    fileInfos.Add(new BeatmapSetFileInfo
                    {
                        Filename = file,
                        FileInfo = files.Add(s)
                    });
            }

            BeatmapMetadata metadata;

            using (var stream = new StreamReader(reader.GetStream(mapName)))
                metadata = BeatmapDecoder.GetDecoder(stream).Decode(stream).Metadata;

            beatmapSet = new BeatmapSetInfo
            {
                OnlineBeatmapSetID = metadata.OnlineBeatmapSetID,
                Beatmaps           = new List <BeatmapInfo>(),
                Hash     = hash,
                Files    = fileInfos,
                Metadata = metadata
            };

            var mapNames = reader.Filenames.Where(f => f.EndsWith(".osu"));

            foreach (var name in mapNames)
            {
                using (var raw = reader.GetStream(name))
                    using (var ms = new MemoryStream()) //we need a memory stream so we can seek and shit
                        using (var sr = new StreamReader(ms))
                        {
                            raw.CopyTo(ms);
                            ms.Position = 0;

                            var     decoder = BeatmapDecoder.GetDecoder(sr);
                            Beatmap beatmap = decoder.Decode(sr);

                            beatmap.BeatmapInfo.Path    = name;
                            beatmap.BeatmapInfo.Hash    = ms.ComputeSHA2Hash();
                            beatmap.BeatmapInfo.MD5Hash = ms.ComputeMD5Hash();

                            // TODO: Diff beatmap metadata with set metadata and leave it here if necessary
                            beatmap.BeatmapInfo.Metadata = null;

                            // TODO: this should be done in a better place once we actually need to dynamically update it.
                            beatmap.BeatmapInfo.Ruleset        = rulesets.Query <RulesetInfo>().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID);
                            beatmap.BeatmapInfo.StarDifficulty = rulesets.Query <RulesetInfo>().FirstOrDefault(r => r.ID == beatmap.BeatmapInfo.RulesetID)?.CreateInstance()?.CreateDifficultyCalculator(beatmap)
                                                                 .Calculate() ?? 0;

                            beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo);
                        }
            }

            return(beatmapSet);
        }
Пример #16
0
 public virtual void SetDefaultsFromBeatmap(Beatmap beatmap)
 {
 }
Пример #17
0
 /// <summary>
 /// Checks if a Beatmap can be converted using this Beatmap Converter.
 /// </summary>
 /// <param name="beatmap">The Beatmap to check.</param>
 /// <returns>Whether the Beatmap can be converted using this Beatmap Converter.</returns>
 public bool CanConvert(Beatmap beatmap) => ValidConversionTypes.All(t => beatmap.HitObjects.Any(t.IsInstanceOfType));