Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

# The proxy builds against LibDmd.Core from dmd-extensions (referenced by path until it's
# published as a NuGet package). Check it out as a sibling and point LibDmdExtensionsRoot at it.
# NOTE: LibDmd.Core currently lives on the 'core' branch; update the ref once it merges.
# Pin the dmd-extensions source used to build the LibDmd.Core proxy.
- name: Checkout dmd-extensions
uses: actions/checkout@v4
with:
repository: freezy/dmd-extensions
ref: core
ref: 9387c66046a1390cd81170c4defe3710f59ec8cd
path: dmd-extensions

- uses: actions/setup-dotnet@v4
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ altcolor path is empty, it uses the `DMDDEVICE_CONFIG` folder's `altcolor` direc
VPM folder lookup. Serum is tried first, then VNI/PAL/PAC, with `[global] vni.key` and
`[global] vni.scalermode` honored.

### Shared table folders in the VPE Player

The Player plugin's Automatic mode checks beside the `.vpe` package before using the configured colorization library. It looks in `serum/<provider>/<game>/` for `<game>.cROMc` or `<game>.cRZ`, then in `vni/<provider>/<game>/` for `<game>.pal` or `pin2dmd.pal` with an optional same-stem `.vni`. Each also accepts a bare `<game>/` directory. For PinMAME games, `pinmame/altcolor/<game>/` beside the package is the final local fallback for these formats. Use the configured library for `.cROM`, `.fsq`, and `.pac` assets.

## License

This plugin is licensed under the GPL-2.0 license, matching DMD Extensions / LibDmd, which it builds
Expand Down
32 changes: 31 additions & 1 deletion Tests/Player/ColorizationCatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using NUnit.Framework;
using VisualPinball.Engine.DMD.Player;
using VisualPinball.Plugins;

namespace VisualPinball.Engine.DMD.Tests
{
Expand All @@ -20,7 +21,36 @@ public sealed class ColorizationCatalogTests
[TearDown] public void TearDown() { if (Directory.Exists(_root)) Directory.Delete(_root, true); }
private string Asset(string path)
{
string file = Path.Combine(_root, path); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, path); return file;
string file = Path.GetFullPath(Path.Combine(_root, path)); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, path); return file;
}
[Test]
public void AutomaticUsesEachTablesOwnMediaAndRetainsLibraryChoices()
{
var game = new GameIdentity("pinmame", "game");
string first = Asset("First/Release.vpe");
string second = Asset("Second/Release.vpe");
string scoped = Asset("First/Serum/PinMAME/GAME/GAME.cROMc");
Asset("First/Serum/game/game.crz");
string vni = Asset("Second/vni/game/game.pal");
string animation = Asset("Second/vni/game/game.VNI");
string global = Asset("Global/game/game.crz");
string library = Path.Combine(_root, "Global");

Assert.That(ColorizationCatalog.Select(library, first, game, "auto", false).Files, Is.EqualTo(new[] { scoped }));
Assert.That(ColorizationCatalog.Select(library, second, game, "auto", false).Files, Is.EqualTo(new[] { vni, animation }));
Assert.That(ColorizationCatalog.Select(library, first, game, "game/game.crz", false).Files, Is.EqualTo(new[] { global }));
Assert.That(ColorizationCatalog.Select(library, second, game, "none", false), Is.Null);
File.Delete(vni);
Assert.That(ColorizationCatalog.Select(library, second, game, "auto", false).Files, Is.EqualTo(new[] { global }));
}

[Test]
public void LegacyAltcolorIsPinMameOnly()
{
string table = Asset("Table/Release.vpe");
string legacy = Asset("Table/pinmame/altcolor/game/PIN2DMD.PAL");
Assert.That(ColorizationCatalog.FindTableAsset(table, new GameIdentity("pinmame", "game")).Files, Is.EqualTo(new[] { legacy }));
Assert.That(ColorizationCatalog.FindTableAsset(table, new GameIdentity("another-controller", "game")), Is.Null);
}
[Test]
public void VariantsHaveStableIdsAndKeepPaletteAnimationsTogether()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ internal static IReadOnlyList<ColorizationAsset> Read(string root, string game)
private static bool InGameFolder(ColorizationAsset asset, string game) => asset.Id.StartsWith(game + "/", StringComparison.OrdinalIgnoreCase) && asset.Id.IndexOf('/', game.Length + 1) < 0;
private static bool IsSerum(string file) => Path.GetExtension(file).ToLowerInvariant() is ".crz" or ".crom" or ".cromc";
private static string Relative(string root, string file) => Path.GetRelativePath(root, file).Replace('\\', '/');

internal static ColorizationAsset FindTableAsset(string packagePath, GameIdentity game)
{
string table = Path.GetDirectoryName(packagePath);
foreach (string folder in TableMediaPaths.GameDirectories(TableMediaPaths.FindDirectory(table, "serum"), game)) {
var asset = FindSerum(folder, game.Key);
if (asset != null) return asset;
}
foreach (string folder in TableMediaPaths.GameDirectories(TableMediaPaths.FindDirectory(table, "vni"), game)) {
var asset = FindVni(folder, game.Key);
if (asset != null) return asset;
}
if (game.Provider != "pinmame") return null;
string legacy = TableMediaPaths.FindDirectory(table, "pinmame", "altcolor", game.Key);
return legacy == null ? null : FindSerum(legacy, game.Key) ?? FindVni(legacy, game.Key);
}

private static ColorizationAsset FindSerum(string folder, string game)
{
string file = TableMediaPaths.FindFile(folder, game + ".cROMc") ?? TableMediaPaths.FindFile(folder, game + ".cRZ");
return file == null ? null : new ColorizationAsset(game + "/" + Path.GetFileName(file), Path.GetFileNameWithoutExtension(file) + " · Serum", file);
}

private static ColorizationAsset FindVni(string folder, string game)
{
string palette = TableMediaPaths.FindFile(folder, game + ".pal") ?? TableMediaPaths.FindFile(folder, "pin2dmd.pal");
if (palette == null) return null;
string stem = Path.GetFileNameWithoutExtension(palette);
string animation = TableMediaPaths.FindFile(folder, stem + ".vni");
return new ColorizationAsset(game + "/" + Path.GetFileName(palette), stem + (animation == null ? " · Palette" : " · VNI/PAL"),
animation == null ? new[] { palette } : new[] { palette, animation });
}

internal static ColorizationAsset Select(string root, string packagePath, GameIdentity game, string selection, bool hasPacKey)
=> (selection == "auto" ? FindTableAsset(packagePath, game) : null) ?? Select(root, game.Key, selection, hasPacKey);

/// <param name="hasPacKey">Whether a PAC key is configured. Without one, automatic selection skips PAC files and doesn't fall
/// back to pin2dmd.pal next to a PAC, since DmdDevice fails to load such a folder and shows the uncolorized frames.</param>
internal static ColorizationAsset Select(string root, string game, string selection, bool hasPacKey = false)
Expand Down
5 changes: 3 additions & 2 deletions VisualPinball.Engine.DMD.Unity/Runtime/Plugins/DmdPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public override Task PrepareGameAsync(PluginGameContext game, CancellationToken
settings.RomName = game.Identity.Key;
_gameSettings = effective;
_colorizationLibrary = DmdPluginFactory.Library(effective, game.Identity.Key);
var asset = ColorizationCatalog.Select(_colorizationLibrary, game.Identity.Key, effective.String("Colorization", "auto"), effective.String("VniKey").Length > 0);
var asset = ColorizationCatalog.Select(_colorizationLibrary, game.PackagePath, game.Identity,
effective.String("Colorization", "auto"), effective.String("VniKey").Length > 0);
settings.EnableColorization = asset != null;
_asset = asset; _settings = settings;
_noColorizationReason = asset != null ? null : NoColorizationReason(game.Identity.Key, effective);
Expand All @@ -60,7 +61,7 @@ public override Task PrepareGameAsync(PluginGameContext game, CancellationToken
settings.AltColorPath = staged;
_stagedColorization = staged;
}
_application.Logger.Info($"Colorization for {game.Identity.Key}: {_colorizationAsset}, library {(_colorizationLibrary.Length > 0 ? _colorizationLibrary : "not found")}.");
_application.Logger.Info($"Colorization for {game.Identity.Key}: {_colorizationAsset}, source {asset?.Files[0] ?? _colorizationLibrary}.");
ConfigureCabinetOutputs(game, effective, settings);
_root = new GameObject("DMD plugin"); _root.SetActive(false); _root.transform.SetParent(scene.Table.transform, false);
game.Lifetime.Own(new Subscription(() => { if (_root != null) UnityEngine.Object.Destroy(_root); }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ private PluginChoiceCatalog Discover(string provider, PluginChoiceRequest reques
var choices = new List<PluginChoice>();
switch (provider) {
case "colorizations":
choices.Add(new PluginChoice("auto", "Automatic", "Uses the sole available colorization, or what DmdDevice loads from the game folder: Serum first, then the newest .pac, which needs a PAC key (without one, no colorization), then pin2dmd.pal and .vni. Otherwise select one.")); choices.Add(new PluginChoice("none", "No colorization"));
var local = request.Game.HasValue ? ColorizationCatalog.FindTableAsset(request.Package?.Path, request.Game.Value) : null;
choices.Add(new PluginChoice("auto", "Automatic", local != null
? "Uses " + local.Label + " from the table folder."
: "Looks beside the table first, then uses what DmdDevice would load from the library. Select a library entry to override Automatic."));
choices.Add(new PluginChoice("none", "No colorization"));
foreach (var asset in ColorizationCatalog.Read(Library(request.Settings, request.Game?.Key), request.Game?.Key ?? "")) choices.Add(new PluginChoice(asset.Id, asset.Label, available: !asset.RequiresKey || PacKey(request.Settings).Length > 0, unavailableReason: "A PAC key is required."));
break;
case "scalers": foreach (string name in Enum.GetNames(typeof(ScalerMode))) choices.Add(new PluginChoice(name, name)); break;
Expand Down Expand Up @@ -145,7 +149,8 @@ public IReadOnlyList<PluginValidationIssue> Validate(PluginChoiceRequest request
foreach (string field in new[] { "UnlitDot", "GlassColor" }) if (!ColorUtility.TryParseHtmlString(request.Settings.String(field), out _)) issues.Add(new PluginValidationIssue(field, "Enter a color such as #FFAA00."));
if (request.Game.HasValue) try {
bool hasKey = PacKey(request.Settings).Length > 0;
var asset = ColorizationCatalog.Select(Library(request.Settings, request.Game.Value.Key), request.Game.Value.Key, request.Settings.String("Colorization", "auto"), hasKey);
var asset = ColorizationCatalog.Select(Library(request.Settings, request.Game.Value.Key), request.Package?.Path,
request.Game.Value, request.Settings.String("Colorization", "auto"), hasKey);
if (asset?.RequiresKey == true && !hasKey) issues.Add(new PluginValidationIssue("VniKey", "A PAC key is required."));
} catch (Exception error) { issues.Add(new PluginValidationIssue("Colorization", error.Message)); }
return issues;
Expand Down
2 changes: 1 addition & 1 deletion VisualPinball.Engine.DMD.Unity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"unity": "6000.5",
"unityRelease": "0f1",
"dependencies": {
"org.visualpinball.engine.unity": "0.0.1-preview.212"
"org.visualpinball.engine.unity": "0.0.1-preview.238"
},
"author": "freezy <freezy@vpdb.io>",
"documentationUrl": "https://docs.visualpinball.org/",
Expand Down
Loading