diff --git a/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs b/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs index ab1981f..e9b71e2 100644 --- a/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs +++ b/TestProject/Assets/Tests/PlayMode/GenericWorldCaptureTests.cs @@ -205,6 +205,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests float tractorBeamPower = 0f; float tractorReleasedPower = 1f; int tractorBeamParticleSystemCount = 0; + EveUnityFeedbackEvent pickupCollection = null; + int pickupCollectionEventCount = 0; + int initialPickupEntityCount = 0; + int finalPickupEntityCount = -1; try { @@ -267,6 +271,16 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests } Assert.That(host.PresentedEntities?.CurrentGeneration, Is.Not.Null); Assert.That(host.PresentedEntities.CurrentGeneration.Entities.Count, Is.GreaterThan(0)); + initialPickupEntityCount = host.PresentedEntities.CurrentGeneration.Entities.Count(entity => + string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal)); + Assert.That(initialPickupEntityCount, Is.GreaterThan(0), + "The daemon fixture did not publish its physical starter pickup through the entity SoA."); + runtime.FeedbackAvailable += feedback => + { + if (!string.Equals(feedback.Kind, "pickup.collected", StringComparison.Ordinal)) return; + pickupCollectionEventCount++; + pickupCollection = feedback; + }; var playerId = runtime.ActiveWorld.PlayerEntityId; var playerFact = host.PresentedEntities.CurrentGeneration.Entities @@ -418,6 +432,27 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests tractorBeamParticleSystemCount = beamRenderer.ActiveParticleSystemCount; Assert.That(tractorBeamParticleSystemCount, Is.GreaterThan(0), "The generic beam lowerer did not instantiate the provider-owned effect prefab."); + var pickupDeadline = Time.realtimeSinceStartup + 12f; + while (Time.realtimeSinceStartup < pickupDeadline && + (pickupCollection == null || + host.PresentedEntities.CurrentGeneration.Entities.Any(entity => + string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal)))) + { + yield return new WaitForSecondsRealtime(0.1f); + runtime.Refresh(); + } + finalPickupEntityCount = host.PresentedEntities.CurrentGeneration.Entities.Count(entity => + string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal)); + Assert.That(pickupCollection, Is.Not.Null, + "The released client did not observe provider-owned feedback for Ymir contact collection."); + Assert.That(pickupCollectionEventCount, Is.EqualTo(1), + "One Ymir contact transaction must emit one client-visible collection event."); + Assert.That(pickupCollection.ItemKey, Is.EqualTo("scrap-metal")); + Assert.That(pickupCollection.ScalarValue, Is.EqualTo(1)); + Assert.That(pickupCollection.CargoQuantityBefore, Is.Zero); + Assert.That(pickupCollection.CargoQuantityAfter, Is.EqualTo(1)); + Assert.That(finalPickupEntityCount, Is.EqualTo(initialPickupEntityCount - 1), + "Collected pickup remained in the provider-authored entity generation."); var focusVersion = runtime.ActiveVersion; var inputDriver = root.GetComponent() ?? @@ -659,6 +694,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests tractorBeamPower, tractorReleasedPower, tractorBeamParticleSystemCount, + initialPickupEntityCount, + finalPickupEntityCount, + pickupCollectionEventCount, + pickupCollection, playerRendererFacts); } finally @@ -711,6 +750,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests float tractorBeamPower, float tractorReleasedPower, int tractorBeamParticleSystemCount, + int initialPickupEntityCount, + int finalPickupEntityCount, + int pickupCollectionEventCount, + EveUnityFeedbackEvent pickupCollection, RendererFact[] playerRendererFacts) { var path = Environment.GetEnvironmentVariable("EVEUNITY_WITNESS_FACTS_PATH"); @@ -753,6 +796,15 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests tractorBeamPower = tractorBeamPower, tractorReleasedPower = tractorReleasedPower, tractorBeamParticleSystemCount = tractorBeamParticleSystemCount, + pickupCollection = pickupCollection != null && pickupCollectionEventCount == 1 && + pickupCollection.CargoQuantityAfter - pickupCollection.CargoQuantityBefore == pickupCollection.ScalarValue, + initialPickupEntityCount = initialPickupEntityCount, + finalPickupEntityCount = finalPickupEntityCount, + pickupCollectionEventCount = pickupCollectionEventCount, + pickupItemKey = pickupCollection?.ItemKey ?? "", + pickupQuantity = (float)(pickupCollection?.ScalarValue ?? 0), + cargoQuantityBeforePickup = (float)(pickupCollection?.CargoQuantityBefore ?? 0), + cargoQuantityAfterPickup = (float)(pickupCollection?.CargoQuantityAfter ?? 0), playerRenderers = playerRendererFacts, mapChannelRendererCount = mapChannelRendererCount, mapChangedPixels = mapChangedPixels, @@ -803,6 +855,14 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests public float tractorBeamPower; public float tractorReleasedPower; public int tractorBeamParticleSystemCount; + public bool pickupCollection; + public int initialPickupEntityCount; + public int finalPickupEntityCount; + public int pickupCollectionEventCount; + public string pickupItemKey; + public float pickupQuantity; + public float cargoQuantityBeforePickup; + public float cargoQuantityAfterPickup; public RendererFact[] playerRenderers; public int mapChannelRendererCount; public int mapChangedPixels; diff --git a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityFeedbackPresenter.cs b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityFeedbackPresenter.cs index 1f189fe..723671f 100644 --- a/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityFeedbackPresenter.cs +++ b/packages/org.gamecult.eve.unity-scene/Runtime/EveUnityFeedbackPresenter.cs @@ -11,10 +11,13 @@ namespace GameCult.Eve.UnityScene public EveUnityFeedbackEvent(EveUnitySceneNode node) { EventId = Get(node, "eventId"); Kind = Get(node, "eventKind"); SubjectKey = Get(node, "subjectKey"); - ItemKey = Get(node, "itemKey"); Position = Get(node, "position"); + ItemKey = Get(node, "itemKey"); Position = Get(node, "position"); Reason = Get(node, "reason"); FrameId = Long(node, "frameId", -1); ZoneIndex = Int(node, "zoneIndex", -1); SourceEntityIndex = Int(node, "sourceEntityIndex", -1); TargetEntityIndex = Int(node, "targetEntityIndex", -1); PickupIndex = Int(node, "pickupIndex", -1); ScalarValue = Double(node, "scalarValue", 0); + AuxiliaryValue = Double(node, "auxiliaryValue", 0); + CargoQuantityBefore = Double(node, "cargoQuantityBefore", 0); + CargoQuantityAfter = Double(node, "cargoQuantityAfter", 0); } public string EventId { get; } public string Kind { get; } @@ -26,7 +29,11 @@ namespace GameCult.Eve.UnityScene public string SubjectKey { get; } public string ItemKey { get; } public string Position { get; } + public string Reason { get; } public double ScalarValue { get; } + public double AuxiliaryValue { get; } + public double CargoQuantityBefore { get; } + public double CargoQuantityAfter { get; } private static string Get(EveUnitySceneNode node, string key) => node.Props.TryGetValue(key, out var value) ? value ?? "" : ""; private static int Int(EveUnitySceneNode node, string key, int fallback) => int.TryParse(Get(node, key), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback; private static long Long(EveUnitySceneNode node, string key, long fallback) => long.TryParse(Get(node, key), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback; diff --git a/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityFeedbackPresenterTests.cs b/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityFeedbackPresenterTests.cs index e4bd612..8dc0d35 100644 --- a/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityFeedbackPresenterTests.cs +++ b/packages/org.gamecult.eve.unity-scene/Tests/Editor/EveUnityFeedbackPresenterTests.cs @@ -29,14 +29,51 @@ namespace GameCult.Eve.UnityScene.Tests Assert.That(emitted.Count, Is.EqualTo(1)); } + [Test] + public void FeedbackEventPreservesProviderOwnedCargoDeltaAndReason() + { + var node = Event("pickup", "pickup.collected", 9, new Dictionary + { + ["itemKey"] = "scrap-metal", + ["scalarValue"] = "1", + ["auxiliaryValue"] = "0", + ["cargoQuantityBefore"] = "0", + ["cargoQuantityAfter"] = "1", + ["reason"] = "" + }); + + var value = new EveUnityFeedbackEvent(node); + + Assert.That(value.ItemKey, Is.EqualTo("scrap-metal")); + Assert.That(value.ScalarValue, Is.EqualTo(1)); + Assert.That(value.AuxiliaryValue, Is.Zero); + Assert.That(value.CargoQuantityBefore, Is.Zero); + Assert.That(value.CargoQuantityAfter, Is.EqualTo(1)); + Assert.That(value.Reason, Is.Empty); + } + private static EveUnitySceneProjection Projection(params EveUnitySceneNode[] events) => new EveUnitySceneProjection("provider", "surface", "world", "commands", "receipt", "provider", null, Node("root", "surface", Node("feedback", "feedback.stream", events))); - private static EveUnitySceneNode Event(string id, string kind, long frame) => + private static EveUnitySceneNode Event( + string id, + string kind, + long frame, + IReadOnlyDictionary? extra = null) + { + var props = new Dictionary(StringComparer.Ordinal) + { + ["eventId"] = id, + ["eventKind"] = kind, + ["frameId"] = frame.ToString() + }; + foreach (var pair in extra ?? Empty()) props[pair.Key] = pair.Value; + return new EveUnitySceneNode(id, "feedback.event", "scene-node", - new Dictionary(StringComparer.Ordinal) { ["eventId"] = id, ["eventKind"] = kind, ["frameId"] = frame.ToString() }, + props, Empty(), Empty(), 0, 0, Array.Empty(), null, Array.Empty()); + } private static EveUnitySceneNode Node(string id, string kind, params EveUnitySceneNode[] children) => new EveUnitySceneNode(id, kind, "scene-node", Empty(), Empty(), Empty(), 0, 0, diff --git a/packages/org.gamecult.eve.unity-scene/package.json b/packages/org.gamecult.eve.unity-scene/package.json index 4882abb..4bfe911 100644 --- a/packages/org.gamecult.eve.unity-scene/package.json +++ b/packages/org.gamecult.eve.unity-scene/package.json @@ -1,7 +1,7 @@ { "name": "org.gamecult.eve.unity-scene", "displayName": "Eve Unity Scene Lowering", - "version": "0.3.31", + "version": "0.3.32", "unity": "2021.3", "description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.", "dependencies": {