From 84ab4f753f4513f08da279c872600b91d167b998 Mon Sep 17 00:00:00 2001 From: minenice55 Date: Wed, 11 Jan 2023 19:55:31 -0500 Subject: [PATCH] file explorer chart loading --- Assets/Resources/Prefabs/Cameras.prefab | 2 +- Assets/Scenes/Editor.unity | 17 ++-- Assets/Scripts/AppInfo.cs | 4 +- .../Scripts/BeatmapFormats/DynamicBeatmap.cs | 3 +- Assets/Scripts/DebugUI.cs | 2 +- Assets/Scripts/GameManager.cs | 35 ++++---- Assets/Scripts/Initializer.cs | 81 ++++++++++++++++++- Assets/Scripts/LevelEditor/BoxSelection.cs | 1 + Assets/Scripts/LevelEditor/EditorTheme.cs | 1 + ProjectSettings/ProjectSettings.asset | 6 +- 10 files changed, 119 insertions(+), 33 deletions(-) diff --git a/Assets/Resources/Prefabs/Cameras.prefab b/Assets/Resources/Prefabs/Cameras.prefab index 37ea5abc3..b36714f5d 100644 --- a/Assets/Resources/Prefabs/Cameras.prefab +++ b/Assets/Resources/Prefabs/Cameras.prefab @@ -394,7 +394,7 @@ Camera: m_Depth: 1 m_CullingMask: serializedVersion: 2 - m_Bits: 8192 + m_Bits: 8256 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index c913dbd8f..3efd88305 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -4903,7 +4903,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: -289.15, y: 2} + m_AnchoredPosition: {x: -289.15002, y: 2} m_SizeDelta: {x: -578.29, y: 49.92} m_Pivot: {x: 0.5, y: 0} --- !u!114 &156962255 @@ -25563,7 +25563,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1589389271} m_Direction: 2 m_Value: 1 - m_Size: 1 + m_Size: 0.99823457 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -31110,7 +31110,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -408.97998, y: -17} + m_AnchoredPosition: {x: -408.98004, y: -17} m_SizeDelta: {x: -817.96, y: -46.29} m_Pivot: {x: 0.5, y: 0.5} --- !u!1 &1118147045 @@ -32587,7 +32587,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0, y: 129.94043} + m_AnchoredPosition: {x: 0, y: 129.911} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 1} --- !u!114 &1154875944 @@ -39444,6 +39444,7 @@ MonoBehaviour: m_EditorClassIdentifier: level: {fileID: 0} music: {fileID: 0} + canvas: {fileID: 1791483799} debugUI: 0 playOnStart: 0 editor: 1 @@ -42568,7 +42569,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 0, y: -42.494995} + m_AnchoredPosition: {x: 0, y: -42.495026} m_SizeDelta: {x: 1440.022, y: -84.99} m_Pivot: {x: 0, y: 0.5} --- !u!114 &1527251881 @@ -49428,7 +49429,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 0, y: -84.99002} + m_AnchoredPosition: {x: 0, y: -84.99005} m_SizeDelta: {x: 320, y: -84.99} m_Pivot: {x: 0, y: 1} --- !u!1 &1852819572 @@ -54654,7 +54655,7 @@ Camera: m_Depth: -1 m_CullingMask: serializedVersion: 2 - m_Bits: 32 + m_Bits: 96 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 @@ -55299,7 +55300,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 0, y: -42.494995} + m_AnchoredPosition: {x: 0, y: -42.495026} m_SizeDelta: {x: 1054, y: -84.99} m_Pivot: {x: 0, y: 0.5} --- !u!114 &2066632681 diff --git a/Assets/Scripts/AppInfo.cs b/Assets/Scripts/AppInfo.cs index 967171b79..b363dc186 100644 --- a/Assets/Scripts/AppInfo.cs +++ b/Assets/Scripts/AppInfo.cs @@ -2,8 +2,8 @@ using System; public static class AppInfo { //--- AutoGenerated.begin - public const string Version = "0.0.961"; - public static readonly DateTime Date = new DateTime(2022, 10, 13, 16, 09, 43, 581, DateTimeKind.Utc); + public const string Version = "0.0.963"; + public static readonly DateTime Date = new DateTime(2023, 01, 12, 00, 27, 14, 138, DateTimeKind.Utc); //--- AutoGenerated.end } diff --git a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs index 77ef3024b..6788ab6f9 100644 --- a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs +++ b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs @@ -353,7 +353,8 @@ namespace HeavenStudio Debug.LogWarning($"Unknown game {gameName} found in remix.json! Adding game..."); game = new Minigames.Minigame(gameName, DisplayName(gameName) + " \n[inferred from remix.json]", "", false, true, new List()); EventCaller.instance.minigames.Add(game); - Editor.Editor.instance.AddIcon(game); + if (Editor.Editor.instance != null) + Editor.Editor.instance.AddIcon(game); } action = EventCaller.instance.GetGameAction(game, actionName); if (action == null) diff --git a/Assets/Scripts/DebugUI.cs b/Assets/Scripts/DebugUI.cs index 80ace75f3..349d667a3 100644 --- a/Assets/Scripts/DebugUI.cs +++ b/Assets/Scripts/DebugUI.cs @@ -31,7 +31,7 @@ namespace HeavenStudio private void Start() { - CreateDebugUI(out Title); SetText(Title, "Rhythm Heaven Mania v1.0 BRAEDON DEBUG PLAYTEST"); + CreateDebugUI(out Title); SetText(Title, $"Heaven Studio {GlobalGameManager.buildTime}"); CreateDebugUI(out SongPosBeats); CreateDebugUI(out SongPos); CreateDebugUI(out SecPerBeat); diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index dd8ed9d6c..65b2066dc 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -19,7 +19,8 @@ namespace HeavenStudio public List SoundObjects = new List(); [Header("Components")] - public TextAsset txt; + public string txt; + public string ext; public Camera GameCamera, CursorCam, OverlayCamera; public GameObject GameLetterbox; public CircleCursor CircleCursor; @@ -83,17 +84,6 @@ namespace HeavenStudio GameObject fade = new GameObject(); this.fade = fade.AddComponent(); - if (txt != null) - { - string json = txt.text; - Beatmap = JsonConvert.DeserializeObject(json); - } - else - { - NewRemix(); - } - - SortEventsList(); GlobalGameManager.Init(); @@ -106,13 +96,16 @@ namespace HeavenStudio GameObject textbox = Instantiate(Resources.Load("Prefabs/Common/Textbox")); textbox.name = "Textbox"; - - if (playOnStart) + if (txt != null && ext != null) { - Play(startBeat); + LoadRemix(txt, ext); + } + else + { + NewRemix(); } - // SetCurrentGame(eventCaller.GamesHolder.transform.GetComponentsInChildren()[1].name); + SortEventsList(); if (Beatmap.entities.Count >= 1) { @@ -123,6 +116,11 @@ namespace HeavenStudio { SetGame("noGame"); } + + if (playOnStart) + { + Play(startBeat); + } } public void NewRemix() @@ -384,6 +382,11 @@ namespace HeavenStudio SetCurrentEventToClosest(beat); onBeatChanged?.Invoke(beat); KillAllSounds(); + + if (playOnStart) + { + Play(0); + } } public void KillAllSounds() diff --git a/Assets/Scripts/Initializer.cs b/Assets/Scripts/Initializer.cs index ee18415c9..7490aa468 100644 --- a/Assets/Scripts/Initializer.cs +++ b/Assets/Scripts/Initializer.cs @@ -1,5 +1,11 @@ +using System; using System.Collections; using System.Collections.Generic; +using System.IO; + +using System.IO.Compression; +using System.Text; + using UnityEngine; using UnityEngine.Audio; @@ -9,13 +15,37 @@ namespace HeavenStudio { public TextAsset level; public AudioClip music; + public GameObject canvas; public bool debugUI; public bool playOnStart = false; public bool editor = false; + string json = ""; + string ext = ""; + private void Start() { + string[] args = System.Environment.GetCommandLineArgs(); + string input = ""; + for (int i = 1; i < args.Length; i++) { + // first arg is always this executable + Debug.Log(args[i]); + if (args[i].IndexOfAny(Path.GetInvalidPathChars()) == -1) + { + if (File.Exists(args[i])) + { + input = args[i]; + editor = false; + playOnStart = true; + } + } + else if (args[i] == "-debug") + { + debugUI = true; + } + } + GameObject Cameras = Instantiate(Resources.Load("Prefabs/Cameras")); Cameras.name = "Cameras"; GameObject MainCamera = Cameras.transform.GetChild(0).gameObject; GameObject CursorCamera = Cameras.transform.GetChild(1).gameObject; @@ -33,7 +63,6 @@ namespace HeavenStudio GameManager gameManager = GameManager.AddComponent(); gameManager.playOnStart = playOnStart; - gameManager.txt = level; gameManager.GamesHolder = Games; gameManager.CircleCursor = Cursor.transform.GetChild(0).GetComponent(); gameManager.GameCamera = MainCamera.GetComponent(); @@ -64,8 +93,58 @@ namespace HeavenStudio } else { + this.GetComponent().enabled = false; + this.GetComponent().enabled = false; + this.GetComponent().enabled = false; + canvas.SetActive(false); + + OpenCmdRemix(input); + Debug.Log(json); + gameManager.txt = json; + gameManager.ext = ext; gameManager.Init(); } } + + public void OpenCmdRemix(string path) + { + if (path == string.Empty) return; + if (!File.Exists(path)) return; + byte[] MusicBytes; + bool loadedMusic = false; + string extension = path.GetExtension(); + + using var zipFile = File.Open(path, FileMode.Open); + using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read); + + foreach (var entry in archive.Entries) + switch (entry.Name) + { + case "remix.json": + { + using var stream = entry.Open(); + using var reader = new StreamReader(stream); + json = reader.ReadToEnd(); + ext = extension; + break; + } + case "song.ogg": + { + using var stream = entry.Open(); + using var memoryStream = new MemoryStream(); + stream.CopyTo(memoryStream); + MusicBytes = memoryStream.ToArray(); + Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(MusicBytes, "music"); + loadedMusic = true; + break; + } + } + + if (!loadedMusic) + { + Conductor.instance.musicSource.clip = null; + MusicBytes = null; + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/BoxSelection.cs b/Assets/Scripts/LevelEditor/BoxSelection.cs index 11c89d362..9caddd16c 100644 --- a/Assets/Scripts/LevelEditor/BoxSelection.cs +++ b/Assets/Scripts/LevelEditor/BoxSelection.cs @@ -48,6 +48,7 @@ namespace HeavenStudio.Editor private void Update() { + if (Editor.instance == null) return; float deltaTimelineX = timelineContent.transform.localPosition.x - timelineLastX; Camera camera = Editor.instance.EditorCamera; diff --git a/Assets/Scripts/LevelEditor/EditorTheme.cs b/Assets/Scripts/LevelEditor/EditorTheme.cs index effab54ec..a28e057f6 100644 --- a/Assets/Scripts/LevelEditor/EditorTheme.cs +++ b/Assets/Scripts/LevelEditor/EditorTheme.cs @@ -31,6 +31,7 @@ namespace HeavenStudio.Editor private void Start() { + if (Editor.instance == null) return; specialLayers.GetComponent().color = theme.properties.SpecialLayersCol.Hex2RGB(); tempoLayer.GetComponent().color = theme.properties.TempoLayerCol.Hex2RGB(); musicLayer.GetComponent().color = theme.properties.MusicLayerCol.Hex2RGB(); diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index de7d695db..4a9cc8c02 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -134,7 +134,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 0.0.961 + bundleVersion: 0.0.963 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0 @@ -155,11 +155,11 @@ PlayerSettings: applicationIdentifier: Standalone: com.Megaminerzero.HeavenStudio buildNumber: - Standalone: 961 + Standalone: 963 iPhone: 0 tvOS: 0 overrideDefaultApplicationIdentifier: 0 - AndroidBundleVersionCode: 961 + AndroidBundleVersionCode: 963 AndroidMinSdkVersion: 19 AndroidTargetSdkVersion: 0 AndroidPreferredInstallLocation: 1