diff --git a/EliteAPI.Tests/FlatteningTests.cs b/EliteAPI.Tests/FlatteningTests.cs index ff79d731..548f3570 100644 --- a/EliteAPI.Tests/FlatteningTests.cs +++ b/EliteAPI.Tests/FlatteningTests.cs @@ -1,7 +1,7 @@ using EliteAPI.Events; using EliteAPI.Json; using FluentAssertions; -using ValueType = EliteAPI.Events.ValueType; +using EventValueType = EliteAPI.Events.EventValueType; namespace EliteAPI.Tests; @@ -15,7 +15,7 @@ public void OneField() var expected = new[] { - new EventPath("test", 1, ValueType.Number) + new EventPath("test", 1, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -29,9 +29,9 @@ public void MultipleFields() var expected = new[] { - new EventPath("test1", 1, ValueType.Number), - new EventPath("test2", "value", ValueType.String), - new EventPath("test3", true, ValueType.Boolean) + new EventPath("test1", 1, EventValueType.Number), + new EventPath("test2", "value", EventValueType.String), + new EventPath("test3", true, EventValueType.Boolean) }; paths.Should().BeEquivalentTo(expected); @@ -45,10 +45,10 @@ public void SimpleArray() var expected = new[] { - new EventPath("items[0]", 1, ValueType.Number), - new EventPath("items[1]", 2, ValueType.Number), - new EventPath("items[2]", 3, ValueType.Number), - new EventPath("items.Length", 3, ValueType.Number) + new EventPath("items[0]", 1, EventValueType.Number), + new EventPath("items[1]", 2, EventValueType.Number), + new EventPath("items[2]", 3, EventValueType.Number), + new EventPath("items.Length", 3, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -62,10 +62,10 @@ public void ArrayWithObject() var expected = new[] { - new EventPath("items[0].nested", 1, ValueType.Number), - new EventPath("items[1].nested", "2", ValueType.String), - new EventPath("items[2].nested", false, ValueType.Boolean), - new EventPath("items.Length", 3, ValueType.Number) + new EventPath("items[0].nested", 1, EventValueType.Number), + new EventPath("items[1].nested", "2", EventValueType.String), + new EventPath("items[2].nested", false, EventValueType.Boolean), + new EventPath("items.Length", 3, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -79,7 +79,7 @@ public void DecimalField() var expected = new[] { - new EventPath("price", 19.99m, ValueType.Decimal) + new EventPath("price", 19.99m, EventValueType.Decimal) }; paths.Should().BeEquivalentTo(expected); @@ -93,9 +93,9 @@ public void MultipleDecimalFields() var expected = new[] { - new EventPath("price", 19.99m, ValueType.Decimal), - new EventPath("tax", 1.50m, ValueType.Decimal), - new EventPath("total", 21.49m, ValueType.Decimal) + new EventPath("price", 19.99m, EventValueType.Decimal), + new EventPath("tax", 1.50m, EventValueType.Decimal), + new EventPath("total", 21.49m, EventValueType.Decimal) }; paths.Should().BeEquivalentTo(expected); @@ -109,7 +109,7 @@ public void DateTimeField() var expected = new[] { - new EventPath("timestamp", new DateTime(2025, 11, 21, 10, 30, 0, DateTimeKind.Utc), ValueType.DateTime) + new EventPath("timestamp", new DateTime(2025, 11, 21, 10, 30, 0, DateTimeKind.Utc), EventValueType.DateTime) }; paths.Should().BeEquivalentTo(expected); @@ -123,8 +123,8 @@ public void MultipleDateTimeFields() var expected = new[] { - new EventPath("createdAt", new DateTime(2025, 11, 21, 10, 30, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("updatedAt", new DateTime(2025, 11, 21, 15, 45, 0, DateTimeKind.Utc), ValueType.DateTime) + new EventPath("createdAt", new DateTime(2025, 11, 21, 10, 30, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("updatedAt", new DateTime(2025, 11, 21, 15, 45, 0, DateTimeKind.Utc), EventValueType.DateTime) }; paths.Should().BeEquivalentTo(expected); @@ -138,11 +138,11 @@ public void MixedTypesWithDecimalAndDateTime() var expected = new[] { - new EventPath("id", 1, ValueType.Number), - new EventPath("name", "Product", ValueType.String), - new EventPath("price", 29.99m, ValueType.Decimal), - new EventPath("created", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("active", true, ValueType.Boolean) + new EventPath("id", 1, EventValueType.Number), + new EventPath("name", "Product", EventValueType.String), + new EventPath("price", 29.99m, EventValueType.Decimal), + new EventPath("created", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("active", true, EventValueType.Boolean) }; paths.Should().BeEquivalentTo(expected); @@ -156,8 +156,8 @@ public void SimpleNestedObject() var expected = new[] { - new EventPath("user.name", "John", ValueType.String), - new EventPath("user.age", 30, ValueType.Number) + new EventPath("user.name", "John", EventValueType.String), + new EventPath("user.age", 30, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -171,7 +171,7 @@ public void DeeplyNestedObject() var expected = new[] { - new EventPath("level1.level2.level3.value", "deep", ValueType.String) + new EventPath("level1.level2.level3.value", "deep", EventValueType.String) }; paths.Should().BeEquivalentTo(expected); @@ -185,11 +185,11 @@ public void NestedObjectWithMixedTypes() var expected = new[] { - new EventPath("product.id", 1, ValueType.Number), - new EventPath("product.name", "Widget", ValueType.String), - new EventPath("product.price", 19.99m, ValueType.Decimal), - new EventPath("product.created", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("product.inStock", true, ValueType.Boolean) + new EventPath("product.id", 1, EventValueType.Number), + new EventPath("product.name", "Widget", EventValueType.String), + new EventPath("product.price", 19.99m, EventValueType.Decimal), + new EventPath("product.created", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("product.inStock", true, EventValueType.Boolean) }; paths.Should().BeEquivalentTo(expected); @@ -203,10 +203,10 @@ public void MultipleNestedObjects() var expected = new[] { - new EventPath("user.name", "John", ValueType.String), - new EventPath("user.age", 30, ValueType.Number), - new EventPath("address.city", "NYC", ValueType.String), - new EventPath("address.zip", 10001, ValueType.Number) + new EventPath("user.name", "John", EventValueType.String), + new EventPath("user.age", 30, EventValueType.Number), + new EventPath("address.city", "NYC", EventValueType.String), + new EventPath("address.zip", 10001, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -220,9 +220,9 @@ public void NestedObjectWithDecimalAndDateTime() var expected = new[] { - new EventPath("transaction.amount", 99.99m, ValueType.Decimal), - new EventPath("transaction.fee", 2.50m, ValueType.Decimal), - new EventPath("transaction.timestamp", new DateTime(2025, 11, 21, 14, 30, 0, DateTimeKind.Utc), ValueType.DateTime) + new EventPath("transaction.amount", 99.99m, EventValueType.Decimal), + new EventPath("transaction.fee", 2.50m, EventValueType.Decimal), + new EventPath("transaction.timestamp", new DateTime(2025, 11, 21, 14, 30, 0, DateTimeKind.Utc), EventValueType.DateTime) }; paths.Should().BeEquivalentTo(expected); @@ -236,11 +236,11 @@ public void NestedObjectWithArrays() var expected = new[] { - new EventPath("user.name", "John", ValueType.String), - new EventPath("user.scores[0]", 95, ValueType.Number), - new EventPath("user.scores[1]", 87, ValueType.Number), - new EventPath("user.scores[2]", 92, ValueType.Number), - new EventPath("user.scores.Length", 3, ValueType.Number) + new EventPath("user.name", "John", EventValueType.String), + new EventPath("user.scores[0]", 95, EventValueType.Number), + new EventPath("user.scores[1]", 87, EventValueType.Number), + new EventPath("user.scores[2]", 92, EventValueType.Number), + new EventPath("user.scores.Length", 3, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -270,16 +270,16 @@ public void ComplexNestedStructure() var expected = new[] { - new EventPath("order.id", 123, ValueType.Number), - new EventPath("order.customer.name", "Jane Doe", ValueType.String), - new EventPath("order.customer.email", "jane@example.com", ValueType.String), - new EventPath("order.items[0].name", "Item1", ValueType.String), - new EventPath("order.items[0].price", 10.50m, ValueType.Decimal), - new EventPath("order.items[1].name", "Item2", ValueType.String), - new EventPath("order.items[1].price", 25.99m, ValueType.Decimal), - new EventPath("order.items.Length", 2, ValueType.Number), - new EventPath("order.total", 36.49m, ValueType.Decimal), - new EventPath("order.orderDate", new DateTime(2025, 11, 21, 9, 0, 0, DateTimeKind.Utc), ValueType.DateTime) + new EventPath("order.id", 123, EventValueType.Number), + new EventPath("order.customer.name", "Jane Doe", EventValueType.String), + new EventPath("order.customer.email", "jane@example.com", EventValueType.String), + new EventPath("order.items[0].name", "Item1", EventValueType.String), + new EventPath("order.items[0].price", 10.50m, EventValueType.Decimal), + new EventPath("order.items[1].name", "Item2", EventValueType.String), + new EventPath("order.items[1].price", 25.99m, EventValueType.Decimal), + new EventPath("order.items.Length", 2, EventValueType.Number), + new EventPath("order.total", 36.49m, EventValueType.Decimal), + new EventPath("order.orderDate", new DateTime(2025, 11, 21, 9, 0, 0, DateTimeKind.Utc), EventValueType.DateTime) }; paths.Should().BeEquivalentTo(expected); @@ -304,7 +304,7 @@ public void EmptyArray() var expected = new[] { - new EventPath("items.Length", 0, ValueType.Number) + new EventPath("items.Length", 0, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -318,7 +318,7 @@ public void NullValues() var expected = new[] { - new EventPath("age", 30, ValueType.Number) + new EventPath("age", 30, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -332,8 +332,8 @@ public void NegativeNumbers() var expected = new[] { - new EventPath("temperature", -15, ValueType.Number), - new EventPath("balance", -100, ValueType.Number) + new EventPath("temperature", -15, EventValueType.Number), + new EventPath("balance", -100, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -347,8 +347,8 @@ public void NegativeDecimals() var expected = new[] { - new EventPath("balance", -99.99m, ValueType.Decimal), - new EventPath("adjustment", -5.50m, ValueType.Decimal) + new EventPath("balance", -99.99m, EventValueType.Decimal), + new EventPath("adjustment", -5.50m, EventValueType.Decimal) }; paths.Should().BeEquivalentTo(expected); @@ -362,9 +362,9 @@ public void ZeroValues() var expected = new[] { - new EventPath("count", 0, ValueType.Number), - new EventPath("price", 0.0m, ValueType.Decimal), - new EventPath("active", false, ValueType.Boolean) + new EventPath("count", 0, EventValueType.Number), + new EventPath("price", 0.0m, EventValueType.Decimal), + new EventPath("active", false, EventValueType.Boolean) }; paths.Should().BeEquivalentTo(expected); @@ -378,8 +378,8 @@ public void EmptyString() var expected = new[] { - new EventPath("name", "", ValueType.String), - new EventPath("description", "text", ValueType.String) + new EventPath("name", "", EventValueType.String), + new EventPath("description", "text", EventValueType.String) }; paths.Should().BeEquivalentTo(expected); @@ -393,10 +393,10 @@ public void ArrayOfDecimals() var expected = new[] { - new EventPath("prices[0]", 19.99m, ValueType.Decimal), - new EventPath("prices[1]", 29.99m, ValueType.Decimal), - new EventPath("prices[2]", 39.99m, ValueType.Decimal), - new EventPath("prices.Length", 3, ValueType.Number) + new EventPath("prices[0]", 19.99m, EventValueType.Decimal), + new EventPath("prices[1]", 29.99m, EventValueType.Decimal), + new EventPath("prices[2]", 39.99m, EventValueType.Decimal), + new EventPath("prices.Length", 3, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -410,10 +410,10 @@ public void ArrayOfDateTimes() var expected = new[] { - new EventPath("timestamps[0]", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("timestamps[1]", new DateTime(2025, 11, 21, 11, 0, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("timestamps[2]", new DateTime(2025, 11, 21, 12, 0, 0, DateTimeKind.Utc), ValueType.DateTime), - new EventPath("timestamps.Length", 3, ValueType.Number) + new EventPath("timestamps[0]", new DateTime(2025, 11, 21, 10, 0, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("timestamps[1]", new DateTime(2025, 11, 21, 11, 0, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("timestamps[2]", new DateTime(2025, 11, 21, 12, 0, 0, DateTimeKind.Utc), EventValueType.DateTime), + new EventPath("timestamps.Length", 3, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -427,11 +427,11 @@ public void MixedTypeArray() var expected = new[] { - new EventPath("mixed[0]", 1, ValueType.Number), - new EventPath("mixed[1]", "text", ValueType.String), - new EventPath("mixed[2]", true, ValueType.Boolean), - new EventPath("mixed[3]", 2.5m, ValueType.Decimal), - new EventPath("mixed.Length", 4, ValueType.Number) + new EventPath("mixed[0]", 1, EventValueType.Number), + new EventPath("mixed[1]", "text", EventValueType.String), + new EventPath("mixed[2]", true, EventValueType.Boolean), + new EventPath("mixed[3]", 2.5m, EventValueType.Decimal), + new EventPath("mixed.Length", 4, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); @@ -445,7 +445,7 @@ public void VeryLargeDecimal() var expected = new[] { - new EventPath("bigNumber", 999999999.99m, ValueType.Decimal) + new EventPath("bigNumber", 999999999.99m, EventValueType.Decimal) }; paths.Should().BeEquivalentTo(expected); @@ -459,7 +459,7 @@ public void VerySmallDecimal() var expected = new[] { - new EventPath("smallNumber", 0.0001m, ValueType.Decimal) + new EventPath("smallNumber", 0.0001m, EventValueType.Decimal) }; paths.Should().BeEquivalentTo(expected); @@ -473,7 +473,7 @@ public void StringWithSpecialCharacters() var expected = new[] { - new EventPath("text", "Hello \"World\"\nNew Line\tTab", ValueType.String) + new EventPath("text", "Hello \"World\"\nNew Line\tTab", EventValueType.String) }; paths.Should().BeEquivalentTo(expected); @@ -487,8 +487,8 @@ public void StringWithUnicode() var expected = new[] { - new EventPath("greeting", "Hello 🌍 World", ValueType.String), - new EventPath("emoji", "😀", ValueType.String) + new EventPath("greeting", "Hello 🌍 World", EventValueType.String), + new EventPath("emoji", "😀", EventValueType.String) }; paths.Should().BeEquivalentTo(expected); @@ -503,7 +503,7 @@ public void VeryLongString() var expected = new[] { - new EventPath("longText", longText, ValueType.String) + new EventPath("longText", longText, EventValueType.String) }; paths.Should().BeEquivalentTo(expected); @@ -517,8 +517,8 @@ public void NullInNestedObject() var expected = new[] { - new EventPath("user.name", "John", ValueType.String), - new EventPath("user.age", 30, ValueType.Number) + new EventPath("user.name", "John", EventValueType.String), + new EventPath("user.age", 30, EventValueType.Number) }; paths.Should().BeEquivalentTo(expected); diff --git a/EliteAPI.Tests/StatusTrackerTests.cs b/EliteAPI.Tests/StatusTrackerTests.cs index 1fc3b758..5819e337 100644 --- a/EliteAPI.Tests/StatusTrackerTests.cs +++ b/EliteAPI.Tests/StatusTrackerTests.cs @@ -1,7 +1,7 @@ using EliteAPI.Events; using EliteAPI.Journals; using FluentAssertions; -using ValueType = EliteAPI.Events.ValueType; +using EventValueType = EliteAPI.Events.EventValueType; namespace EliteAPI.Tests; @@ -15,16 +15,16 @@ public void DetectsFieldChange_WhenBooleanValueChanges() // First update: Gear is false var initialPaths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean), - new("EliteAPI.Hardpoints", false, ValueType.Boolean) + new("EliteAPI.Gear", false, EventValueType.Boolean), + new("EliteAPI.Hardpoints", false, EventValueType.Boolean) }; tracker.UpdateState(initialPaths); // Second update: Gear changes to true var updatedPaths = new List { - new("EliteAPI.Gear", true, ValueType.Boolean), - new("EliteAPI.Hardpoints", false, ValueType.Boolean) + new("EliteAPI.Gear", true, EventValueType.Boolean), + new("EliteAPI.Hardpoints", false, EventValueType.Boolean) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -41,16 +41,16 @@ public void DetectsFieldChange_WhenNumericValueChanges() // First update: GuiFocus is 0 var initialPaths = new List { - new("EliteAPI.GuiFocus", 0, ValueType.Number), - new("EliteAPI.FireGroup", 1, ValueType.Number) + new("EliteAPI.GuiFocus", 0, EventValueType.Number), + new("EliteAPI.FireGroup", 1, EventValueType.Number) }; tracker.UpdateState(initialPaths); // Second update: GuiFocus changes to 3 var updatedPaths = new List { - new("EliteAPI.GuiFocus", 3, ValueType.Number), - new("EliteAPI.FireGroup", 1, ValueType.Number) + new("EliteAPI.GuiFocus", 3, EventValueType.Number), + new("EliteAPI.FireGroup", 1, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -67,16 +67,16 @@ public void DetectsFieldChange_WhenDecimalValueChanges() // First update: FuelMain is 32.0 var initialPaths = new List { - new("EliteAPI.Fuel.FuelMain", 32.0m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.5m, ValueType.Decimal) + new("EliteAPI.Fuel.FuelMain", 32.0m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.5m, EventValueType.Decimal) }; tracker.UpdateState(initialPaths); // Second update: FuelMain changes to 31.5 var updatedPaths = new List { - new("EliteAPI.Fuel.FuelMain", 31.5m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.5m, ValueType.Decimal) + new("EliteAPI.Fuel.FuelMain", 31.5m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.5m, EventValueType.Decimal) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -94,18 +94,18 @@ public void DetectsMultipleFieldChanges() // First update var initialPaths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean), - new("EliteAPI.Hardpoints", false, ValueType.Boolean), - new("EliteAPI.GuiFocus", 0, ValueType.Number) + new("EliteAPI.Gear", false, EventValueType.Boolean), + new("EliteAPI.Hardpoints", false, EventValueType.Boolean), + new("EliteAPI.GuiFocus", 0, EventValueType.Number) }; tracker.UpdateState(initialPaths); // Second update: Multiple fields change var updatedPaths = new List { - new("EliteAPI.Gear", true, ValueType.Boolean), - new("EliteAPI.Hardpoints", true, ValueType.Boolean), - new("EliteAPI.GuiFocus", 0, ValueType.Number) + new("EliteAPI.Gear", true, EventValueType.Boolean), + new("EliteAPI.Hardpoints", true, EventValueType.Boolean), + new("EliteAPI.GuiFocus", 0, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -123,16 +123,16 @@ public void ReturnsEmptyList_WhenNoFieldsChange() // First update var initialPaths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean), - new("EliteAPI.GuiFocus", 0, ValueType.Number) + new("EliteAPI.Gear", false, EventValueType.Boolean), + new("EliteAPI.GuiFocus", 0, EventValueType.Number) }; tracker.UpdateState(initialPaths); // Second update: Same values var updatedPaths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean), - new("EliteAPI.GuiFocus", 0, ValueType.Number) + new("EliteAPI.Gear", false, EventValueType.Boolean), + new("EliteAPI.GuiFocus", 0, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -148,9 +148,9 @@ public void ReturnsEmptyList_OnFirstUpdate() // First update (no previous state) var paths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean), - new("EliteAPI.Hardpoints", false, ValueType.Boolean), - new("EliteAPI.GuiFocus", 0, ValueType.Number) + new("EliteAPI.Gear", false, EventValueType.Boolean), + new("EliteAPI.Hardpoints", false, EventValueType.Boolean), + new("EliteAPI.GuiFocus", 0, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(paths); @@ -167,18 +167,18 @@ public void ExtractsRootFieldName_FromNestedPath() // First update var initialPaths = new List { - new("EliteAPI.Fuel.FuelMain", 32.0m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.5m, ValueType.Decimal), - new("EliteAPI.Destination.System", 123456789L, ValueType.Number) + new("EliteAPI.Fuel.FuelMain", 32.0m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.5m, EventValueType.Decimal), + new("EliteAPI.Destination.System", 123456789L, EventValueType.Number) }; tracker.UpdateState(initialPaths); // Second update: Change nested field var updatedPaths = new List { - new("EliteAPI.Fuel.FuelMain", 31.0m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.4m, ValueType.Decimal), - new("EliteAPI.Destination.System", 987654321L, ValueType.Number) + new("EliteAPI.Fuel.FuelMain", 31.0m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.4m, EventValueType.Decimal), + new("EliteAPI.Destination.System", 987654321L, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -197,16 +197,16 @@ public void OnlyReportsRootFieldOnce_WhenMultipleSubfieldsChange() // First update var initialPaths = new List { - new("EliteAPI.Fuel.FuelMain", 32.0m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.5m, ValueType.Decimal) + new("EliteAPI.Fuel.FuelMain", 32.0m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.5m, EventValueType.Decimal) }; tracker.UpdateState(initialPaths); // Second update: Both Fuel subfields change var updatedPaths = new List { - new("EliteAPI.Fuel.FuelMain", 31.0m, ValueType.Decimal), - new("EliteAPI.Fuel.FuelReservoir", 0.4m, ValueType.Decimal) + new("EliteAPI.Fuel.FuelMain", 31.0m, EventValueType.Decimal), + new("EliteAPI.Fuel.FuelReservoir", 0.4m, EventValueType.Decimal) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -224,14 +224,14 @@ public void HandlesStringValueChanges() // First update var initialPaths = new List { - new("EliteAPI.LegalState", "Clean", ValueType.String) + new("EliteAPI.LegalState", "Clean", EventValueType.String) }; tracker.UpdateState(initialPaths); // Second update: LegalState changes var updatedPaths = new List { - new("EliteAPI.LegalState", "Wanted", ValueType.String) + new("EliteAPI.LegalState", "Wanted", EventValueType.String) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -248,18 +248,18 @@ public void HandlesPipsArrayChanges() // First update var initialPaths = new List { - new("EliteAPI.Pips.Systems", 2, ValueType.Number), - new("EliteAPI.Pips.Engines", 8, ValueType.Number), - new("EliteAPI.Pips.Weapons", 2, ValueType.Number) + new("EliteAPI.Pips.Systems", 2, EventValueType.Number), + new("EliteAPI.Pips.Engines", 8, EventValueType.Number), + new("EliteAPI.Pips.Weapons", 2, EventValueType.Number) }; tracker.UpdateState(initialPaths); // Second update: Pips change var updatedPaths = new List { - new("EliteAPI.Pips.Systems", 4, ValueType.Number), - new("EliteAPI.Pips.Engines", 4, ValueType.Number), - new("EliteAPI.Pips.Weapons", 4, ValueType.Number) + new("EliteAPI.Pips.Systems", 4, EventValueType.Number), + new("EliteAPI.Pips.Engines", 4, EventValueType.Number), + new("EliteAPI.Pips.Weapons", 4, EventValueType.Number) }; var changedFields = tracker.GetChangedFieldNames(updatedPaths); @@ -277,7 +277,7 @@ public void IsThreadSafe_WhenAccessedConcurrently() // Initialize var initialPaths = new List { - new("EliteAPI.Gear", false, ValueType.Boolean) + new("EliteAPI.Gear", false, EventValueType.Boolean) }; tracker.UpdateState(initialPaths); @@ -290,7 +290,7 @@ public void IsThreadSafe_WhenAccessedConcurrently() { var paths = new List { - new("EliteAPI.Gear", value, ValueType.Boolean) + new("EliteAPI.Gear", value, EventValueType.Boolean) }; tracker.GetChangedFieldNames(paths); tracker.UpdateState(paths); diff --git a/EliteAPI/EliteDangerousApi.cs b/EliteAPI/EliteDangerousApi.cs index 1698a68d..6d6364e3 100644 --- a/EliteAPI/EliteDangerousApi.cs +++ b/EliteAPI/EliteDangerousApi.cs @@ -240,6 +240,8 @@ internal void Invoke(string json, IEvent? @event) private void HandleBindingsPreset(string presetContent) { + // look at the preset that occurs the most + var presets = presetContent.Split('\n').Where(line => !string.IsNullOrWhiteSpace(line)).ToList(); // Make sure all presets use the same format diff --git a/EliteAPI/Events/EventPath.cs b/EliteAPI/Events/EventPath.cs index 1f9752e6..80a0e991 100644 --- a/EliteAPI/Events/EventPath.cs +++ b/EliteAPI/Events/EventPath.cs @@ -1,18 +1,21 @@ +using System; +using System.Runtime.CompilerServices; + namespace EliteAPI.Events; -public readonly struct EventPath(string path, dynamic value, ValueType type) +public readonly struct EventPath(string path, dynamic value, EventValueType type) { public string Path { get; init; } = path; public dynamic Value { get; init; } = value; - public ValueType Type { get; init; } = type; + public EventValueType Type { get; init; } = type; internal EventPath WithPath(string path) => new(path.Replace("..", "."), Value, Type); } -public enum ValueType +public enum EventValueType { String, Number, @@ -20,3 +23,17 @@ public enum ValueType Boolean, DateTime, } + + +public static class EventUtils +{ + public static string ToDisplayType(this EventValueType valueType) => valueType switch + { + EventValueType.String => "TXT", + EventValueType.Number => "INT", + EventValueType.Decimal => "DEC", + EventValueType.Boolean => "BOOL", + EventValueType.DateTime => "DATE", + _ => "", + }; +} diff --git a/EliteAPI/Journals/JournalUtils.cs b/EliteAPI/Journals/JournalUtils.cs index 0da9cd33..4a877964 100644 --- a/EliteAPI/Journals/JournalUtils.cs +++ b/EliteAPI/Journals/JournalUtils.cs @@ -6,7 +6,7 @@ using System.Text.RegularExpressions; using EliteAPI.Events; using EliteAPI.Json; -using ValueType = EliteAPI.Events.ValueType; +using EventValueType = EliteAPI.Events.EventValueType; namespace EliteAPI.Journals; @@ -29,13 +29,13 @@ public static List ToPaths(string json) var flagsPath = paths.FirstOrDefault(p => p.Path == "Flags"); var flagsValue = flagsPath.Equals(default(EventPath)) ? 0 : Convert.ToInt32(flagsPath.Value); foreach (var flag in StatusUtils.GetFlags(flagsValue)) - paths.Add(new EventPath(flag.Key, flag.Value, ValueType.Boolean)); + paths.Add(new EventPath(flag.Key, flag.Value, EventValueType.Boolean)); // expand flags2 var flags2Path = paths.FirstOrDefault(p => p.Path == "Flags2"); var flags2Value = flags2Path.Equals(default(EventPath)) ? 0 : Convert.ToInt32(flags2Path.Value); foreach (var flag in StatusUtils.GetFlags2(flags2Value)) - paths.Add(new EventPath(flag.Key, flag.Value, ValueType.Boolean)); + paths.Add(new EventPath(flag.Key, flag.Value, EventValueType.Boolean)); // replace pips array with individual pips paths.Add(paths.FirstOrDefault(p => p.Path == "Pips[0]").WithPath("Pips.Systems")); @@ -47,7 +47,7 @@ public static List ToPaths(string json) if (!balancePath.Equals(default(EventPath))) { paths.Remove(balancePath); - paths.Add(new EventPath("Balance", Convert.ToDecimal(balancePath.Value), ValueType.Decimal)); + paths.Add(new EventPath("Balance", Convert.ToDecimal(balancePath.Value), EventValueType.Decimal)); } } diff --git a/EliteAPI/Json/JsonUtils.cs b/EliteAPI/Json/JsonUtils.cs index 2a20e96a..b00fb8b0 100644 --- a/EliteAPI/Json/JsonUtils.cs +++ b/EliteAPI/Json/JsonUtils.cs @@ -6,7 +6,7 @@ using EliteAPI.Json.SerializationSettings; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using ValueType = EliteAPI.Events.ValueType; +using EventValueType = EliteAPI.Events.EventValueType; namespace EliteAPI.Json; @@ -108,37 +108,37 @@ private static EventPath ToJsonPath(this JValue value) { Path = path, Value = Convert.ToInt32(value.Value), - Type = ValueType.Number + Type = EventValueType.Number }, JTokenType.Float => new EventPath { Path = path, Value = value.Value is BigInteger bigInt ? (decimal)bigInt : Convert.ToDecimal(value.Value), - Type = ValueType.Decimal + Type = EventValueType.Decimal }, JTokenType.Uri or JTokenType.Guid or JTokenType.String => new EventPath { Path = path, Value = Convert.ToString(value.Value) ?? string.Empty, - Type = ValueType.String + Type = EventValueType.String }, JTokenType.Boolean => new EventPath { Path = path, Value = Convert.ToBoolean(value.Value), - Type = ValueType.Boolean + Type = EventValueType.Boolean }, JTokenType.Date => new EventPath { Path = path, Value = Convert.ToDateTime(value.Value), - Type = ValueType.DateTime + Type = EventValueType.DateTime }, _ => new EventPath { Path = "", Value = "", - Type = ValueType.String + Type = EventValueType.String }, }; } diff --git a/EliteVA/EliteVA.cs b/EliteVA/EliteVA.cs index 1cd64862..309519c9 100644 --- a/EliteVA/EliteVA.cs +++ b/EliteVA/EliteVA.cs @@ -10,7 +10,7 @@ using EliteAPI.Utils; using EliteVA.Abstractions; using EliteVA.Logging; -using ValueType = EliteAPI.Events.ValueType; +using EliteAPI.Events; namespace EliteVA; @@ -70,7 +70,7 @@ public override async Task OnStart(IVoiceAttackProxy proxy) if (!Directory.Exists(Path.Combine(Dir, "Variables"))) Directory.CreateDirectory(Path.Combine(Dir, "Variables")); - File.WriteAllText(Path.Combine(Dir, "Variables", $"Keybindings.txt"), bindings.Select(b => $"{b.name}: {b.binding.KeyCode}").Aggregate((a, b) => $"{a}\n{b}")); + File.WriteAllText(Path.Combine(Dir, "Variables", $"Keybindings.txt"), bindings.Select(b => $"{{TXT:{b.name}}}: {b.binding.KeyCode}").Aggregate((a, b) => $"{a}\n{b}")); proxy.Log.Write($"Applying {bindings.Count} keybindings", VoiceAttackColor.Blue); }); @@ -85,11 +85,11 @@ public override async Task OnStart(IVoiceAttackProxy proxy) var stringValue = Convert.ToString(v.Value, CultureInfo.InvariantCulture) ?? string.Empty; proxy.Variables.Set(v.Path, stringValue, v.Type switch { - ValueType.String => TypeCode.String, - ValueType.Number => TypeCode.Int32, - ValueType.Decimal => TypeCode.Decimal, - ValueType.Boolean => TypeCode.Boolean, - ValueType.DateTime => TypeCode.DateTime, + EventValueType.String => TypeCode.String, + EventValueType.Number => TypeCode.Int32, + EventValueType.Decimal => TypeCode.Decimal, + EventValueType.Boolean => TypeCode.Boolean, + EventValueType.DateTime => TypeCode.DateTime, _ => TypeCode.String }); }); @@ -112,7 +112,7 @@ public override async Task OnStart(IVoiceAttackProxy proxy) if (!Directory.Exists(Path.Combine(Dir, "Variables"))) Directory.CreateDirectory(Path.Combine(Dir, "Variables")); - File.WriteAllText(Path.Combine(Dir, "Variables", $"{e.eventName}.txt"), paths.Select(p => $"{p.Path}: {p.Value}").Aggregate((a, b) => $"{a}\n{b}")); + File.WriteAllText(Path.Combine(Dir, "Variables", $"{e.eventName}.txt"), paths.Select(p => $"{{{p.Type.ToDisplayType()}:{p.Path}}}: {p.Value}").Aggregate((a, b) => $"{a}\n{b}")); } });