Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f1d7094
lamps: Add types.
freezy Jan 10, 2021
c17f4d6
All the boilerplate required for the Lamp Manager. Mostly copied from…
ecurtz Nov 21, 2020
598d1bb
lamps: Wire them up!
freezy Jan 9, 2021
4fd6238
lamps: Add RGB output (untested).
freezy Jan 11, 2021
18bba6b
lamps: Fix RGB output, add multi-lamp API and unit tests.
freezy Jan 12, 2021
949f422
lamps: Add some documentation.
freezy Jan 13, 2021
c2324da
lamps: Add lamp destination to coils.
freezy Jan 14, 2021
4f6c70f
lamps: Update coil ID when coil lamp ID is updated.
freezy Jan 14, 2021
d225cb2
lamps: Handle coil lamps during runtime.
freezy Jan 14, 2021
8d0efa9
player: Move coil-, switch-, lamp-, and wire handling into separate c…
freezy Jan 17, 2021
3587aad
player: Fix calling order.
freezy Jan 17, 2021
2fcca2a
player: Better error logging when assiging coils, lamps, switches and…
freezy Jan 17, 2021
8f5e80a
gle: Make default gamelogic engine a component.
freezy Jan 17, 2021
bffeb76
lamps: Fix intensity.
freezy Jan 17, 2021
040f31f
lamp: Fix coil hook-up.
freezy Jan 17, 2021
24268a8
coils: Remove lamp entry when removing lamp coil.
freezy Jan 17, 2021
4f13aca
lamps: Add support for single-wire RGB lamps.
freezy Jan 17, 2021
d749283
player: Split into multiple classes.
freezy Jan 18, 2021
bf645de
lamps: Add more documentation.
freezy Jan 18, 2021
f43faf0
doc: Add missing lamp type section.
freezy Jan 18, 2021
d4e35c4
doc: Update coil manager with new destination.
freezy Jan 18, 2021
408379c
doc: Update changelog.
freezy Jan 19, 2021
83309c2
docs: light to lamp updates
jsm174 Jan 19, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Built with [Unity 2020.2](https://github.com/freezy/VisualPinball.Engine/pull/255).

### Added
- [Lamp Manager](https://docs.visualpinball.org/creators-guide/editor/coil-manager.html) ([#282](https://github.com/freezy/VisualPinball.Engine/pull/282))
- The VPE core is now also available on [NuGet](https://www.nuget.org/packages/VisualPinball.Engine/).
- VPE is now packaged and published on every merge!
- Native trough component ([#229](https://github.com/freezy/VisualPinball.Engine/pull/229), [#248](https://github.com/freezy/VisualPinball.Engine/pull/248), [#256](https://github.com/freezy/VisualPinball.Engine/pull/256), [Documentation](https://docs.visualpinball.org/creators-guide/manual/mechanisms/troughs.html))
Expand Down
6 changes: 3 additions & 3 deletions VisualPinball.Engine.Test/VPT/Mappings/CoilPopulationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void ShouldMapAHoldCoilByHint()
}

[Test]
public void ShouldMapAHoldCoilAsMainCoilIfHintedMainCoilNotFound()
public void ShouldCreateMainCoilIfNotFoundByHoldCoil()
{
var table = new TableBuilder()
.AddFlipper("left_flipper")
Expand All @@ -123,9 +123,9 @@ public void ShouldMapAHoldCoilAsMainCoilIfHintedMainCoilNotFound()
table.Mappings.Data.Coils[0].PlayfieldItem.Should().Be("left_flipper");
table.Mappings.Data.Coils[0].HoldCoilId.Should().BeEmpty();

table.Mappings.Data.Coils[1].Id.Should().Be("left_flipper_hold");
table.Mappings.Data.Coils[1].Id.Should().Be("foobar");
table.Mappings.Data.Coils[1].PlayfieldItem.Should().BeEmpty();
table.Mappings.Data.Coils[1].HoldCoilId.Should().BeEmpty();
table.Mappings.Data.Coils[1].HoldCoilId.Should().Be("left_flipper_hold");
}

[Test]
Expand Down
182 changes: 182 additions & 0 deletions VisualPinball.Engine.Test/VPT/Mappings/LampPopulationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
// Visual Pinball Engine
// Copyright (C) 2021 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.Linq;
using FluentAssertions;
using NUnit.Framework;
using VisualPinball.Engine.Game.Engines;
using VisualPinball.Engine.VPT;
using VisualPinball.Engine.VPT.Mappings;
using VisualPinball.Engine.VPT.Table;

namespace VisualPinball.Engine.Test.VPT.Mappings
{
public class LampPopulationTests
{
[Test]
public void ShouldMapALampWithTheSameName()
{
var table = new TableBuilder()
.AddLight("some_light")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "some_light", Description = "Some Light"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("some_light");
table.Mappings.Data.Lamps[0].Description.Should().Be("Some Light");
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().Be("some_light");
}

[Test]
public void ShouldMapALampWithTheSameNumericalId()
{
var table = new TableBuilder()
.AddLight("l42")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "42", Description = "Light 42"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("42");
table.Mappings.Data.Lamps[0].Description.Should().Be("Light 42");
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().Be("l42");
}

[Test]
public void ShouldMapALampWithViaRegex()
{
var table = new TableBuilder()
.AddLight("lamp_foobar_name")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "11", Description = "Foobar", PlayfieldItemHint = "_foobar_"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("11");
table.Mappings.Data.Lamps[0].Description.Should().Be("Foobar");
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().Be("lamp_foobar_name");
}

[Test]
public void ShouldNotMapALampWithViaRegex()
{
var table = new TableBuilder()
.AddLight("lamp_foobar_name")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "12", Description = "Foobar", PlayfieldItemHint = "^_foobar_$"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("12");
table.Mappings.Data.Lamps[0].Description.Should().Be("Foobar");
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().BeEmpty();
}

[Test]
public void ShouldMapAnRgbLamp()
{
var table = new TableBuilder()
.AddLight("my_rgb_light")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "rgb", Description = "RGB", PlayfieldItemHint = "rgb"},
new GamelogicEngineLamp {Id = "g", MainLampIdOfGreen = "rgb"},
new GamelogicEngineLamp {Id = "b", MainLampIdOfBlue = "rgb"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("rgb");
table.Mappings.Data.Lamps[0].Green.Should().Be("g");
table.Mappings.Data.Lamps[0].Blue.Should().Be("b");
table.Mappings.Data.Lamps[0].Description.Should().Be("RGB");
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().Be("my_rgb_light");
}

[Test]
public void ShouldCreateMapAnRgbLampIfRisMissing()
{
var table = new TableBuilder()
.AddLight("my_rgb_light")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "g", Description = "RGB", MainLampIdOfGreen = "rgb"},
new GamelogicEngineLamp {Id = "b", MainLampIdOfBlue = "rgb"}
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);

table.Mappings.Data.Lamps.Should().HaveCount(1);
table.Mappings.Data.Lamps[0].Destination.Should().Be(CoilDestination.Playfield);
table.Mappings.Data.Lamps[0].Id.Should().Be("rgb");
table.Mappings.Data.Lamps[0].Green.Should().Be("g");
table.Mappings.Data.Lamps[0].Blue.Should().Be("b");
table.Mappings.Data.Lamps[0].Description.Should().BeEmpty();
table.Mappings.Data.Lamps[0].PlayfieldItem.Should().BeEmpty();
}

[Test]
public void ShouldReturnAllLampIds()
{
var table = new TableBuilder()
.AddLight("l11")
.AddLight("l12")
.Build();

var gameEngineLamps = new[] {
new GamelogicEngineLamp {Id = "11" },
};

table.Mappings.PopulateLamps(gameEngineLamps, table.Lightables);
table.Mappings.Data.AddLamp(new MappingsLampData {
Id = "12",
Destination = LampDestination.Playfield,
PlayfieldItem = "l12"
});

var lampIds = table.Mappings.GetLamps(gameEngineLamps).ToArray();

lampIds.Length.Should().Be(2);
lampIds[0].Id.Should().Be("11");
lampIds[1].Id.Should().Be("12");
}
}
}
2 changes: 1 addition & 1 deletion VisualPinball.Engine.Test/VPT/MaterialFileTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Visual Pinball Engine
// Copyright (C) 2020 freezy and VPE Team
// Copyright (C) 2021 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
28 changes: 28 additions & 0 deletions VisualPinball.Engine/Game/Engines/GamelogicEngineLamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Visual Pinball Engine
// Copyright (C) 2021 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace VisualPinball.Engine.Game.Engines
{
public struct GamelogicEngineLamp
{
public string Id;
public string Description;
public string PlayfieldItemHint;
public int TypeHint;
public string MainLampIdOfGreen;
public string MainLampIdOfBlue;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions VisualPinball.Engine/Game/ILightable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Visual Pinball Engine
// Copyright (C) 2021 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace VisualPinball.Engine.Game
{
public interface ILightable
{
string Name { get; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions VisualPinball.Engine/IO/BiffMappingsLampAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Visual Pinball Engine
// Copyright (C) 2021 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System.IO;
using VisualPinball.Engine.VPT.Mappings;
using VisualPinball.Engine.VPT.Table;

namespace VisualPinball.Engine.IO
{
public class BiffMappingsLampAttribute : BiffAttribute
{
public BiffMappingsLampAttribute(string name) : base(name) { }

public override void Parse<T>(T obj, BinaryReader reader, int len)
{
ParseValue(obj, reader, len, ReadMappingsLamp);
}

public override void Write<TItem>(TItem obj, BinaryWriter writer, HashWriter hashWriter)
{
WriteValue<TItem, MappingsLampData>(obj, writer, (w, v) => WriteMappingsLamp(w, v, hashWriter), hashWriter, x => 0);
}

private static void WriteMappingsLamp(BinaryWriter writer, BiffData value, HashWriter hashWriter)
{
value.Write(writer, hashWriter);
}

private static MappingsLampData ReadMappingsLamp(BinaryReader reader, int len)
{
return new MappingsLampData(reader);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions VisualPinball.Engine/Math/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public enum ColorFormat
Bgr, Argb
}

public enum ColorChannel
{
Red, Green, Blue, Alpha
}

public static class Colors
{
public static readonly Color Black = new Color(0, 0, 0, 255);
Expand Down
21 changes: 21 additions & 0 deletions VisualPinball.Engine/VPT/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static class CoilDestination
{
public const int Playfield = 0;
public const int Device = 1;
public const int Lamp = 2;
}

public static class CoilType
Expand All @@ -190,4 +191,24 @@ public static class WireType
public const int OnOff = 0;
public const int Pulse = 1;
}

public static class LampDestination
{
public const int Playfield = 0;
public const int Device = 1;
}

public static class LampSource
{
public const int Lamps = 0;
public const int Coils = 1;
}

public static class LampType
{
public const int SingleOnOff = 0;
public const int SingleFading = 1;
public const int RgbMulti = 2;
public const int Rgb = 3;
}
}
Loading