Exemplo n.º 1
0
        /// <summary>
        /// Load beatmaps from the database, or by parsing the directory structure in fallback cases.
        /// </summary>
        private void InitializeBeatmaps()
        {
            string udid = GameBase.Instance.DeviceIdentifier; //cache the udid before possibly writing the database out.

            BeatmapDatabase.Initialize();

#if !DIST
            if (GameBase.Mapper)
            {
                //desktop/mapper builds.
                recursiveBeatmaps(BeatmapPath);
            }
            else
#endif
            if (BeatmapDatabase.BeatmapInfo.Count > 0 && !ForceBeatmapRefresh && BeatmapDatabase.Version == BeatmapDatabase.DATABASE_VERSION)
            {
                bool hasMissingMaps = false;
                foreach (BeatmapInfo bmi in BeatmapDatabase.BeatmapInfo)
                {
                    Beatmap b = bmi.GetBeatmap();
                    if (!File.Exists(b.ContainerFilename))
                    {
                        hasMissingMaps = true;
                        continue;
                    }

                    maps.AddInPlace(b);
                }
            }
            else
            {
#if !DIST
                Console.WriteLine("Regenerating database!");
#endif

                ForceBeatmapRefresh = false;

#if iOS
                //bundled maps
                foreach (string s in Directory.GetFiles("Beatmaps/"))
                {
                    Beatmap b = new Beatmap(s);

                    BeatmapDatabase.PopulateBeatmap(b);
                    maps.AddInPlace(b);
                }
#endif

                foreach (string s in Directory.GetFiles(BeatmapPath, "*.os*"))
                {
                    Beatmap b = new Beatmap(s);

                    if (b.Package == null)
                    {
                        continue;
                    }

                    BeatmapDatabase.PopulateBeatmap(b);
                    maps.AddInPlace(b);
                }

                BeatmapDatabase.Write();
            }

            int index = 0;

            string lastPackId = null;
            foreach (Beatmap b in maps)
            {
                if (b.Package == null)
                {
                    continue;
                }

                BeatmapPanel panel = new BeatmapPanel(b, panelSelected, index++);
                if (b.PackId != lastPackId)
                {
                    panel.NewSection = true;
                    lastPackId       = b.PackId;
                }

                topmostSpriteManager.Add(panel);
                panels.Add(panel);
            }

            panelDownloadMore = new BeatmapPanel(null, delegate
            {
                AudioEngine.PlaySample(OsuSamples.MenuHit);
                State = SelectState.Exiting;
                Director.ChangeMode(OsuMode.Store);
            }, index++)
            {
                NewSection = true
            };

            panelDownloadMore.s_Text.Text      = LocalisationManager.GetString(OsuString.DownloadMoreSongs);
            panelDownloadMore.s_Text.Colour    = Color4.White;
            panelDownloadMore.s_Text.Offset.Y += 16;
            panels.Add(panelDownloadMore);
            topmostSpriteManager.Add(panelDownloadMore);
        }