Add EveUnity TeX projection shells
This commit is contained in:
parent
0ae4970885
commit
ebd44028a5
19 changed files with 304 additions and 61 deletions
|
|
@ -19,7 +19,8 @@ namespace GameCult.Eve.UnityUIToolkit
|
|||
PluginProjectionAdapters = pluginProjectionAdapters ?? new IEveUiToolkitPluginProjectionAdapter[]
|
||||
{
|
||||
new SaiVisualNovelUiToolkitProjectionAdapter(),
|
||||
new NornGraphUiToolkitProjectionAdapter()
|
||||
new NornGraphUiToolkitProjectionAdapter(),
|
||||
new TeXMathUiToolkitProjectionAdapter()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Eve.Surface;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Eve.UnityUIToolkit
|
||||
{
|
||||
public sealed class TeXMathUiToolkitProjectionAdapter : IEveUiToolkitPluginProjectionAdapter
|
||||
{
|
||||
public string PluginId => "tex.math";
|
||||
|
||||
public IReadOnlyList<string> Capabilities { get; } = new[]
|
||||
{
|
||||
"embed.tex",
|
||||
"tex.inline",
|
||||
"tex.block"
|
||||
};
|
||||
|
||||
public bool CanLower(EveSurfaceComponent component)
|
||||
{
|
||||
return string.Equals(component.Kind, "embed.tex", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public VisualElement Lower(
|
||||
EveSurfaceComponent component,
|
||||
EveSurfaceDocument document,
|
||||
Action<EveSurfaceCommandRequest>? commandSink)
|
||||
{
|
||||
var tex = new VisualElement();
|
||||
tex.AddToClassList("eve-plugin-projection");
|
||||
tex.AddToClassList("eve-plugin-tex-math");
|
||||
tex.AddToClassList("tex-math");
|
||||
tex.AddToClassList($"tex-display-{SafeClass(component.GetProp("display", "inline"))}");
|
||||
tex.style.flexDirection = FlexDirection.Column;
|
||||
|
||||
var label = component.GetProp("label", "TeX");
|
||||
if (!string.IsNullOrWhiteSpace(label))
|
||||
{
|
||||
var labelElement = new Label(label);
|
||||
labelElement.AddToClassList("tex-math-label");
|
||||
tex.Add(labelElement);
|
||||
}
|
||||
|
||||
var source = component.GetProp("source", component.GetProp("sourceUri", ""));
|
||||
var sourceElement = new Label(source);
|
||||
sourceElement.AddToClassList("tex-math-source-fallback");
|
||||
tex.Add(sourceElement);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
private static string SafeClass(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "unknown";
|
||||
|
||||
var characters = value.ToCharArray();
|
||||
for (var index = 0; index < characters.Length; index++)
|
||||
{
|
||||
if (!char.IsLetterOrDigit(characters[index]))
|
||||
characters[index] = '-';
|
||||
}
|
||||
|
||||
return new string(characters).Trim('-').ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,12 +12,13 @@ namespace GameCult.Eve.UnityUIToolkit.Tests
|
|||
public sealed class EveUiToolkitSurfaceLowererTests
|
||||
{
|
||||
[Test]
|
||||
public void DefaultOptionsExposeSaiAndNornProjectionAdapters()
|
||||
public void DefaultOptionsExposeSaiNornAndTeXProjectionAdapters()
|
||||
{
|
||||
var options = EveUiToolkitSurfaceOptions.Default;
|
||||
|
||||
Assert.That(options.FindPluginProjectionAdapter(Component("stage", "vn.stage"))?.PluginId, Is.EqualTo("sai.vn"));
|
||||
Assert.That(options.FindPluginProjectionAdapter(Component("graph", "embed.norn"))?.PluginId, Is.EqualTo("norn.graph"));
|
||||
Assert.That(options.FindPluginProjectionAdapter(Component("math", "embed.tex"))?.PluginId, Is.EqualTo("tex.math"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
@ -58,6 +59,27 @@ namespace GameCult.Eve.UnityUIToolkit.Tests
|
|||
Assert.That(root.ClassListContains("norn-graph"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TeXMathLowersThroughRuntimeProjectionAdapterAsSourceFallback()
|
||||
{
|
||||
var document = Document(Component(
|
||||
"math",
|
||||
"embed.tex",
|
||||
new Dictionary<string, string>
|
||||
{
|
||||
["label"] = "Bifrost voting weight",
|
||||
["source"] = "\\\\mathrm{votes}(p)=1+\\\\lfloor\\\\log_b(1+p)\\\\rfloor",
|
||||
["display"] = "block"
|
||||
}));
|
||||
|
||||
var root = new EveUiToolkitSurfaceLowerer().Lower(document);
|
||||
|
||||
Assert.That(root.ClassListContains("eve-plugin-projection"), Is.True);
|
||||
Assert.That(root.ClassListContains("eve-plugin-tex-math"), Is.True);
|
||||
Assert.That(root.ClassListContains("tex-math"), Is.True);
|
||||
Assert.That(root.ClassListContains("tex-display-block"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmbeddedDocumentSlotMountsResolverBackedChildSurface()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,14 +33,18 @@
|
|||
"embed.norn"
|
||||
],
|
||||
"projectionAdapter": "NornGraphUiToolkitProjectionAdapter"
|
||||
}
|
||||
],
|
||||
"unsupportedPlugins": [
|
||||
},
|
||||
{
|
||||
"pluginId": "tex.math",
|
||||
"reason": "Unity UI Toolkit currently preserves embed.tex as generic Eve structure; no adapter exists for the TeX sidecar-advertised projection in this runtime."
|
||||
"capabilities": [
|
||||
"embed.tex",
|
||||
"tex.inline",
|
||||
"tex.block"
|
||||
],
|
||||
"projectionAdapter": "TeXMathUiToolkitProjectionAdapter"
|
||||
}
|
||||
],
|
||||
"unsupportedPlugins": [],
|
||||
"commandTransport": {
|
||||
"schema": "gamecult.eve.command.v1",
|
||||
"emitter": "EveUiToolkitSurfaceLowerer.EmitCommand",
|
||||
|
|
@ -55,6 +59,7 @@
|
|||
"ownership": "runtime-lowers-provider-world-surface-without-owning-world-state",
|
||||
"evidencePaths": [
|
||||
"packages/org.gamecult.eve.unity-uitoolkit/Runtime/EveUiToolkitSurfaceLowerer.cs",
|
||||
"packages/org.gamecult.eve.unity-uitoolkit/Runtime/TeXMathUiToolkitProjectionAdapter.cs",
|
||||
"packages/org.gamecult.eve.unity-uitoolkit/Tests/Editor/EveUiToolkitSurfaceLowererTests.cs",
|
||||
"web/fixtures/aetheria.provider-advertisement.json"
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue