예제 #1
0
        /// <summary>
        /// Convert Beat Saber data to a minecraft ResourcePack
        /// </summary>
        /// <param name="unzippedFolderPath">Path to unzipped beat saber pack</param>
        /// <param name="datapackOutputPath">Folder path that Resourcepack will be generated in</param>
        /// <param name="packInfo">Beat Saber Infomation</param>
        /// <returns>-1 if successful</returns>
        public static async Task <ConversionError> FromBeatSaberData(string datapackOutputPath, BeatSaberMap beatSaberMap)
        {
            return(await Task.Run(() =>
            {
                var packInfo = beatSaberMap.InfoData;
                var unzippedFolderPath = beatSaberMap.ExtractedFilePath;
                if (!Directory.Exists(unzippedFolderPath) || packInfo == null)
                {
                    return ConversionError.MissingInfo;
                }

                Dictionary <string, string> keyVars = new Dictionary <string, string>();

                string folder_uuid = SafeFileManagement.GetFileName(Path.GetFileName(unzippedFolderPath)).MakeMinecraftSafe();
                string packName = Globals.RESOURCEPACK + folder_uuid;

                // Paths
                string fullOutputPath = Path.Combine(datapackOutputPath, packName + Globals.ZIP);
                string rootFolderPath = Path.Combine(unzippedFolderPath, packName);
                string minecraftNamespace = Path.Combine(rootFolderPath, Globals.ASSETS, Globals.MINECRAFT);
                string mapSong = Path.Combine(unzippedFolderPath, packInfo.SongFilename);
                string packSong = Path.Combine(minecraftNamespace, Globals.SOUNDS, Globals.CUSTOM, folder_uuid + Globals.OGG);
                string mapIcon = Path.Combine(unzippedFolderPath, packInfo.CoverImageFilename);
                string packIcon = Path.Combine(rootFolderPath, Globals.PACK_ICON);

                // Replaced vars
                keyVars["SONGUUID"] = folder_uuid;
                keyVars["SONGNAME"] = packInfo.SongName + packInfo.SongSubName;
                keyVars["AUTHORNAME"] = packInfo.SongAuthorName;

                // Copying Template
                string copiedTemplatePath = Path.Combine(unzippedFolderPath, Globals.TEMPLATE_RESOURCES_PACK_NAME);

                if (SafeFileManagement.DirectoryCopy(Globals.pathOfResourcepackTemplate, unzippedFolderPath, true, Globals.excludeExtensions, Globals.NUMBER_OF_IO_RETRY_ATTEMPTS))
                {
                    if (SafeFileManagement.MoveDirectory(copiedTemplatePath, rootFolderPath, Globals.NUMBER_OF_IO_RETRY_ATTEMPTS))
                    {
                        Filemanagement.UpdateAllCopiedFiles(rootFolderPath, keyVars);

                        // Copying Image Icon
                        SafeFileManagement.CopyFileTo(mapIcon, packIcon, true, Globals.NUMBER_OF_IO_RETRY_ATTEMPTS);

                        // Copying Song
                        if (SafeFileManagement.CopyFileTo(mapSong, packSong, true, Globals.NUMBER_OF_IO_RETRY_ATTEMPTS))
                        {
                            if (!Filemanagement.UpdateFileWithKeys(Path.Combine(minecraftNamespace, Globals.SOUNDS_JSON), keyVars))
                            {
                                return ConversionError.OtherFail;
                            }
                        }

                        // Creating Zip
                        Archive.Compress(rootFolderPath, fullOutputPath, true);
                        return ConversionError.None;
                    }
                }
                return ConversionError.FailedToCopyFile;
            }));
        }
        public DataPackData(string unzippedFolderPath, string datapackOutputPath, BeatSaberMap beatSaberMap)
        {
            var packInfo = beatSaberMap.InfoData;

            keyVars     = new Dictionary <string, string>();
            folder_uuid = SafeFileManagement.GetFileName(Path.GetFileName(unzippedFolderPath)).MakeMinecraftSafe();
            packName    = Globals.DATAPACK + folder_uuid;
            songGuid    = beatSaberMap.GuidId.ToString();

            // Paths
            datapackRootPath            = Path.Combine(unzippedFolderPath, packName);
            fullOutputPath              = Path.Combine(datapackOutputPath, packName + Globals.ZIP);
            blockSaberBaseFunctionsPath = Path.Combine(datapackRootPath, Globals.DATA, Globals.BLOCK_SABER_BASE, Globals.FUNCTIONS);
            folder_uuidFunctionsPath    = Path.Combine(datapackRootPath, Globals.DATA, folder_uuid, Globals.FUNCTIONS);
            spawnNotesBasePath          = Path.Combine(folder_uuidFunctionsPath, Globals.SPAWN_NOTES_BASE_FUNCTION);

            // Values
            metersPerTick    = packInfo.BeatsPerMinute / 60.0d * 24 * 0.21 / 20;
            ticksStartOffset = (int)(Mathf.Clamp((float)(packInfo.BeatsPerMinute / 60d * 10), 7, 20) / metersPerTick);

            // Set up Keys
            keyVars["MAPPER_NAME"]      = packInfo.LevelAuthorName;
            keyVars["BEATS_PER_MINUTE"] = packInfo.BeatsPerMinute.ToString();
            keyVars["SONGID"]           = beatSaberMap.GuidId.GetHashCode().ToString();
            keyVars["MOVESPEED"]        = metersPerTick.ToString();
            keyVars["SONGTITLE"]        = packInfo.SongName + " " + packInfo.SongSubName;
            keyVars["SONGSHORTNAME"]    = packInfo.SongName;
            keyVars["SONGARTIST"]       = packInfo.SongAuthorName;
            keyVars["folder_uuid"]      = folder_uuid;
            keyVars["SONGDIFFICULTYID"] = songGuid + "1";

            StringBuilder listOfDifficulties = new StringBuilder();
            var           beatMapSets        = beatSaberMap.InfoData.DifficultyBeatmapSets;

            for (int beatMapCounts = 0; beatMapCounts < beatMapSets.Length; beatMapCounts++)
            {
                var beatMapInfos = beatMapSets[beatMapCounts].DifficultyBeatmaps;
                int beatMapCount = beatMapInfos.Length;
                for (int difficulty = 0; difficulty < beatMapCount; difficulty++)
                {
                    listOfDifficulties.Append(beatMapInfos[difficulty].Difficulty);
                    if (difficulty < beatMapCount - 1)
                    {
                        listOfDifficulties.Append(" | ");
                    }
                }
            }
            keyVars["DIFFICULTYLIST"] = listOfDifficulties.ToString();
        }