Skip to content

Commit

Permalink
Update framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jai-x committed Mar 17, 2022
1 parent 6cedcf2 commit ffb9e94
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand Down
4 changes: 2 additions & 2 deletions hues.Game.Tests/NonVisual/TestSongPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
2 changes: 1 addition & 1 deletion hues.Game.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 11 additions & 7 deletions hues.Game/Drawables/Editor/EditorTextbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -240,7 +248,7 @@ protected override void OnFocus(FocusEvent e)
{
base.OnFocus(e);

textInput?.Activate();
textInput?.Activate(false);
BorderThickness = 3;
}

Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 7 additions & 5 deletions hues.Game/ResourceStores/InMemoryResourceStore.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,13 +12,13 @@ public class InMemoryResourceStore : IResourceStore<byte[]>
protected readonly Dictionary<string, byte[]> store = new Dictionary<string, byte[]>();
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();
}
}

Expand All @@ -33,7 +34,8 @@ public byte[] Get(string name)
}

// TODO: Find out how C# async works and why this is cursed
public Task<byte[]> GetAsync(string name) => Task.Run(() => Get(name));
public Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
=> Task.Run(() => Get(name), cancellationToken);

public Stream GetStream(string name)
{
Expand Down
7 changes: 3 additions & 4 deletions hues.Game/RespackLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void addSongsToResourceStore(ZipArchive archive, IReadOnlyCollection<Son
throw new RespackMissingFileException(song.LoopSource);

using (var stream = loopEntry.Open())
trackResources.Add(song.LoopSource, stream, loopEntry.Length);
trackResources.Add(song.LoopSource, stream);

if (String.IsNullOrEmpty(song.BuildupSource))
continue;
Expand All @@ -105,7 +105,7 @@ private void addSongsToResourceStore(ZipArchive archive, IReadOnlyCollection<Son
throw new RespackMissingFileException(song.BuildupSource);

using (var stream = buildupEntry.Open())
trackResources.Add(song.BuildupSource, stream, loopEntry.Length);
trackResources.Add(song.BuildupSource, stream);
}
}

Expand All @@ -119,8 +119,7 @@ private void addImagesToResourceStore(ZipArchive archive, IReadOnlyCollection<Im
throw new RespackMissingFileException(image.TexturePath);

using (var stream = imageEntry.Open())
textureResources.Add(image.TexturePath, stream, imageEntry.Length);

textureResources.Add(image.TexturePath, stream);
}
}

Expand Down
4 changes: 3 additions & 1 deletion hues.Game/Stores/RespackTrackStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
Expand All @@ -24,7 +25,8 @@ public RespackTrackStore(ITrackStore backing)

#region IResourceStore<Track>
public Track Get(string name) => backing.Get(name);
public Task<Track> GetAsync(string name) => backing.GetAsync(name);
public Task<Track> GetAsync(string name, CancellationToken cancellationToken = default)
=> backing.GetAsync(name, cancellationToken);
public Stream GetStream(string name) => backing.GetStream(name);
public IEnumerable<string> GetAvailableResources() => backing.GetAvailableResources();
#endregion
Expand Down
2 changes: 1 addition & 1 deletion hues.Game/hues.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ppy.osu.Framework" Version="2021.1111.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.314.0" />
</ItemGroup>

<Target Name="PostClean" AfterTargets="Clean">
Expand Down

0 comments on commit ffb9e94

Please sign in to comment.