diff --git a/LethalLevelLoader/Tools/ContentRestore.cs b/LethalLevelLoader/Tools/ContentRestore.cs deleted file mode 100644 index 6198dc6..0000000 --- a/LethalLevelLoader/Tools/ContentRestore.cs +++ /dev/null @@ -1,163 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; -using UnityEngine.Audio; -using UnityEngine.Rendering; -using Object = UnityEngine.Object; - -namespace LethalLevelLoader.Tools -{ - public abstract class ContentRestore - { - public abstract void Flush(); - } - public abstract class ContentRestore : ContentRestore - { - protected List restoredContentDestroyList = new List(); - - // List Of New Content, List Of Original Comparisons - public virtual void TryRestoreContents(List originalContents, ref List newContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Count; i++) - newContents[i] = TryRestoreContent(newContents[i], originalContents, debugAction, destroyOnRestore); - } - - // 1 New Content : List Of Orignal Comparisons - public virtual T TryRestoreContent(T newContent, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - if (newContent == null) return newContent; - - for (int i = 0; i < originalContents.Count; i++) - if (originalContents[i] != null && CompareContent(originalContents[i], newContent)) - return (RestoreContent(originalContents[i], newContent, debugAction, destroyOnRestore)); - - return (newContent); - } - - // 1 New Content : 1 Original Content Comparison - public virtual T TryRestoreContent(T originalContent, T newContent, bool debugAction = false, bool destroyOnReplace = true) - { - if (originalContent == null || newContent == null) return originalContent; - - if (CompareContent(originalContent, newContent)) - return (RestoreContent(originalContent, newContent, debugAction, destroyOnReplace)); - else - return (originalContent); - } - - public abstract bool CompareContent(T originalContent, T newContent); - - protected virtual T RestoreContent(T originalContent, T newContent, bool debugAction = false, bool destroyOnReplace = true) - { - if (originalContent != null && newContent != null) - { - if (debugAction == true && originalContent.ToString() != null) - DebugHelper.Log("Restoring " + originalContent.GetType().ToString() + ": Old Asset Name: " + originalContent + " , New Asset Name: ", DebugType.Developer); - - if (destroyOnReplace == true) - if (!restoredContentDestroyList.Contains(originalContent)) - restoredContentDestroyList.Add(originalContent); - } - else - DebugHelper.LogWarning("Asset Restoration Failed, Null Reference Found!", DebugType.Developer); - return (newContent); - } - } - - public class UnityContentRestore : ContentRestore where T : Object - { - public override bool CompareContent(T originalContent, T newContent) - { - if (originalContent.name != null && newContent.name != null) - return (originalContent.name == newContent.name); - else - return (false); - } - - public override void Flush() - { - for (int i = 0; i < restoredContentDestroyList.Count; i++) - Object.Destroy(restoredContentDestroyList[i]); - restoredContentDestroyList.Clear(); - } - } - - public class ItemRestore : UnityContentRestore - { - public void TryRestoreContents(List newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Count; i++) - newContents[i].spawnableItem = TryRestoreContent(newContents[i].spawnableItem, originalContents, debugAction, destroyOnRestore); - } - } - - public class EnemyRestore : UnityContentRestore - { - public void TryRestoreContents(List newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Count; i++) - newContents[i].enemyType = TryRestoreContent(newContents[i].enemyType, originalContents, debugAction, destroyOnRestore); - } - } - - public class SpawnableMapObjectRestore : UnityContentRestore - { - public void TryRestoreContents(SpawnableMapObject[] newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Length; i++) - newContents[i].prefabToSpawn = TryRestoreContent(newContents[i].prefabToSpawn, originalContents, debugAction, destroyOnRestore); - } - - public void TryRestoreContents(List newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Count; i++) - for (int j = 0; j < newContents[i].spawnablePrefabs.Count; j++) - newContents[i].spawnablePrefabs[j] = TryRestoreContent(newContents[i].spawnablePrefabs[j], originalContents, debugAction, destroyOnRestore); - } - - public void TryRestoreContents(RandomMapObject newContent, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int j = 0; j < newContent.spawnablePrefabs.Count; j++) - newContent.spawnablePrefabs[j] = TryRestoreContent(newContent.spawnablePrefabs[j], originalContents, debugAction, destroyOnRestore); - } - } - - public class SpawnableOutsideObjectRestore : UnityContentRestore - { - public void TryRestoreContents(SpawnableOutsideObjectWithRarity[] newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - List prefabs = originalContents.Select(p => p.prefabToSpawn).ToList(); - for (int i = 0; i < newContents.Length; i++) - newContents[i].spawnableObject.prefabToSpawn = TryRestoreContent(newContents[i].spawnableObject.prefabToSpawn, prefabs, debugAction, destroyOnRestore); - } - } - - public class ItemGroupRestore : UnityContentRestore - { - public void TryRestoreContents(List newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Count; i++) - newContents[i].spawnableItems = TryRestoreContent(newContents[i].spawnableItems, originalContents, debugAction, destroyOnRestore); - } - } - - public class ReverbPresetRestore : UnityContentRestore - { - public void TryRestoreContents(AudioReverbTrigger[] newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true ) - { - for (int i = 0; i < newContents.Length; i++) - newContents[i].reverbPreset = TryRestoreContent(newContents[i].reverbPreset, originalContents, debugAction, destroyOnRestore); - } - } - - public class AudioMixerGroupRestore : UnityContentRestore - { - public void TryRestoreContents(AudioSource[] newContents, List originalContents, bool debugAction = false, bool destroyOnRestore = true) - { - for (int i = 0; i < newContents.Length; i++) - newContents[i].outputAudioMixerGroup = TryRestoreContent(newContents[i].outputAudioMixerGroup, originalContents, debugAction, destroyOnRestore); - } - } -} diff --git a/LethalLevelLoader/Tools/NewContentRestorer.cs b/LethalLevelLoader/Tools/NewContentRestorer.cs deleted file mode 100644 index e55378b..0000000 --- a/LethalLevelLoader/Tools/NewContentRestorer.cs +++ /dev/null @@ -1,81 +0,0 @@ -using DunGen; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; -using UnityEngine.Audio; -using Object = UnityEngine.Object; - -namespace LethalLevelLoader.Tools -{ - public static class NewContentRestorer - { - public static ItemRestore ItemRestore { get; private set; } = new ItemRestore(); - public static EnemyRestore EnemyRestore { get; private set; } = new EnemyRestore(); - public static SpawnableMapObjectRestore SpawnableMapObjectRestore { get; private set; } = new SpawnableMapObjectRestore(); - public static SpawnableOutsideObjectRestore SpawnableOutsideObjectRestore { get; private set; } = new SpawnableOutsideObjectRestore(); - public static UnityContentRestore LevelAmbienceRestore { get; private set; } = new UnityContentRestore(); - public static ItemGroupRestore ItemGroupRestore { get; private set; } = new ItemGroupRestore(); - - public static AudioMixerGroupRestore AudioMixerGroupRestore { get; private set; } = new AudioMixerGroupRestore(); - public static ReverbPresetRestore ReverbPresetRestore { get; private set; } = new ReverbPresetRestore(); - - internal static List ContentRestores = new List() - { - ItemRestore, EnemyRestore, SpawnableMapObjectRestore, SpawnableOutsideObjectRestore, LevelAmbienceRestore, - ItemGroupRestore, AudioMixerGroupRestore, ReverbPresetRestore - }; - - internal static void RestoreVanillaLevelAssetReferences(ExtendedLevel extendedLevel) - { - SelectableLevel selectableLevel = extendedLevel.SelectableLevel; - - foreach (SpawnableItemWithRarity spawnableItem in new List(selectableLevel.spawnableScrap)) - if (spawnableItem.spawnableItem == null) - selectableLevel.spawnableScrap.Remove(spawnableItem); - - ItemRestore.TryRestoreContents(selectableLevel.spawnableScrap, OriginalContent.Items); - - EnemyRestore.TryRestoreContents(selectableLevel.Enemies, OriginalContent.Enemies); - EnemyRestore.TryRestoreContents(selectableLevel.DaytimeEnemies, OriginalContent.Enemies); - EnemyRestore.TryRestoreContents(selectableLevel.OutsideEnemies, OriginalContent.Enemies); - - SpawnableMapObjectRestore.TryRestoreContents(selectableLevel.spawnableMapObjects, OriginalContent.SpawnableMapObjects); - - SpawnableOutsideObjectRestore.TryRestoreContents(selectableLevel.spawnableOutsideObjects, OriginalContent.SpawnableOutsideObjects); - - selectableLevel.levelAmbienceClips = LevelAmbienceRestore.TryRestoreContent(selectableLevel.levelAmbienceClips, OriginalContent.LevelAmbienceLibraries); - } - - internal static void RestoreVanillaInteriorAssetReferences(ExtendedDungeonFlow extendedDungeonFlow) - { - foreach (Tile tile in extendedDungeonFlow.DungeonFlow.GetTiles()) - RestoreVanillaTileAssetReferences(tile); - } - - internal static void RestoreVanillaTileAssetReferences(Tile tile) - { - foreach (RandomScrapSpawn spawn in tile.GetComponentsInChildren()) - spawn.spawnableItems = ItemGroupRestore.TryRestoreContent(spawn.spawnableItems, OriginalContent.ItemGroups); - - foreach (RandomMapObject spawn in tile.GetComponentsInChildren()) - SpawnableMapObjectRestore.TryRestoreContents(spawn, OriginalContent.SpawnableMapObjects); - } - - internal static void RestoreVanillaParentAudioAssetReferences(GameObject parent) - { - AudioSource[] allAudioSources = parent.GetComponentsInChildren(true); - AudioReverbTrigger[] allReverbTriggers = parent.GetComponentsInChildren(true); - - AudioMixerGroupRestore.TryRestoreContents(allAudioSources, OriginalContent.AudioMixerGroups, destroyOnRestore: false); - ReverbPresetRestore.TryRestoreContents(allReverbTriggers, OriginalContent.ReverbPresets); - } - - internal static void FlushAll() - { - foreach (ContentRestore contentRestore in ContentRestores) - contentRestore.Flush(); - } - } -}