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
11 changes: 11 additions & 0 deletions VisualPinball.Plugins.Test/CabinetDisplayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public void DuplicateAssignmentsAndInvalidAvailableDestinationsAreRejected()
Assert.That(new CabinetDisplaySnapshot(1, 1, 1, new[] { target, second }, Array.Empty<CabinetOutputAssignment>()).TargetsFor(CabinetOutputRole.Dmd).Count, Is.EqualTo(2));
}

[Test]
public void ContentOfADestinationTurnedByAQuarterIsAsWideAsTheDestinationIsHigh()
{
var upright = new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 300, height: 1200, rotation: 1);
Assert.That((upright.ContentWidth, upright.ContentHeight), Is.EqualTo((1200, 300)));
var turnedOver = new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 300, height: 1200, rotation: 2);
Assert.That((turnedOver.ContentWidth, turnedOver.ContentHeight), Is.EqualTo((300, 1200)));
Assert.That(new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 128, height: 32).Rotation, Is.EqualTo(0));
Assert.Throws<ArgumentOutOfRangeException>(() => new CabinetDisplayTarget("screen", CabinetOutputRole.Dmd, CabinetEndpointState.Available, width: 128, height: 32, rotation: 4));
}

[Test]
public void RankingFallsBackOnlyWhenIneligibleAndIsIndependentOfPublicationOrder()
{
Expand Down
14 changes: 12 additions & 2 deletions VisualPinball.Plugins/Api/CabinetDisplays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,26 @@ public sealed class CabinetDisplayTarget
public int Y { get; }
public int Width { get; }
public int Height { get; }
/// <summary>
/// Clockwise quarter turns, 0 to 3, by which the Player turns what it shows here. A producer that lays out its
/// picture for this destination sizes it by <see cref="ContentWidth"/> and <see cref="ContentHeight"/>.
/// </summary>
public int Rotation { get; }
/// <summary>The width of a picture that fills this destination: its height when the content is turned by a quarter.</summary>
public int ContentWidth => (Rotation & 1) != 0 ? Height : Width;
/// <summary>The height of a picture that fills this destination: its width when the content is turned by a quarter.</summary>
public int ContentHeight => (Rotation & 1) != 0 ? Width : Height;

public CabinetDisplayTarget(string endpointId, CabinetOutputRole role, CabinetEndpointState state,
int x = 0, int y = 0, int width = 0, int height = 0, string reason = "")
int x = 0, int y = 0, int width = 0, int height = 0, string reason = "", int rotation = 0)
{
if (string.IsNullOrWhiteSpace(endpointId)) throw new ArgumentException("An endpoint needs an ID.", nameof(endpointId));
if (!CabinetOutputRoles.IsDefined(role)) throw new ArgumentException("An output needs a role.", nameof(role));
if (!Enum.IsDefined(typeof(CabinetEndpointState), state)) throw new ArgumentOutOfRangeException(nameof(state));
if (state == CabinetEndpointState.Available && (width < 1 || height < 1)) throw new ArgumentOutOfRangeException(nameof(width));
if (rotation < 0 || rotation > 3) throw new ArgumentOutOfRangeException(nameof(rotation));
EndpointId = endpointId; Role = role; State = state;
X = x; Y = y; Width = width; Height = height; Reason = reason ?? "";
X = x; Y = y; Width = width; Height = height; Reason = reason ?? ""; Rotation = rotation;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public IEnumerator RuntimePackagePreservesFourBanksAndSharedAndNullReferences()
var input = child.AddComponent<InputActionSoundComponent>();
input.ActionName = "Start Game";
input.SoundAsset = second;
input.StartWhen = StartWhen.TurnedOff;
new PackageWriter(source).WritePackageSync(package);
var task = new RuntimePackageReader(package).ImportIntoScene();
while (!task.IsCompleted)
Expand All @@ -97,6 +98,7 @@ public IEnumerator RuntimePackagePreservesFourBanksAndSharedAndNullReferences()
var restoredInput = imported.GetComponentInChildren<InputActionSoundComponent>(true);
Assert.That(restoredInput.ActionName, Is.EqualTo("Start Game"));
Assert.That(restoredInput.SoundAsset, Is.SameAs(restored.Up));
Assert.That(restoredInput.StartWhen, Is.EqualTo(StartWhen.TurnedOff));
}
finally {
if (imported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public void UnpackReferences(byte[] data, Transform root, PackagedRefs refs, Pac

private bool _isRotatingDown => Direction == ScoreReelDirection.Down;

/// <summary>
/// Where the reel is now, in digits, from 0 up to but not including 10: 0 shows the zero, 9 the nine, and a
/// value in between means the reel is on its way to the next digit. After the nine it starts again at 0. It
/// counts up the same way for both values of <see cref="Direction"/>, which only says whether the next digit
/// comes from above or from below. Follows the animation, so a flat drawing of the reel can move with it.
/// </summary>
public float DigitPosition => _currentRotation / 36f;

public void AnimateTo(int position)
{
var increasePositions = (position - _endPosition + 10) % 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static class VpePackageSchemas
/// The version of the items schema this build writes. It goes up by one with every change to the schema that
/// a reader has to know about, with a line added to <see cref="ItemsChanges"/>.
/// </summary>
public const int ItemsVersion = 5;
public const int ItemsVersion = 6;

/// <summary>
/// The oldest items schema version a reader must implement to load what this build writes, stored in the manifest
Expand Down Expand Up @@ -99,6 +99,7 @@ public static class VpePackageSchemas
"the names in a table's files were made consistent, and tables from before would lose the settings stored under the old names",
"the settings of a table's objects moved from thousands of small files into one, and tables from before have them where this build no longer looks",
"the objects of a prefab instance say which of the prefab's objects they are, so the editor links them to the prefab again even when they were renamed",
"input action sounds can play when the button is released, which older players play on the press instead",
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace VisualPinball.Unity
public class InputActionSoundComponent : SoundComponent, IPackable
{
public string ActionName;
[Tooltip("Whether the sound plays when the button is pressed or when it is released.")]
public StartWhen StartWhen = StartWhen.TurnedOn;
private Player _player;
private bool _pressed;
public override bool SupportsLoopingSoundAssets() => false;
Expand All @@ -38,7 +40,7 @@ private void OnInput(string action, bool pressed) {
if (InputManager.GetCanonicalActionName(ActionName) != action || _pressed == pressed)
return;
_pressed = pressed;
if (pressed)
if (pressed == (StartWhen == StartWhen.TurnedOn))
StartSound();
}
protected override void OnDisable() {
Expand All @@ -51,17 +53,20 @@ protected override void OnDisable() {
public new byte[] Pack() => PackageApi.Packer.Pack(new InputActionSoundPackable
{
Sound = base.Pack(),
ActionName = ActionName
ActionName = ActionName,
StartWhen = StartWhen
});
public new void Unpack(byte[] bytes) {
var p = PackageApi.Packer.Unpack<InputActionSoundPackable>(bytes);
base.Unpack(p.Sound);
ActionName = p.ActionName;
StartWhen = p.StartWhen;
}
}
public struct InputActionSoundPackable
{
public byte[] Sound;
public string ActionName;
public StartWhen StartWhen;
}
}
Loading