Beispiel #1
0
        public static ulong RemoveLevel(SerializedAssets assets, LevelBehaviorData level)
        {
            // We want to find the level object in the assets list of objects so that we can remove it via PathID.
            // Well, this is quite a messy solution... But it _should work_...
            // What this is doing: Removing the asset that is a monobehavior, and the monobehavior's data equals this level.
            // Then it casts that to a level behavior data.

            // TODO Make this work with Transactions instead of an assets object.

            // Also remove difficulty beatmaps
            foreach (BeatmapSet s in level.difficultyBeatmapSets)
            {
                foreach (BeatmapDifficulty d in s.difficultyBeatmaps)
                {
                    assets.RemoveAssetAt(d.beatmapData.pathID);
                }
            }
            // Remove cover image
            assets.RemoveAssetAt(level.coverImage.pathID);
            // Remove the file for the audio asset and the audio clip
            var audioAsset = assets.RemoveAssetAt(level.audioClip.pathID).data as AudioClipAssetData;

            if (audioAsset == null)
            {
                throw new ApplicationException($"Could not find audio asset at PathID: {level.audioClip.pathID}");
            }

            // Remove itself!
            ulong levelPathID = assets.RemoveAsset(ao => ao.data.GetType().Equals(typeof(MonoBehaviorAssetData)) &&
                                                   (ao.data as MonoBehaviorAssetData).name == level.levelID + "Level").pathID;

            return(levelPathID);
        }
Beispiel #2
0
        // This method will fail if given an object that is not a LevelBehaviorData
        public static void RemoveLevel(SerializedAssets assets, SerializedAssets.AssetObject obj, Apk.Transaction apk)
        {
            LevelBehaviorData level = (obj.data as MonoBehaviorAssetData).data as LevelBehaviorData;

            // Remove audio file
            foreach (string s in level.OwnedFiles(assets))
            {
                apk.RemoveFileAt($"assets/bin/Data/{s}");
            }

            // Remove things from bottom up, so that pointers to other assets still are rooted
            // and so get fixed up by RemoveAssetAt

            foreach (BeatmapSet s in level.difficultyBeatmapSets)
            {
                foreach (BeatmapDifficulty d in s.difficultyBeatmaps)
                {
                    assets.RemoveAssetAt(d.beatmapData.pathID);
                }
            }

            assets.RemoveAssetAt(level.coverImage.pathID);
            assets.RemoveAssetAt(level.audioClip.pathID);

            assets.RemoveAssetAt(obj.pathID);
        }
Beispiel #3
0
        public AssetPtr AddToAssets(SerializedAssets.Transaction assets, Apk.Transaction apk, string levelID)
        {
            // var watch = System.Diagnostics.Stopwatch.StartNew();
            AudioClipAssetData audioClip    = CreateAudioAsset(apk, levelID);
            AssetPtr           audioClipPtr = assets.AppendAsset(audioClip);

            string             coverPath = Path.Combine(levelFolderPath, _coverImageFilename);
            Texture2DAssetData cover     = Texture2DAssetData.CoverFromImageFile(coverPath, levelID);
            AssetPtr           coverPtr  = assets.AppendAsset(cover);

            AssetPtr environment = new AssetPtr(20, 1); // default environment

            switch (_environmentName)
            {
            case "NiceEnvironment":
                environment = new AssetPtr(38, 3);
                break;

            case "TriangleEnvironment":
                environment = new AssetPtr(0, 252);
                break;

            case "BigMirrorEnvironment":
                environment = new AssetPtr(0, 249);
                break;
            }

            LevelBehaviorData level = new LevelBehaviorData()
            {
                levelID          = levelID,
                songName         = _songName,
                songSubName      = _songSubName,
                songAuthorName   = _songAuthorName,
                levelAuthorName  = _levelAuthorName,
                beatsPerMinute   = _beatsPerMinute,
                songTimeOffset   = _songTimeOffset,
                shuffle          = _shuffle,
                shufflePeriod    = _shufflePeriod,
                previewStartTime = _previewStartTime,
                previewDuration  = _previewDuration,

                audioClip   = audioClipPtr,
                coverImage  = coverPtr,
                environment = environment,

                difficultyBeatmapSets = _difficultyBeatmapSets.Select(s => s.ToAssets(assets, levelFolderPath, levelID)).Where(s => s != null).ToList(),
            };

            MonoBehaviorAssetData monob = new MonoBehaviorAssetData()
            {
                script = new AssetPtr(1, LevelBehaviorData.PathID),
                name   = level.levelID + "Level",
                data   = level,
            };

            // watch.Stop();
            // Console.WriteLine("song: " + watch.ElapsedMilliseconds);

            return(assets.AppendAsset(monob));
        }
Beispiel #4
0
        public Dictionary <string, ulong> FindLevels()
        {
            var dict = new Dictionary <string, ulong>();

            foreach (AssetObject obj in objects)
            {
                if (!(obj.data is MonoBehaviorAssetData))
                {
                    continue;
                }
                MonoBehaviorAssetData monob = (MonoBehaviorAssetData)obj.data;
                if (!(monob.data is LevelBehaviorData))
                {
                    continue;
                }
                LevelBehaviorData levelData = (LevelBehaviorData)monob.data;
                dict.Add(levelData.levelID, obj.pathID);
            }
            return(dict);
        }
Beispiel #5
0
        public HashSet <string> ExistingLevelIDs()
        {
            var set = new HashSet <string>();

            foreach (AssetObject obj in objects)
            {
                if (!(obj.data is MonoBehaviorAssetData))
                {
                    continue;
                }
                MonoBehaviorAssetData monob = (MonoBehaviorAssetData)obj.data;
                if (!(monob.data is LevelBehaviorData))
                {
                    continue;
                }
                LevelBehaviorData levelData = (LevelBehaviorData)monob.data;
                set.Add(levelData.levelID);
            }
            return(set);
        }