Example #1
0
        public static async Task <List <Beatmaps> > GetBeatmapsAsync(ulong id, BeatmapType bmType = BeatmapType.ByBeatmap, GameMode gameMode = GameMode.Standard, int limit = 500)
        {
            string mode    = UserMode.ToString(gameMode);
            string type    = Beatmap.ToString(bmType);
            string request = await GetAsync($"{GET_BEATMAPS_URL}{API_KEY_PARAMETER}{ApiKey}{type}{id}{LIMIT_PARAMETER}{limit}{mode}");

            return(JsonConvert.DeserializeObject <List <Beatmaps> >(request));
        }
        public void SetChannels(BeatmapType typeInstance)
        {
            for (int i = 0; i < _expectedFrameValueControllers.Count; i++)
            {
                var templateFrameController = (TemplateFrameValueController)_expectedFrameValueControllers[i];
                templateFrameController.SetChannelNameText(typeInstance.ChannelFlyweights[i].Name);

                //rotate value button?
            }
        }
Example #3
0
        public static async Task <Beatmaps> GetBeatmapAsync(ulong beatmapId, BeatmapType bmType = BeatmapType.ByDifficulty, GameMode gameMode = GameMode.Standard)
        {
            string mode    = UserMode.ToString(gameMode);
            string type    = Beatmap.ToString(bmType);
            string request = await GetAsync($"{GET_BEATMAPS_URL}{API_KEY_PARAMETER}{ApiKey}{type}{beatmapId}{mode}");

            List <Beatmaps> r = JsonConvert.DeserializeObject <List <Beatmaps> >(request);

            return(r.Count > 0 ? r[0] : null);
        }
Example #4
0
        public Beatmap ToBeatmap()
        {
            var typeInstance = BeatmapType.Get(TypeName);

            if (typeInstance == null)
            {
                return(null);
            }

            var beatmap = new Beatmap(typeInstance);

            beatmap.Frames.AddRange(Frames.Select(sFrame => sFrame.ToFrame(typeInstance)));

            return(beatmap);
        }
Example #5
0
        public void Awake()
        {
            _songNames = PopulateDropdown(NameDropdown1, SongDataFileUtility.GetAllSongNames(), value => value);
            NameDropdown2.ClearOptions();
            NameDropdown2.AddOptions(_songNames);

            _difficulties  = PopulateDropdown(DifficultyDropdown, BeatmapDifficulty.GetAll(), value => value.Name);
            _typeInstances = PopulateDropdown(TypeDropdown, BeatmapType.GetAll(), value => value.Name);

            CreateNewSongButton.onClick.AddListener(OnClickCreateSongButton);

            CreateBeatmapButton.onClick.AddListener(OnClickCreateBeatmapButton);
            LoadBeatmapButton.onClick.AddListener(OnClickLoadBeatmapButton);
            RefreshButton.onClick.AddListener(OnClickRefreshButton);

            EditSongButton.onClick.AddListener(OnClickEditSongButton);
        }
Example #6
0
        public static string ToString(BeatmapType type)
        {
            switch (type)
            {
            case BeatmapType.ByBeatmap:
                return("&s=");

            case BeatmapType.ByDifficulty:
                return("&b=");

            case BeatmapType.ByCreator:
                return("&u=");

            default:
                return("&s=");
            }
        }
Example #7
0
        protected override SaveArgs PrepareSave()
        {
            BeatmapEditor beatmapEditor = (BeatmapEditor)WeakEditor;

            string            songName    = WeakEditor.SongName;
            BeatmapDifficulty difficulty  = beatmapEditor.Difficulty;
            BeatmapType       beatmapType = beatmapEditor.BeatmapWriter.TypeInstance;

            var saveDataIsValid = !string.IsNullOrEmpty(songName) &&
                                  difficulty != null &&
                                  beatmapType != null;

            var dataWillOverwrite = SongDataFileUtility.BeatmapFileExists(songName, beatmapType, difficulty);

            var willOverwriteMessage =
                string.Format(
                    "Song: \"{0}\"\n" +
                    "Difficulty: \"{1}\"\n" +
                    "Beatmap Type: \"{2}\"\n" +
                    "A beatmap already exists for this song and difficulty. Are you sure you want to overwrite it?",
                    songName, difficulty.Name, beatmapType);

            var successMessage =
                string.Format(
                    "Song: \"{0}\"\n" +
                    "Difficulty: \"{1}\"\n" +
                    "Beatmap Type: \"{2}\"\n" +
                    "Beatmap saved successfully.",
                    songName, difficulty.Name, beatmapType);

            void writeToFile() => WriteToFile(songName, difficulty);    //local function

            return(new SaveArgs()
            {
                SaveDataIsValid = saveDataIsValid,
                DataWillOverwrite = dataWillOverwrite,
                WillOverwriteMessage = willOverwriteMessage,
                SuccessMessage = successMessage,
                WriteToFileDelegate = writeToFile,
            });
        }
Example #8
0
        public void ParseStructuredBeatmap(string path, BeatmapType type, out bool succeed)
        {
            string       rawData;
            StreamReader stream;

            if (Game.Packet.loadFromResources)
            {
                var beatmapFile = Resources.Load <TextAsset>(path);
                rawData = beatmapFile.text;
            }
            else
            {
                try
                {
                    stream  = new StreamReader(path);
                    rawData = stream.ReadToEnd();
                    stream.Close();
                }
                catch (Exception e)
                {
                    TSystemStatic.LogWithException("Beatmap file does not exists.", e);
                    succeed = false;
                    return;
                }
            }

            switch (type)
            {
            case BeatmapType.TWx:
                succeed = ParseTWx(rawData);
                break;

            case BeatmapType.SSTrain:
                succeed = ParseSSTrain(rawData);
                break;

            default:
                succeed = false;
                break;
            }
        }
Example #9
0
        public Frame ToFrame(BeatmapType typeInstance)
        {
            if (typeInstance.ChannelFlyweights.Count != ValueNames.Length)
            {
                Game.Log(Logging.Category.SONG_DATA, "Serializable frame value count and requested type instance channel count mismatch.", Logging.Level.LOG_WARNING);
                return(null);
            }

            var values = new List <Channel.Value>();

            for (int i = 0; i < typeInstance.ChannelFlyweights.Count; i++)
            {
                var channel = typeInstance.ChannelFlyweights[i];    //associated channel

                //try to find a valid value with that name (case insensitive), otherwise return the default for the channel
                var value = channel.ValueFlyweights.Find(v => v.Name.ToUpperInvariant() == ValueNames[i].ToUpperInvariant()) ?? channel.DefaultValueFlyweight;

                values.Add(value);    //add it to the list
            }
            return(new Frame(values));
        }
Example #10
0
 public static bool TryReadBeatmap(string songName, BeatmapType typeInstance, BeatmapDifficulty difficulty, out Beatmap newBeatmap)
 {
     newBeatmap = null;
     try
     {
         if (Directory.Exists(GetSongDirectoryPath(songName)))
         {
             string filePath = GetBeatmapFilePath(songName, typeInstance, difficulty);
             if (File.Exists(filePath))
             {
                 byte[] bytes = File.ReadAllBytes(filePath);
                 if (TryDeserializeBeatmap(bytes, out SerializableBeatmap beatmapData))
                 {
                     if (beatmapData.TypeName == typeInstance.Name)
                     {
                         newBeatmap = beatmapData.ToBeatmap();
                         if (newBeatmap != null)
                         {
                             Game.Log(Logging.Category.SONG_DATA, "Read beatmap from file: " + filePath, Logging.Level.LOG);
                             return(true);
                         }
                         throw new IOException("Found beatmap is of unknown type.");
                     }
                     throw new IOException("Found beatmap is of incorrect type.");
                 }
                 throw new IOException("Beatmap data is corrupt.");
             }
             throw new FileNotFoundException(filePath);
         }
         throw new DirectoryNotFoundException();
     }
     catch (System.Exception e)
     {
         Game.Log(Logging.Category.SONG_DATA, "Unable to read beatmap from file: " + e, Logging.Level.LOG_WARNING);
     }
     return(false);
 }
Example #11
0
 public static string GetBeatmapFilePath(string songName, BeatmapType typeInstance, BeatmapDifficulty difficulty)
 {
     return(string.Format("{0}/{1}", GetBeatmapSubDirectoryPath(songName, typeInstance), GetBeatmapFileName(typeInstance, difficulty)));
 }
Example #12
0
 public static string GetBeatmapFileName(BeatmapType typeInstance, BeatmapDifficulty difficulty)
 {
     return(string.Format("{0}_{1}.{2}", typeInstance.Name, difficulty.Name, BEATMAP_FILE_EXTENSION));
 }
Example #13
0
 public static string GetBeatmapSubDirectoryPath(string songName, BeatmapType typeInstance)
 {
     return(string.Format("{0}/{1}", GetBeatmapDirectoryPath(songName), typeInstance.Name));
 }
Example #14
0
 public static bool BeatmapFileExists(string songName, BeatmapType typeInstance, BeatmapDifficulty difficulty)
 {
     return(File.Exists(GetBeatmapFilePath(songName, typeInstance, difficulty)));
 }