Skip to content

Commit

Permalink
Merge pull request #1504 from andy840119/update-package
Browse files Browse the repository at this point in the history
Update package to the latest.
  • Loading branch information
andy840119 authored Aug 10, 2022
2 parents d3f8cf1 + 327d9f3 commit bf629ba
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 54 deletions.
14 changes: 11 additions & 3 deletions osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using NUnit.Framework;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Dummy;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Database;
Expand Down Expand Up @@ -44,19 +46,25 @@ public static string GetTestLrcForImport(string name)

public static IStorageResourceProvider CreateSkinStorageResourceProvider(string skinName = "special-skin") => new TestStorageResourceProvider(skinName);

#nullable disable

private class TestStorageResourceProvider : IStorageResourceProvider
{
public TestStorageResourceProvider(string skinName)
{
Files = Resources = new NamespacedResourceStore<byte[]>(new DllResourceStore(GetType().Assembly), $"Resources/{skinName}");
}

public IResourceStore<TextureUpload>? CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
public IRenderer Renderer => new DummyRenderer();

public AudioManager? AudioManager => null;
public AudioManager AudioManager => null;
public IResourceStore<byte[]> Files { get; }
public IResourceStore<byte[]> Resources { get; }
public RealmAccess? RealmAccess => null;
public RealmAccess RealmAccess => null;

public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
}

#nullable enable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public TestManageFontPreview()
private void load(GameHost host)
{
var resources = new KaraokeRuleset().CreateResourceStore();
var textureStore = new TextureStore(host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
var textureStore = new TextureStore(host.Renderer, host.CreateTextureLoaderStore(new NamespacedResourceStore<byte[]>(resources, @"Textures")));
Dependencies.CacheAs(textureStore);

Add(new ManageFontPreview
Expand Down
35 changes: 23 additions & 12 deletions osu.Game.Rulesets.Karaoke/Graphics/Shapes/RightTriangle.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.OpenGL;
using osu.Framework.Graphics.OpenGL.Vertices;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;

namespace osu.Game.Rulesets.Karaoke.Graphics.Shapes
Expand All @@ -21,7 +18,15 @@ public class RightTriangle : Sprite
/// </summary>
public RightTriangle()
{
Texture = Texture.WhitePixel;
// Setting the texture would normally set a size of (1, 1), but since the texture is set from BDL it needs to be set here instead.
// RelativeSizeAxes may not behave as expected if this is not done.
Size = Vector2.One;
}

[BackgroundDependencyLoader]
private void load(IRenderer renderer)
{
Texture ??= renderer.WhitePixel;
}

public override RectangleF BoundingBox => toTriangle(ToParentSpace(LayoutRectangle), RightAngleDirection).AABBFloat;
Expand Down Expand Up @@ -70,20 +75,26 @@ public override void ApplyState()
rightAngleDirection = Source.RightAngleDirection;
}

protected override void Blit(Action<TexturedVertex2D> vertexAction)
protected override void Blit(IRenderer renderer)
{
DrawTriangle(Texture, toTriangle(ScreenSpaceDrawQuad, rightAngleDirection), DrawColourInfo.Colour, null, null,
if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0)
return;

renderer.DrawTriangle(Texture, toTriangle(ScreenSpaceDrawQuad, rightAngleDirection), DrawColourInfo.Colour, null, null,
new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height), TextureCoords);
}

protected override void BlitOpaqueInterior(Action<TexturedVertex2D> vertexAction)
protected override void BlitOpaqueInterior(IRenderer renderer)
{
if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0)
return;

var triangle = toTriangle(ConservativeScreenSpaceDrawQuad, rightAngleDirection);

if (GLWrapper.IsMaskingActive)
DrawClipped(ref triangle, Texture, DrawColourInfo.Colour, vertexAction: vertexAction);
if (renderer.IsMaskingActive)
renderer.DrawClipped(ref triangle, Texture, DrawColourInfo.Colour);
else
DrawTriangle(Texture, triangle, DrawColourInfo.Colour, vertexAction: vertexAction);
renderer.DrawTriangle(Texture, triangle, DrawColourInfo.Colour);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.IO.Stores;
Expand Down Expand Up @@ -198,12 +199,12 @@ public FontSelector()
}

[BackgroundDependencyLoader]
private void load(FontManager fontManager)
private void load(FontManager fontManager, IRenderer renderer)
{
fonts.BindTo(fontManager.Fonts);

// create local font store and import those files
localFontStore = new KaraokeLocalFontStore(fontManager);
localFontStore = new KaraokeLocalFontStore(fontManager, renderer);
fontStore.AddStore(localFontStore);

Current.BindValueChanged(e =>
Expand Down
8 changes: 4 additions & 4 deletions osu.Game.Rulesets.Karaoke/IO/Stores/KaraokeLocalFontStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#nullable disable

using System.Collections.Generic;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
Expand All @@ -15,19 +16,18 @@ namespace osu.Game.Rulesets.Karaoke.IO.Stores
public class KaraokeLocalFontStore : FontStore
{
private readonly Dictionary<FontInfo, IResourceStore<TextureUpload>> fontInfos = new();
private readonly IResourceStore<TextureUpload> store;
private readonly FontManager fontManager;

/// <summary>
/// Construct a font store to be added to a parent font store via <see cref="AddFont"/>.
/// </summary>
/// <param name="fontManager">font manager.</param>
/// <param name="renderer">The renderer to create textures with.</param>
/// <param name="store">The texture source.</param>
/// <param name="scaleAdjust">The raw pixel height of the font. Can be used to apply a global scale or metric to font usages.</param>
public KaraokeLocalFontStore(FontManager fontManager, IResourceStore<TextureUpload> store = null, float scaleAdjust = 100)
: base(store, scaleAdjust)
public KaraokeLocalFontStore(FontManager fontManager, IRenderer renderer, IResourceStore<TextureUpload> store = null, float scaleAdjust = 100)
: base(renderer, store, scaleAdjust)
{
this.store = store;
this.fontManager = fontManager;
}

Expand Down
57 changes: 36 additions & 21 deletions osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Bindings;
Expand Down Expand Up @@ -158,27 +160,7 @@ public override IEnumerable<Mod> GetModsFor(ModType type) =>
_ => Array.Empty<Mod>()
};

public override Drawable CreateIcon() => new Container
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.9f),
Texture = new TextureStore(new TextureLoaderStore(CreateResourceStore()), false).Get("Textures/logo"),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(45f),
Icon = FontAwesome.Regular.Circle,
},
}
};
public override Drawable CreateIcon() => new KaraokeIcon(this);

public override IResourceStore<byte[]> CreateResourceStore()
{
Expand Down Expand Up @@ -312,5 +294,38 @@ public KaraokeRuleset()
// it's a tricky way for loading customized karaoke beatmap.
RulesetInfo.OnlineID = 111;
}

private class KaraokeIcon : CompositeDrawable
{
private readonly KaraokeRuleset ruleset;

public KaraokeIcon(KaraokeRuleset ruleset)
{
this.ruleset = ruleset;
AutoSizeAxes = Axes.Both;
}

[BackgroundDependencyLoader]
private void load(IRenderer renderer)
{
InternalChildren = new Drawable[]
{
new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.9f),
Texture = new TextureStore(renderer, new TextureLoaderStore(ruleset.CreateResourceStore()), false).Get("Textures/logo"),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(45f),
Icon = FontAwesome.Regular.Circle,
},
};
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
using osu.Framework.IO.Stores;
using osu.Game.Rulesets.Karaoke.Configuration;
Expand Down Expand Up @@ -74,10 +75,10 @@ void addFont(FontUsage fontUsage)
}

[BackgroundDependencyLoader]
private void load(FontManager fontManager, KaraokeRulesetConfigManager config)
private void load(FontManager fontManager, IRenderer renderer, KaraokeRulesetConfigManager config)
{
// create local font store and import those files
localFontStore = new KaraokeLocalFontStore(fontManager);
localFontStore = new KaraokeLocalFontStore(fontManager, renderer);
fontStore.AddStore(localFontStore);

// fonts
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected JsonSerializerSettings CreateJsonSerializerSettings(params JsonConvert
}

public override ISample? GetSample(ISampleInfo sampleInfo)
=> sampleInfo.LookupNames.Select(lookup => resources?.AudioManager.Samples.Get(lookup)).FirstOrDefault(sample => sample != null);
=> sampleInfo.LookupNames.Select(lookup => resources?.AudioManager?.Samples.Get(lookup)).FirstOrDefault(sample => sample != null);

public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
=> null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Dummy;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Beatmaps;
Expand Down Expand Up @@ -101,6 +103,8 @@ public TempLegacySkin(SkinInfo skin)
}
}

#nullable disable

private class InternalSkinStorageResourceProvider : IStorageResourceProvider
{
public InternalSkinStorageResourceProvider(string skinName)
Expand All @@ -109,12 +113,15 @@ public InternalSkinStorageResourceProvider(string skinName)
Files = Resources = new NamespacedResourceStore<byte[]>(store, $"Skin/{skinName}");
}

public IResourceStore<TextureUpload>? CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
public IRenderer Renderer => new DummyRenderer();

public AudioManager? AudioManager => null;
public AudioManager AudioManager => null;
public IResourceStore<byte[]> Files { get; }
public IResourceStore<byte[]> Resources { get; }
public RealmAccess? RealmAccess => null;
public RealmAccess RealmAccess => null;
public IResourceStore<TextureUpload> CreateTextureLoaderStore(IResourceStore<byte[]> underlyingStore) => null;
}

#nullable enable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Sprites;
using osu.Framework.IO.Stores;
using osu.Game.Rulesets.Karaoke.Configuration;
Expand All @@ -26,7 +27,7 @@ public class KaraokePlayfieldAdjustmentContainer : PlayfieldAdjustmentContainer
private KaraokeLocalFontStore localFontStore;

[BackgroundDependencyLoader]
private void load(FontManager fontManager, KaraokeRulesetConfigManager manager)
private void load( FontManager fontManager, IRenderer renderer, KaraokeRulesetConfigManager manager)
{
// get all font usage which wants to import.
var targetImportFonts = new[]
Expand All @@ -46,7 +47,7 @@ private void load(FontManager fontManager, KaraokeRulesetConfigManager manager)
return;

// create local font store and import those files
localFontStore = new KaraokeLocalFontStore(fontManager);
localFontStore = new KaraokeLocalFontStore(fontManager, renderer);
fontStore.AddStore(localFontStore);

foreach (var fontInfo in fontInfos)
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
<PackageReference Include="LanguageDetection.karaoke-dev" Version="1.3.3-alpha" />
<PackageReference Include="LrcParser" Version="2022.529.1" />
<PackageReference Include="Octokit" Version="1.0.0" />
<PackageReference Include="osu.Framework.KaraokeFont" Version="2022.716.0" />
<PackageReference Include="osu.Framework.Microphone" Version="2022.718.0" />
<PackageReference Include="osu.Framework.KaraokeFont" Version="2022.806.0" />
<PackageReference Include="osu.Framework.Microphone" Version="2022.806.0" />
<PackageReference Include="ppy.LocalisationAnalyser" Version="2022.607.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ppy.osu.Game" Version="2022.730.0" />
<PackageReference Include="ppy.osu.Game" Version="2022.810.0" />
<PackageReference Include="Lucene.Net" Version="4.8.0-beta00016" />
<PackageReference Include="Lucene.Net.Analysis.Kuromoji" Version="4.8.0-beta00016" />
<PackageReference Include="NicoKaraParser" Version="1.1.0" />
Expand Down

0 comments on commit bf629ba

Please sign in to comment.