internal static bool Prefix(UnityEngine.GameObject gameObject, ref string __result) { if (gameObject == null) { return(true); } var component = gameObject.GetComponent <ZEventListener>(); if (component == null) { return(true); } if (component.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { var track = Mod.Instance.Variables.CachedMusicTrack.GetOrCreate(component, () => MusicTrack.FromObject(component)); if (track == null) { __result = "Music Track?"; } __result = $"Music Track: {track.Name}"; return(false); } return(true); }
public string GetMusicChoiceValue(GameObject obj, string key) { var listener = obj.GetComponent <ZEventListener>(); if (listener?.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>()) != true) { return(null); } var choice = mod_.Variables.CachedMusicChoice.GetOrCreate(listener, () => MusicChoice.FromObject(listener)); if (choice == null) { return(null); } choice.Choices.TryGetValue(key, out MusicChoiceEntry entry); if (entry == null) { return(null); } return(entry.Track); }
public InfoData(string _version, string _songName, string _songSubName, string _songAuthorName, string _levelAuthorName, float _beatsPerMinute, float _shuffle, float _shufflePeriod, float _previewStartTime, float _previewDuration, string _songFilename, string _coverImageFilename, string _environmentName, string _allDirectionsEnvironmentName, float _songTimeOffset, CustomDataInfo _customData, List<DifficultyBeatmapSets> _difficultyBeatmapSets) { this._version = _version; this._songName = _songName; this._songSubName = _songSubName; this._songAuthorName = _songAuthorName; this._levelAuthorName = _levelAuthorName; this._beatsPerMinute = _beatsPerMinute; this._shuffle = _shuffle; this._shufflePeriod = _shufflePeriod; this._previewStartTime = _previewStartTime; this._previewDuration = _previewDuration; this._songFilename = _songFilename; this._coverImageFilename = _coverImageFilename; this._environmentName = _environmentName; this._allDirectionsEnvironmentName = _allDirectionsEnvironmentName; this._songTimeOffset = _songTimeOffset; if (this._customData == null) { this._customData = new(new("Lolighter", new())); } this._customData = _customData; this._difficultyBeatmapSets = _difficultyBeatmapSets; }
internal static void Postfix(ZEventListener __instance) { if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { return; } Mod.Instance.Variables.CachedMusicChoice.GetOrCreate(__instance, () => MusicChoice.FromObject(__instance)); }
internal static bool Prefix(ZEventListener __instance, ref string __result) { if (__instance == null) { return(true); } if (__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { __result = "Custom music track choice"; return(false); } else if (__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { __result = "Custom music track data"; return(false); } return(true); }
public CustomDataInfo GetInfo() { return CustomDataInfo.GetInfo(GetType()); }
internal static void Postfix(NGUIComponentInspector __instance) { if (__instance.ISerializable_ != null && __instance.ISerializable_.GetType() == typeof(ZEventListener)) { if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { __instance.SetRemoveComponentButtonVisibility(false); } else if (((ZEventListener)__instance.ISerializable_).eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { __instance.SetRemoveComponentButtonVisibility(false); } } }
internal static bool Prefix(ZEventListener __instance, IVisitor visitor) { Mod mod = Mod.Instance; if (!(visitor is NGUIComponentInspector)) { return(true); } NGUIComponentInspector inspector = visitor as NGUIComponentInspector; if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { return(true); } visitor.Visit("eventName_", ref __instance.eventName_, false, null); visitor.Visit("delay_", ref __instance.delay_, false, null); var isEditing = inspector.isEditing_; var data = mod.Variables.CachedMusicChoice.GetOrCreate(__instance, () => new MusicChoice()); if (data.LastWrittenData != __instance.eventName_) { data.ReadObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); } else if (!isEditing) { var anyChanges = false; var old = data.LastWritten; if (data.Choices.Count != old.Choices.Count) { anyChanges = true; } foreach (var newChoice in data.Choices) { if (!old.Choices.ContainsKey(newChoice.Key) || old.Choices[newChoice.Key].Track != newChoice.Value.Track) { anyChanges = true; break; } } if (anyChanges) { data.WriteObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); } } for (int index = 0; index < data.Choices.Count; index++) { string key = data.Choices.Keys.ToArray()[index]; var track = data.Choices[key].Track; visitor.Visit($"{key} Track", ref track, null); } return(false); }
internal static bool Prefix(NGUIComponentInspector __instance) { if (__instance.ISerializable_ is ZEventListener listener && listener.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicChoice>())) { if (G.Sys.LevelEditor_.StartNewToolJobOfType(typeof(RemoveMusicChoiceTool), false) is RemoveMusicChoiceTool removeTool) { var ser = __instance.iSerializables_; removeTool.SetComponents(ser.Cast <Component>().ToArray()); } return(false); } return(true); }
internal static bool Prefix(ZEventListener __instance, IVisitor visitor) { Mod mod = Mod.Instance; if (!(visitor is NGUIComponentInspector)) { return(true); } NGUIComponentInspector inspector = visitor as NGUIComponentInspector; if (!__instance.eventName_.StartsWith(CustomDataInfo.GetPrefix <MusicTrack>())) { return(true); } visitor.Visit("eventName_", ref __instance.eventName_, false, null); visitor.Visit("delay_", ref __instance.delay_, false, null); var isEditing = inspector.isEditing_; var data = mod.Variables.CachedMusicTrack.GetOrCreate(__instance, () => new MusicTrack()); if (data.LastWrittenData != __instance.eventName_) { data.ReadObject(__instance); data.LastWrittenData = __instance.eventName_; data.EmbedFile = (data.Embedded.Length > 0 ? "Embedded" : ""); data.LastWritten = data.Clone(); } else if (!isEditing) { var anyChanges = false; var old = data.LastWritten; if (data.Name != old.Name || data.DownloadUrl != old.DownloadUrl || data.FileType != old.FileType) { anyChanges = true; } if (data.EmbedFile != old.EmbedFile) { var newRef = data.EmbedFile; if (newRef == "") { data.Embedded = new byte[0]; anyChanges = true; } else { try { newRef = newRef.Trim('"', '\''); var extension = Path.GetExtension(newRef); var file = FileEx.ReadAllBytes(newRef); data.Embedded = file ?? throw new Exception("Missing file"); data.FileType = extension; data.DownloadUrl = ""; anyChanges = true; } catch (Exception e) { data.Embedded = new byte[0]; data.FileType = ".mp3"; anyChanges = true; // TODO: warn user UnityEngine.Debug.Log($"Failed to embed {newRef} because {e}"); } } } if (anyChanges) { data.FileLocation = null; data.Attempted = false; data.EmbedFile = (data.Embedded.Length > 0 ? "Embedded" : ""); data.NewVersion(); data.WriteObject(__instance); data.LastWrittenData = __instance.eventName_; data.LastWritten = data.Clone(); var lastTrackName = mod.Variables.CurrentTrackName; if (lastTrackName == old.Name) { mod.SoundPlayer.StopCustomMusic(); } mod.SoundPlayer.DownloadAllTracks(); if (lastTrackName == data.Name || mod.SoundPlayer.GetMusicChoiceValue(G.Sys.LevelEditor_.WorkingSettings_.gameObject, "Level") == data.Name) { mod.SoundPlayer.PlayTrack(data.Name, 0f); } } } visitor.Visit("Name", ref data.Name, null); visitor.Visit("Type", ref data.FileType, null); visitor.Visit("Embed File", ref data.EmbedFile, mod.Variables.MusicTrackOptions); visitor.VisitAction("Select File", () => { var dlgOpen = new System.Windows.Forms.OpenFileDialog { Filter = "Music file (*.mp3, *.wav, *.aiff)|*.mp3;*.wav;*.aiff|All Files (*.*)|*.*", SupportMultiDottedExtensions = true, RestoreDirectory = true, Title = "Select a music file", CheckFileExists = true, CheckPathExists = true }; if (dlgOpen.ShowDialog() == System.Windows.Forms.DialogResult.OK) { data.EmbedFile = dlgOpen.FileName; } }, mod.Variables.MusicTrackButtonOptions); visitor.Visit("Download URL", ref data.DownloadUrl, null); var Error = data.GetError(); if (Error == null) { Error = "None"; } visitor.Visit("Error", ref Error, null); return(false); }