diff --git a/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTextureResourceStore.cs b/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTextureResourceStore.cs index e88a883..3114f1c 100644 --- a/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTextureResourceStore.cs +++ b/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTextureResourceStore.cs @@ -49,7 +49,7 @@ public void TestAddTexture() AddStep("Add texture file to resources", () => { - textureResources.Add("sample-texture", textureStream, textureStream.Length); + textureResources.Add("sample-texture", textureStream); }); AddAssert("Texture file has been added", () => diff --git a/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTrackResourceStore.cs b/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTrackResourceStore.cs index e0c3a76..54e91bb 100644 --- a/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTrackResourceStore.cs +++ b/hues.Game.Tests/NonVisual/ResourceStores/TestRespackTrackResourceStore.cs @@ -39,7 +39,7 @@ public void TestAddTrack() AddStep("Add track file to resources", () => { - trackResources.Add("sample_track", trackStream, trackStream.Length); + trackResources.Add("sample_track", trackStream); }); AddAssert("Track file has beed added to resources", () => diff --git a/hues.Game.Tests/NonVisual/TestSongPlayer.cs b/hues.Game.Tests/NonVisual/TestSongPlayer.cs index 3ef13f9..0c91f1c 100644 --- a/hues.Game.Tests/NonVisual/TestSongPlayer.cs +++ b/hues.Game.Tests/NonVisual/TestSongPlayer.cs @@ -27,13 +27,13 @@ public void SetUp() AddStep("Add `sample_track_1` to resources", () => { using (var stream = TestResources.OpenResource("Tracks/sample.mp3")) - trackResources.Add("sample_track_1", stream, stream.Length); + trackResources.Add("sample_track_1", stream); }); AddStep("Add `sample_track_2` to resources", () => { using (var stream = TestResources.OpenResource("Tracks/sample.mp3")) - trackResources.Add("sample_track_2", stream, stream.Length); + trackResources.Add("sample_track_2", stream); }); } diff --git a/hues.Game.Tests/Program.cs b/hues.Game.Tests/Program.cs index ba16b81..b95e29d 100644 --- a/hues.Game.Tests/Program.cs +++ b/hues.Game.Tests/Program.cs @@ -7,7 +7,7 @@ class Program { public static void Main(string[] args) { - using (GameHost host = Host.GetSuitableHost("hues-visual-test")) + using (DesktopGameHost host = Host.GetSuitableDesktopHost("hues-visual-test")) using (var game = new HuesTestBrowser()) host.Run(game); } diff --git a/hues.Game/Drawables/Editor/EditorTextbox.cs b/hues.Game/Drawables/Editor/EditorTextbox.cs index ac3a8f1..e186156 100644 --- a/hues.Game/Drawables/Editor/EditorTextbox.cs +++ b/hues.Game/Drawables/Editor/EditorTextbox.cs @@ -131,7 +131,9 @@ public class EditorTextbox : CompositeDrawable private readonly Cached highlightCache = new Cached(); private readonly Cached cursorCache = new Cached(); - private ITextInputSource textInput; + [Resolved] + private TextInputSource textInput { get; set; } + private Clipboard clipboard; private const int defaultBeatcharSize = 12; @@ -179,10 +181,16 @@ public EditorTextbox() [BackgroundDependencyLoader] private void load(GameHost gameHost) { - textInput = gameHost.GetTextInput(); clipboard = gameHost.GetClipboard(); } + protected override void LoadComplete() + { + base.LoadComplete(); + + textInput.OnTextInput += text => insertString(text); + } + public int BeatcharSize { get; init; } = defaultBeatcharSize; public int MaxBeatcharsPerRow @@ -240,7 +248,7 @@ protected override void OnFocus(FocusEvent e) { base.OnFocus(e); - textInput?.Activate(); + textInput?.Activate(false); BorderThickness = 3; } @@ -330,10 +338,6 @@ protected override bool OnKeyDown(KeyDownEvent e) return true; } - var result = insertString(textInput?.GetPendingText()); - if (result) - return true; - return base.OnKeyDown(e); } diff --git a/hues.Game/ResourceStores/InMemoryResourceStore.cs b/hues.Game/ResourceStores/InMemoryResourceStore.cs index 11e1c6c..0097f0d 100644 --- a/hues.Game/ResourceStores/InMemoryResourceStore.cs +++ b/hues.Game/ResourceStores/InMemoryResourceStore.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using osu.Framework.IO.Stores; using osu.Framework.Logging; @@ -11,13 +12,13 @@ public class InMemoryResourceStore : IResourceStore protected readonly Dictionary store = new Dictionary(); protected readonly object storeLock = new object(); - public void Add(string name, Stream stream, long length) + public void Add(string name, Stream stream) { lock (storeLock) { - byte[] buffer = new byte[length]; - stream.Read(buffer); - store[name] = buffer; + var ms = new MemoryStream(); + stream.CopyTo(ms); + store[name] = ms.ToArray(); } } @@ -33,7 +34,8 @@ public byte[] Get(string name) } // TODO: Find out how C# async works and why this is cursed - public Task GetAsync(string name) => Task.Run(() => Get(name)); + public Task GetAsync(string name, CancellationToken cancellationToken = default) + => Task.Run(() => Get(name), cancellationToken); public Stream GetStream(string name) { diff --git a/hues.Game/RespackLoader.cs b/hues.Game/RespackLoader.cs index 89f6709..52670d2 100644 --- a/hues.Game/RespackLoader.cs +++ b/hues.Game/RespackLoader.cs @@ -94,7 +94,7 @@ private void addSongsToResourceStore(ZipArchive archive, IReadOnlyCollection public Track Get(string name) => backing.Get(name); - public Task GetAsync(string name) => backing.GetAsync(name); + public Task GetAsync(string name, CancellationToken cancellationToken = default) + => backing.GetAsync(name, cancellationToken); public Stream GetStream(string name) => backing.GetStream(name); public IEnumerable GetAvailableResources() => backing.GetAvailableResources(); #endregion diff --git a/hues.Game/hues.Game.csproj b/hues.Game/hues.Game.csproj index a95d81a..128ba6c 100644 --- a/hues.Game/hues.Game.csproj +++ b/hues.Game/hues.Game.csproj @@ -9,7 +9,7 @@ - +