Drive the field shield test scene by publishing capability events
FieldTester now owns a CapabilityEvents instance and stands in for the capability source the simulation doesn't have yet: it publishes AbsorbEvent on click (cycling DamageType so the operator can see how a type-aware presenter would behave), GrabEvent(Started) on pickup click, MeleeEvent on the Melee button, and a ThrustEvent every frame from input -- FieldDriver only ever reacts through CapabilityPresentationBinder. The damped push/twist state that used to live directly on FieldDriver.Push/FrontTwist/RearTwist now lives in FieldTester and is applied through the event instead. Adds a CapabilityPresentationBinder component to the field object in FieldShieldTest.unity, alongside the existing added ClickableCollider component on that same prefab-instance GameObject (same pattern, no serialized fields to wire). Scene behavior is unchanged: hits, melee, pickups and flow all look and act as before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
2138aa4560
commit
807c4fab7e
2 changed files with 80 additions and 24 deletions
|
|
@ -6,6 +6,11 @@ using CultMath.UnityBridge;
|
|||
using static CultMath.math;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
// Drives the field ONLY by publishing capability events into a CapabilityEvents source that
|
||||
// CapabilityPresentationBinder (a component alongside FieldDriver) feeds to it. This scene stands in
|
||||
// for the capability owner the simulation does not have yet (docs/headless-playground-cut.md fork L:
|
||||
// "Simulation emits capability events; presentations subscribe and decide nothing"). FieldTester
|
||||
// itself decides nothing about how those events render -- that stays FieldDriver's job as a presenter.
|
||||
public class FieldTester : MonoBehaviour
|
||||
{
|
||||
public int PickupCount;
|
||||
|
|
@ -21,13 +26,26 @@ public class FieldTester : MonoBehaviour
|
|||
public Camera Camera;
|
||||
public FieldDriver TestField;
|
||||
public PropertiesPanel Properties;
|
||||
|
||||
|
||||
private AetheriaInput _input;
|
||||
private bool _forceThrust;
|
||||
private float _throttleDecay = 2;
|
||||
private bool _directionalPush;
|
||||
private float _twistFront;
|
||||
private float _twistRear;
|
||||
|
||||
// Damped thrust state: previously lived on TestField.Push/FrontTwist/RearTwist and was written
|
||||
// there directly every frame. Now that FieldTester only ever publishes a ThrustEvent, the damped
|
||||
// state itself has to live here instead -- FieldDriver's own Push/FrontTwist/RearTwist fields are
|
||||
// set from the event by FieldDriver.Thrust() and read only for the shader and the properties panel.
|
||||
private float2 _push;
|
||||
private float _frontTwist;
|
||||
private float _rearTwist;
|
||||
|
||||
private CapabilityEvents _capabilityEvents;
|
||||
|
||||
// Cycles through every DamageType on each absorbed hit so the operator can see how a presenter
|
||||
// that varies by type would behave; the field shield presentation itself ignores it today.
|
||||
private static readonly DamageType[] DamageTypeCycle = (DamageType[])Enum.GetValues(typeof(DamageType));
|
||||
private int _nextDamageTypeIndex;
|
||||
|
||||
private List<(float lerp, float time, Transform transform)> _pickups = new List<(float lerp, float time, Transform transform)>();
|
||||
|
||||
|
|
@ -35,9 +53,34 @@ public class FieldTester : MonoBehaviour
|
|||
{
|
||||
_input = new AetheriaInput();
|
||||
_input.Player.Enable();
|
||||
|
||||
_capabilityEvents = new CapabilityEvents();
|
||||
var binder = TestField.GetComponent<CapabilityPresentationBinder>();
|
||||
if (binder == null)
|
||||
Debug.LogError("FieldTester expects a CapabilityPresentationBinder on TestField's GameObject; no capability events will reach the field.");
|
||||
else
|
||||
binder.Bind(_capabilityEvents,
|
||||
grabTargetResolver: handle => handle >= 0 && handle < _pickups.Count ? _pickups[handle].transform : null,
|
||||
grabInitialVelocityResolver: handle => Vector3.forward *
|
||||
(PickupTravelDistance / lerp(PickupTravelTimeMin, PickupTravelTimeMax, _pickups[handle].lerp)));
|
||||
|
||||
// Impact absorption (fork L): what used to be FieldDriver's own click handler is now this
|
||||
// scene's stand-in for whatever will eventually detect a hit and publish AbsorbEvent.
|
||||
var clickableCollider = TestField.GetComponent<ClickableCollider>();
|
||||
if (clickableCollider != null)
|
||||
{
|
||||
clickableCollider.OnClick += (_, _, ray, hit) =>
|
||||
{
|
||||
var damageType = DamageTypeCycle[_nextDamageTypeIndex];
|
||||
_nextDamageTypeIndex = (_nextDamageTypeIndex + 1) % DamageTypeCycle.Length;
|
||||
_capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType));
|
||||
};
|
||||
}
|
||||
|
||||
Properties.AddField("Time Scale", () => Time.timeScale, f => Time.timeScale = f, 0, 2);
|
||||
Properties.AddField("FOV", () => Camera.fieldOfView, f => Camera.fieldOfView = f, 15, 45);
|
||||
Properties.AddButton("Melee", () => TestField.Melee());
|
||||
Properties.AddButton("Melee", () => _capabilityEvents.PublishMelee(
|
||||
new MeleeEvent(float3(0, 0, 1), TestField.MeleeRange, TestField.MeleeAngle, TestField.MeleeDuration)));
|
||||
Properties.AddField("Force Thrust", () => _forceThrust, b => _forceThrust = b);
|
||||
Properties.AddField("Directional Push", () => _directionalPush, b => _directionalPush = b);
|
||||
Properties.AddField("Throttle Decay", () => _throttleDecay, f => _throttleDecay = f);
|
||||
|
|
@ -59,12 +102,11 @@ public class FieldTester : MonoBehaviour
|
|||
if (!TestField.CanGrab) return;
|
||||
click.Clear();
|
||||
var p = _pickups[i1];
|
||||
var travelTime = lerp(PickupTravelTimeMin, PickupTravelTimeMax, l);
|
||||
TestField.GrabObject(p.transform, Vector3.forward * (PickupTravelDistance / travelTime));
|
||||
_capabilityEvents.PublishGrab(new GrabEvent(i1, GrabPhase.Started, p.transform.position.ToCultMath(), 0));
|
||||
p.transform = null;
|
||||
_pickups[i1] = p;
|
||||
};
|
||||
|
||||
|
||||
pickup.ScanLabelContainer.gameObject.SetActive(false);
|
||||
pickup.enabled = false;
|
||||
var pickupTransform = pickup.transform;
|
||||
|
|
@ -79,27 +121,29 @@ public class FieldTester : MonoBehaviour
|
|||
{
|
||||
var move = _forceThrust ? float2(0,1) : _input.Player.Move.ReadValue<Vector2>().ToCultMath();
|
||||
var turn = _input.Player.Turn.ReadValue<float>();
|
||||
|
||||
float2 targetPush;
|
||||
float targetFrontTwist;
|
||||
float targetRearTwist;
|
||||
if (_directionalPush)
|
||||
{
|
||||
TestField.Push = damp(TestField.Push, move, _throttleDecay, Time.deltaTime);
|
||||
TestField.FrontTwist = damp(TestField.FrontTwist,
|
||||
turn,
|
||||
_throttleDecay, Time.deltaTime);
|
||||
TestField.RearTwist = damp(TestField.RearTwist,
|
||||
turn,
|
||||
_throttleDecay, Time.deltaTime);
|
||||
targetPush = move;
|
||||
targetFrontTwist = turn;
|
||||
targetRearTwist = turn;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestField.Push = damp(TestField.Push, float2(0,move.y), _throttleDecay, Time.deltaTime);
|
||||
TestField.FrontTwist = damp(TestField.FrontTwist,
|
||||
clamp(turn + move.x, -1, 1) * (1+min(move.y,0)),
|
||||
_throttleDecay, Time.deltaTime);
|
||||
TestField.RearTwist = damp(TestField.RearTwist,
|
||||
clamp(turn - move.x, -1, 1) * (1+min(-move.y,0)),
|
||||
_throttleDecay, Time.deltaTime);
|
||||
targetPush = float2(0, move.y);
|
||||
targetFrontTwist = clamp(turn + move.x, -1, 1) * (1 + min(move.y, 0));
|
||||
targetRearTwist = clamp(turn - move.x, -1, 1) * (1 + min(-move.y, 0));
|
||||
}
|
||||
|
||||
_push = damp(_push, targetPush, _throttleDecay, Time.deltaTime);
|
||||
_frontTwist = damp(_frontTwist, targetFrontTwist, _throttleDecay, Time.deltaTime);
|
||||
_rearTwist = damp(_rearTwist, targetRearTwist, _throttleDecay, Time.deltaTime);
|
||||
|
||||
_capabilityEvents.PublishThrust(new ThrustEvent(_push, min(length(_push), 1), float2(_frontTwist, _rearTwist)));
|
||||
|
||||
for (var i = 0; i < _pickups.Count; i++)
|
||||
{
|
||||
var (l, time, t) = _pickups[i];
|
||||
|
|
@ -110,4 +154,4 @@ public class FieldTester : MonoBehaviour
|
|||
_pickups[i] = (l, time, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue